我正在构建一个使用Kubebuilder的操作符,它将与包含一些自定义字段以及Argo WorkflowTemplate的所有字段的CRD一起工作。字段本质上是Argo Workflow的所有字段,因为规范中的字段与我不关心的字段是相同的。运算符将使用WorkflowTemplate字段来创建一个实际的Argo WorkflowTemplate资源,但在此之前,它需要对自定义字段执行一些操作。如何将WorkflowTemplate的所有字段包含在我的CRD中,而不逐字逐句地复制所有字段并将其手工粘贴到CRD的规范中?
我尝试在我的CRD中使用这种方法(我只是添加了一些与当前问题无关的字段)。
import (
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
)
type DefinitionSpec struct {
Field1 string `json:"field1,omitempty"`
Field2 string `json:"field2,omitempty"`
WorkflowSpec wfv1.WorkflowSpec `json:",inline"`
}如果这样做,则在安装CRD时会出现此错误。
$ make install
/Users/mbtamuli/workspace/argo-workflow-operator/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/Users/mbtamuli/workspace/argo-workflow-operator/bin/kustomize build config/crd | kubectl apply -f -
The CustomResourceDefinition "definitions.mriyam.dev" is invalid:
* metadata.annotations: Too long: must have at most 262144 bytes
* spec.validation.openAPIV3Schema.properties[spec].properties[templateDefaults].properties[dag].properties[tasks].items.properties[inline].type: Required value: must not be empty for specified object fields
* spec.validation.openAPIV3Schema.properties[spec].properties[templateDefaults].properties[steps].items.items: Required value: must be specified
* spec.validation.openAPIV3Schema.properties[spec].properties[templates].items.properties[dag].properties[tasks].items.properties[inline].type: Required value: must not be empty for specified object fields
* spec.validation.openAPIV3Schema.properties[spec].properties[templates].items.properties[steps].items.items: Required value: must be specified
make: *** [install] Error 1我从其他SO和GitHub问题中发现,我可以通过使用create而不是apply来解决注释问题。
$ bin/kustomize build config/crd | kubectl create -f -
+ kubectl create -f -
The CustomResourceDefinition "definitions.mriyam.dev" is invalid:
* spec.validation.openAPIV3Schema.properties[spec].properties[templateDefaults].properties[dag].properties[tasks].items.properties[inline].type: Required value: must not be empty for specified object fields
* spec.validation.openAPIV3Schema.properties[spec].properties[templateDefaults].properties[steps].items.items: Required value: must be specified
* spec.validation.openAPIV3Schema.properties[spec].properties[templates].items.properties[dag].properties[tasks].items.properties[inline].type: Required value: must not be empty for specified object fields
* spec.validation.openAPIV3Schema.properties[spec].properties[templates].items.properties[steps].items.items: Required value: must be specified发布于 2022-03-18 11:11:52
在包装Argo工作流CRD时,我遇到了同样的问题,然后我发现Argo工作流项目通过删除CRD验证来避免这些问题:
https://github.com/argoproj/argo-workflows/blob/master/hack/crds.go
最重要的部分是以下功能:
func removeCRDValidation(filename string) {
data, err := ioutil.ReadFile(filepath.Clean(filename))
if err != nil {
panic(err)
}
crd := make(obj)
err = yaml.Unmarshal(data, &crd)
if err != nil {
panic(err)
}
spec := crd["spec"].(obj)
versions := spec["versions"].([]interface{})
version := versions[0].(obj)
properties := version["schema"].(obj)["openAPIV3Schema"].(obj)["properties"].(obj)
for k := range properties {
if k == "spec" || k == "status" {
properties[k] = obj{"type": "object", "x-kubernetes-preserve-unknown-fields": true, "x-kubernetes-map-type": "atomic"}
}
}
data, err = yaml.Marshal(crd)
if err != nil {
panic(err)
}
err = ioutil.WriteFile(filename, data, 0o600)
if err != nil {
panic(err)
}
}实际上,它们覆盖CRD规范,并将x-kubernetes-preserve-unknown-fields设置为true,以确保Kubernetes API在不检查字段的情况下接受请求。
https://stackoverflow.com/questions/70644171
复制相似问题