diff --git a/hack/manifests/crds.go b/hack/manifests/crds.go index cfc32bcbd055..cdda31c0a0bd 100644 --- a/hack/manifests/crds.go +++ b/hack/manifests/crds.go @@ -3,7 +3,7 @@ package main import "fmt" // cleanCRD does post-processing of the CRDs generated by kubebuilder to workaround limitations -// (see https://github.com/kubernetes-sigs/controller-tools/issues/461) +// (e.g. https://github.com/kubernetes-sigs/controller-tools/issues/461) func cleanCRD(filename string) { crd := ParseYaml(Read(filename)) crd.RemoveNestedField("status") @@ -12,28 +12,51 @@ func cleanCRD(filename string) { schema := crd.OpenAPIV3Schema() switch crd.Name() { case "cronworkflows.argoproj.io": + patchMetadata(&schema, "spec", "properties", "workflowMetadata", "properties") patchWorkflowSpecTemplateFields(&schema, "spec", "properties", "workflowSpec", "properties") - case "clusterworkflowtemplates.argoproj.io", "workflows.argoproj.io", "workflowtemplates.argoproj.io": + case "clusterworkflowtemplates.argoproj.io", "workflowtemplates.argoproj.io": + patchWorkflowSpecTemplateFields(&schema, "spec", "properties") + case "workflows.argoproj.io": patchWorkflowSpecTemplateFields(&schema, "spec", "properties") - } - if crd.Name() == "workflows.argoproj.io" { - patchTemplateFields(&schema, "status", "properties", "storedTemplates", "additionalProperties") patchWorkflowSpecTemplateFields(&schema, "status", "properties", "storedWorkflowTemplateSpec", "properties") + patchTemplateFields(&schema, "status", "properties", "storedTemplates", "additionalProperties", "properties") + patchEphemeralVolumeFields(&schema, "status", "properties", "persistentVolumeClaims", "items", "properties") + case "workfloweventbindings.argoproj.io": + patchMetadata(&schema, "spec", "properties", "submit", "properties", "metadata", "properties") + case "workflowtasksets.argoproj.io": + patchVolumeFields(&schema, "spec", "properties", "tasks", "additionalProperties", "properties") + } crd.WriteYaml(filename) } func patchWorkflowSpecTemplateFields(schema *obj, baseFields ...string) { - patchTemplateFields(schema, append(baseFields, "templateDefaults")...) - patchTemplateFields(schema, append(baseFields, "templates", "items")...) + patchTemplateFields(schema, append(baseFields, "templateDefaults", "properties")...) + patchTemplateFields(schema, append(baseFields, "templates", "items", "properties")...) + patchVolumeFields(schema, baseFields...) + patchMetadata(schema, append(baseFields, "volumeClaimTemplates", "items", "properties", "metadata", "properties")...) +} + +// Workaround for missing generateName (see https://github.com/kubernetes-sigs/controller-tools/pull/640) +func patchMetadata(schema *obj, baseFields ...string) { + schema.SetNestedField(map[string]string{"type": "string"}, append(baseFields, "generateName")...) +} + +func patchEphemeralVolumeFields(schema *obj, baseFields ...string) { + patchMetadata(schema, append(baseFields, "ephemeral", "properties", "volumeClaimTemplate", "properties", "metadata", "properties")...) +} + +func patchVolumeFields(schema *obj, baseFields ...string) { + patchEphemeralVolumeFields(schema, append(baseFields, "volumes", "items", "properties")...) } func patchTemplateFields(schema *obj, baseFields ...string) { + patchVolumeFields(schema, baseFields...) // "container" and "script" templates embed the k8s.io/api/core/v1/Container // struct, which requires the "name" field to be specified, but it's not actually required, // and there's no easy way to override validating rules for embedded structs in kubebuilder. - schema.RemoveNestedField(append(baseFields, "properties", "container", "required")...) - schema.RemoveNestedField(append(baseFields, "properties", "script", "required")...) + schema.RemoveNestedField(append(baseFields, "container", "required")...) + schema.RemoveNestedField(append(baseFields, "script", "required")...) // Hack to transform "steps" from an array of objects, e.g. // steps: @@ -48,7 +71,7 @@ func patchTemplateFields(schema *obj, baseFields ...string) { // The reason it's represented as an array of objects in "workflow_types.go" // is because that's the only way to get kubebuilder to generate the spec // without breaking API compatibility. - stepFields := append(baseFields, "properties", "steps", "items") + stepFields := append(baseFields, "steps", "items") schema.CopyNestedField(append(stepFields, "properties", "steps"), stepFields) } diff --git a/hack/manifests/helpers.go b/hack/manifests/helpers.go index 713293adb993..f93b36a95734 100644 --- a/hack/manifests/helpers.go +++ b/hack/manifests/helpers.go @@ -15,10 +15,14 @@ func (o *obj) RemoveNestedField(fields ...string) { unstructured.RemoveNestedField(*o, fields...) } +func (o *obj) SetNestedField(value interface{}, fields ...string) { + parentField := nestedFieldNoCopy[map[string]interface{}](o, fields[:len(fields)-1]...) + parentField[fields[len(fields)-1]] = value +} + func (o *obj) CopyNestedField(sourceFields []string, targetFields []string) { value := nestedFieldNoCopy[any](o, sourceFields...) - parentField := nestedFieldNoCopy[map[string]interface{}](o, targetFields[:len(targetFields)-1]...) - parentField[targetFields[len(targetFields)-1]] = value + o.SetNestedField(value, targetFields...) } func (o *obj) Name() string { diff --git a/manifests/base/crds/full/argoproj.io_clusterworkflowtemplates.yaml b/manifests/base/crds/full/argoproj.io_clusterworkflowtemplates.yaml index 7774ec9bedf2..f2c2ba81d413 100644 --- a/manifests/base/crds/full/argoproj.io_clusterworkflowtemplates.yaml +++ b/manifests/base/crds/full/argoproj.io_clusterworkflowtemplates.yaml @@ -12249,6 +12249,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -22919,6 +22921,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -23557,6 +23561,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -23935,6 +23941,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/base/crds/full/argoproj.io_cronworkflows.yaml b/manifests/base/crds/full/argoproj.io_cronworkflows.yaml index 4264234e75a9..4139ee27a01f 100644 --- a/manifests/base/crds/full/argoproj.io_cronworkflows.yaml +++ b/manifests/base/crds/full/argoproj.io_cronworkflows.yaml @@ -67,6 +67,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -12300,6 +12302,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -22970,6 +22974,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -23608,6 +23614,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -23986,6 +23994,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/base/crds/full/argoproj.io_workfloweventbindings.yaml b/manifests/base/crds/full/argoproj.io_workfloweventbindings.yaml index 5fbf3456f799..0cb907882679 100644 --- a/manifests/base/crds/full/argoproj.io_workfloweventbindings.yaml +++ b/manifests/base/crds/full/argoproj.io_workfloweventbindings.yaml @@ -669,6 +669,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/base/crds/full/argoproj.io_workflows.yaml b/manifests/base/crds/full/argoproj.io_workflows.yaml index 75d856d592bf..f0846eb97a48 100644 --- a/manifests/base/crds/full/argoproj.io_workflows.yaml +++ b/manifests/base/crds/full/argoproj.io_workflows.yaml @@ -12263,6 +12263,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -22933,6 +22935,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -23571,6 +23575,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -23949,6 +23955,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -27086,6 +27094,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -37767,6 +37777,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -50579,6 +50591,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -61249,6 +61263,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -61887,6 +61903,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -62265,6 +62283,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/base/crds/full/argoproj.io_workflowtasksets.yaml b/manifests/base/crds/full/argoproj.io_workflowtasksets.yaml index 03e008fde300..40ffebf43b2e 100644 --- a/manifests/base/crds/full/argoproj.io_workflowtasksets.yaml +++ b/manifests/base/crds/full/argoproj.io_workflowtasksets.yaml @@ -10118,6 +10118,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/base/crds/full/argoproj.io_workflowtemplates.yaml b/manifests/base/crds/full/argoproj.io_workflowtemplates.yaml index 0c2b44a31682..e3892203df47 100644 --- a/manifests/base/crds/full/argoproj.io_workflowtemplates.yaml +++ b/manifests/base/crds/full/argoproj.io_workflowtemplates.yaml @@ -12248,6 +12248,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -22918,6 +22920,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -23556,6 +23560,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string @@ -23934,6 +23940,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/base/crds/minimal/argoproj.io_workfloweventbindings.yaml b/manifests/base/crds/minimal/argoproj.io_workfloweventbindings.yaml index 5fbf3456f799..0cb907882679 100644 --- a/manifests/base/crds/minimal/argoproj.io_workfloweventbindings.yaml +++ b/manifests/base/crds/minimal/argoproj.io_workfloweventbindings.yaml @@ -669,6 +669,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/quick-start-minimal.yaml b/manifests/quick-start-minimal.yaml index 9b282b2c6381..ed7d6f173fcc 100644 --- a/manifests/quick-start-minimal.yaml +++ b/manifests/quick-start-minimal.yaml @@ -1885,6 +1885,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/quick-start-mysql.yaml b/manifests/quick-start-mysql.yaml index 4b8e869ec970..dae28656eed1 100644 --- a/manifests/quick-start-mysql.yaml +++ b/manifests/quick-start-mysql.yaml @@ -1885,6 +1885,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string diff --git a/manifests/quick-start-postgres.yaml b/manifests/quick-start-postgres.yaml index dc627a29f414..840470a080fb 100644 --- a/manifests/quick-start-postgres.yaml +++ b/manifests/quick-start-postgres.yaml @@ -1885,6 +1885,8 @@ spec: items: type: string type: array + generateName: + type: string labels: additionalProperties: type: string