From 90b254dee2d400d8752f9e0c2dfca67f5891895f 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 e120620f13..9e3e816e80 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 c4758d5bc5..bc29d7190f 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 8c52a8fa26..4c5bddaeb8 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 1a7ac6cfd8..278e90bd24 100644 --- a/manifests/install.yaml +++ b/manifests/install.yaml @@ -14,6 +14,7 @@ spec: shortNames: - ar singular: analysisrun + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: @@ -2511,6 +2512,7 @@ spec: shortNames: - at singular: analysistemplate + preserveUnknownFields: false scope: Namespaced versions: - name: v1alpha1 @@ -4930,6 +4932,7 @@ spec: shortNames: - cat singular: clusteranalysistemplate + preserveUnknownFields: false scope: Cluster versions: - name: v1alpha1 @@ -7349,6 +7352,7 @@ spec: shortNames: - exp singular: experiment + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: @@ -9683,6 +9687,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 e1b19faaaa..a4ad7e308a 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: @@ -2511,6 +2512,7 @@ spec: shortNames: - at singular: analysistemplate + preserveUnknownFields: false scope: Namespaced versions: - name: v1alpha1 @@ -4930,6 +4932,7 @@ spec: shortNames: - cat singular: clusteranalysistemplate + preserveUnknownFields: false scope: Cluster versions: - name: v1alpha1 @@ -7349,6 +7352,7 @@ spec: shortNames: - exp singular: experiment + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: @@ -9683,6 +9687,7 @@ spec: shortNames: - ro singular: rollout + preserveUnknownFields: false scope: Namespaced versions: - additionalPrinterColumns: