Skip to content

Commit

Permalink
fix: spec.preserveUnknownFields must be explicitly false to allow upg…
Browse files Browse the repository at this point in the history
…rades from apiextensions.k8s.io/v1beta1

Signed-off-by: Jesse Suen <[email protected]>
  • Loading branch information
jessesuen committed Apr 6, 2021
1 parent 1ee46cf commit 90b254d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 13 deletions.
19 changes: 6 additions & 13 deletions hack/gen-crd-spec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -110,7 +111,6 @@ func NewCustomResourceDefinition() []*extensionsobj.CustomResourceDefinition {

for i := range objs {
obj := objs[i]
removeDescriptions(obj)
removeK8S118Fields(obj)
createMetadataValidation(obj)
crd := toCRD(obj)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions manifests/crds/analysis-run-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
shortNames:
- ar
singular: analysisrun
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down
1 change: 1 addition & 0 deletions manifests/crds/analysis-template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
shortNames:
- at
singular: analysistemplate
preserveUnknownFields: false
scope: Namespaced
versions:
- name: v1alpha1
Expand Down
1 change: 1 addition & 0 deletions manifests/crds/cluster-analysis-template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
shortNames:
- cat
singular: clusteranalysistemplate
preserveUnknownFields: false
scope: Cluster
versions:
- name: v1alpha1
Expand Down
1 change: 1 addition & 0 deletions manifests/crds/experiment-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
shortNames:
- exp
singular: experiment
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down
1 change: 1 addition & 0 deletions manifests/crds/rollout-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
shortNames:
- ro
singular: rollout
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down
5 changes: 5 additions & 0 deletions manifests/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
shortNames:
- ar
singular: analysisrun
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down Expand Up @@ -2511,6 +2512,7 @@ spec:
shortNames:
- at
singular: analysistemplate
preserveUnknownFields: false
scope: Namespaced
versions:
- name: v1alpha1
Expand Down Expand Up @@ -4930,6 +4932,7 @@ spec:
shortNames:
- cat
singular: clusteranalysistemplate
preserveUnknownFields: false
scope: Cluster
versions:
- name: v1alpha1
Expand Down Expand Up @@ -7349,6 +7352,7 @@ spec:
shortNames:
- exp
singular: experiment
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down Expand Up @@ -9683,6 +9687,7 @@ spec:
shortNames:
- ro
singular: rollout
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down
5 changes: 5 additions & 0 deletions manifests/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
shortNames:
- ar
singular: analysisrun
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down Expand Up @@ -2511,6 +2512,7 @@ spec:
shortNames:
- at
singular: analysistemplate
preserveUnknownFields: false
scope: Namespaced
versions:
- name: v1alpha1
Expand Down Expand Up @@ -4930,6 +4932,7 @@ spec:
shortNames:
- cat
singular: clusteranalysistemplate
preserveUnknownFields: false
scope: Cluster
versions:
- name: v1alpha1
Expand Down Expand Up @@ -7349,6 +7352,7 @@ spec:
shortNames:
- exp
singular: experiment
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down Expand Up @@ -9683,6 +9687,7 @@ spec:
shortNames:
- ro
singular: rollout
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down

0 comments on commit 90b254d

Please sign in to comment.