我正在尝试使用
oneOf
来验证我的 Kubernetes CRD,但仍然无法使其工作。我定义了以下 CRD。
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
type:
type: string
parameters:
type: array
items:
type: object
properties:
parameterName:
type: string
parameterValue:
type: string
policySpec:
type: object
properties:
json:
x-kubernetes-preserve-unknown-fields: true
type: object
description: this is arbitrary JSON
template:
type: string
我想向参数、policySpec 和模板添加
oneOf
验证,以便用户只能指定其中之一。我遵循了与 oneOf
相关的文档,但仍然无法弄清楚。
还发现了一个类似的 stackoverflow 问题,但没有正确的答案:Properly using oneOf in a Kubernetes CRD OpenAPI schema
有 K8s 人员可以提供帮助吗?预先感谢
提供
oneOf
以及父级的属性应该会产生您正在寻找的内容:
openAPIV3Schema:
type: object
properties:
spec:
type: object
oneOf:
- required: ["parameters"]
- required: ["policySpec"]
- required: ["template"]
properties:
type:
type: string
parameters:
type: array
items:
type: object
properties:
parameterName:
type: string
parameterValue:
type: string
policySpec:
type: object
properties:
json:
x-kubernetes-preserve-unknown-fields: true
type: object
description: this is arbitrary JSON
template:
type: string