From 386a4b7bd967a45f361d984dbf0e1216bcc5fc78 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Tue, 6 Apr 2021 04:57:41 -0700 Subject: [PATCH] fix: spec.preserveUnknownFields must be explicitly false to allow upgrades from apiextensions.k8s.io/v1beta1 Signed-off-by: Jesse Suen --- hack/gen-crd-spec/main.go | 19 ++++++------------- manifests/crds/analysis-run-crd.yaml | 1 + manifests/crds/analysis-template-crd.yaml | 1 + .../crds/cluster-analysis-template-crd.yaml | 1 + manifests/crds/experiment-crd.yaml | 1 + manifests/crds/rollout-crd.yaml | 1 + manifests/install.yaml | 5 +++++ manifests/namespace-install.yaml | 5 +++++ 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/hack/gen-crd-spec/main.go b/hack/gen-crd-spec/main.go index 5f65d83292..bc5cd3f16e 100644 --- a/hack/gen-crd-spec/main.go +++ b/hack/gen-crd-spec/main.go @@ -82,6 +82,7 @@ func NewCustomResourceDefinition() []*extensionsobj.CustomResourceDefinition { // by using the 'setValidationOverride' function in this file. "crd:preserveUnknownFields=false", "crd:crdVersions=v1", + "crd:maxDescLen=0", "output:crd:stdout", ).Output() if err != nil { @@ -110,7 +111,6 @@ func NewCustomResourceDefinition() []*extensionsobj.CustomResourceDefinition { for i := range objs { obj := objs[i] - removeDescriptions(obj) removeK8S118Fields(obj) createMetadataValidation(obj) crd := toCRD(obj) @@ -228,18 +228,6 @@ func createMetadataValidation(un *unstructured.Unstructured) { } } -func removeDescriptions(un *unstructured.Unstructured) { - objVersions, _, _ := unstructured.NestedSlice(un.Object, "spec", "versions") - - var validation []interface{} - for _, v := range objVersions { - removeFieldHelper(v.(map[string]interface{}), "description") - validation = append(validation, v) - } - - unstructured.SetNestedSlice(un.Object, validation, "spec", "versions") -} - func removeFieldHelper(obj map[string]interface{}, fieldName string) { for k, v := range obj { if k == fieldName { @@ -332,6 +320,11 @@ func main() { err = json.Unmarshal(jsonBytes, &r.Object) checkErr(err) + // Need to explicitly set spec.preserveUnknownFields to false, despite false being the + // default value in v1, in order to facilitate upgrades from apiextensions.k8s.io/v1beta1 v1. + // See https://github.com/argoproj/argo-rollouts/issues/1067 + unstructured.SetNestedField(r.Object, false, "spec", "preserveUnknownFields") + // clean up crd yaml before marshalling unstructured.RemoveNestedField(r.Object, "status") unstructured.RemoveNestedField(r.Object, "metadata", "creationTimestamp") diff --git a/manifests/crds/analysis-run-crd.yaml b/manifests/crds/analysis-run-crd.yaml index fd77bd910b..d8d798f5ee 100644 --- a/manifests/crds/analysis-run-crd.yaml +++ b/manifests/crds/analysis-run-crd.yaml @@ -13,6 +13,7 @@ spec: shortNames: - ar singular: analysisrun + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: diff --git a/manifests/crds/analysis-template-crd.yaml b/manifests/crds/analysis-template-crd.yaml index 617be0f408..34bb2a7abd 100644 --- a/manifests/crds/analysis-template-crd.yaml +++ b/manifests/crds/analysis-template-crd.yaml @@ -13,6 +13,7 @@ spec: shortNames: - at singular: analysistemplate + preserveUnknownFields: false scope: Namespaced versions: - name: v1alpha1 diff --git a/manifests/crds/cluster-analysis-template-crd.yaml b/manifests/crds/cluster-analysis-template-crd.yaml index 5957b9fd57..4a725211e9 100644 --- a/manifests/crds/cluster-analysis-template-crd.yaml +++ b/manifests/crds/cluster-analysis-template-crd.yaml @@ -13,6 +13,7 @@ spec: shortNames: - cat singular: clusteranalysistemplate + preserveUnknownFields: false scope: Cluster versions: - name: v1alpha1 diff --git a/manifests/crds/experiment-crd.yaml b/manifests/crds/experiment-crd.yaml index 7b98f2da95..8138e6aa1f 100644 --- a/manifests/crds/experiment-crd.yaml +++ b/manifests/crds/experiment-crd.yaml @@ -13,6 +13,7 @@ spec: shortNames: - exp singular: experiment + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: diff --git a/manifests/crds/rollout-crd.yaml b/manifests/crds/rollout-crd.yaml index 0ec8f5b39f..763411fad6 100644 --- a/manifests/crds/rollout-crd.yaml +++ b/manifests/crds/rollout-crd.yaml @@ -13,6 +13,7 @@ spec: shortNames: - ro singular: rollout + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: diff --git a/manifests/install.yaml b/manifests/install.yaml index 13e5dffc93..519bd631b8 100644 --- a/manifests/install.yaml +++ b/manifests/install.yaml @@ -14,6 +14,7 @@ spec: shortNames: - ar singular: analysisrun + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: @@ -2516,6 +2517,7 @@ spec: shortNames: - at singular: analysistemplate + preserveUnknownFields: false scope: Namespaced versions: - name: v1alpha1 @@ -4940,6 +4942,7 @@ spec: shortNames: - cat singular: clusteranalysistemplate + preserveUnknownFields: false scope: Cluster versions: - name: v1alpha1 @@ -7364,6 +7367,7 @@ spec: shortNames: - exp singular: experiment + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: @@ -9698,6 +9702,7 @@ spec: shortNames: - ro singular: rollout + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: diff --git a/manifests/namespace-install.yaml b/manifests/namespace-install.yaml index 45ac042e1a..a0d6d009e7 100644 --- a/manifests/namespace-install.yaml +++ b/manifests/namespace-install.yaml @@ -14,6 +14,7 @@ spec: shortNames: - ar singular: analysisrun + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: @@ -2516,6 +2517,7 @@ spec: shortNames: - at singular: analysistemplate + preserveUnknownFields: false scope: Namespaced versions: - name: v1alpha1 @@ -4940,6 +4942,7 @@ spec: shortNames: - cat singular: clusteranalysistemplate + preserveUnknownFields: false scope: Cluster versions: - name: v1alpha1 @@ -7364,6 +7367,7 @@ spec: shortNames: - exp singular: experiment + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: @@ -9698,6 +9702,7 @@ spec: shortNames: - ro singular: rollout + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: