在实际应用或执行之前验证yaml中定义的OpenShift对象 [英] Validate OpenShift objects defined in yaml before actually applying or executing it

查看:139
本文介绍了在实际应用或执行之前验证yaml中定义的OpenShift对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在template.yaml文件中有一个OpenShift模板,其中包括以下对象-部署配置,pod,服务和路由.我正在使用以下命令来执行yaml:

I have a OpenShift template in template.yaml file which includes following objects - deployment-config, pod, service and route. I am using the following command to execute the yaml:

oc process -f template.yml | oc apply -f -

我想在实际应用/执行Yaml之前执行以下验证:

I want to perform following validations before I actually apply/execute the yaml:

  1. YAML语法验证-如果YAML语法有任何问题.
  2. OpenShift模式验证-检查对象定义是否遵守OpenShift对象模式.

似乎"oc process"命令正在执行以下检查:

It seems that the command 'oc process' is doing following checking:

  1. 基本YAML语法验证
  2. 模板对象架构验证

如何对template.yaml中定义的其他对象(例如,部署配置,服务,pod等)执行架构验证?

How to perform schema validation of other objects (e.g. deployment-config, service, pod, etc.) that are defined in template.yaml?

推荐答案

例如,现在可以使用OpenShift客户端(通常在Kubernetes上)

This is now possible with the OpenShift client (and on Kubernetes in general), e.g.

$ oc login
Username: john.doe
Password: 
Login successful.

$ oc apply -f openshift/template-app.yaml --dry-run
template "foobar-app" created (dry run)

还可以在本地处理模板,因此您可以避免例如先将其发送到服务器.

It's also possible to process the template locally, thus you can avoid sending it to the server first, e.g.

$ oc process -f openshift/template-app.yaml --local -p APP_NAME=foo | oc apply --dry-run --validate -f -
deploymentconfig "foo" created (dry run)
service "foo" created (dry run)

还请注意我用于架构验证的--validate选项.不幸的是,您仍然必须登录才能使用apply命令(apply没有--local选项).

Also note the --validate option I'm using for schema validation. Unfortunately, you still have to log in for the apply command to work (there's no --local option for apply).

奇怪的是, CLI文档中没有对此功能进行说明.帮助屏幕上提到了它:

Oddly, this feature is not described in the CLI documentation, however it's mentioned on the help screen:

$ oc apply --help
Apply a configuration to a resource by filename or stdin.

JSON and YAML formats are accepted.

Usage:
  oc apply -f FILENAME [options]

...

Options:
      ...
      --dry-run=false: If true, only print the object that would be sent, without sending it.
      ...
      --validate=false: If true, use a schema to validate the input before sending it

Use "oc <command> --help" for more information about a given command.
Use "oc options" for a list of global command-line options (applies to all commands).

这篇关于在实际应用或执行之前验证yaml中定义的OpenShift对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆