Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: spec.preserveUnknownFields must be explicitly false to allow upgrades from apiextensions.k8s.io/v1beta1 #1069

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2516,6 +2517,7 @@ spec:
shortNames:
- at
singular: analysistemplate
preserveUnknownFields: false
scope: Namespaced
versions:
- name: v1alpha1
Expand Down Expand Up @@ -4940,6 +4942,7 @@ spec:
shortNames:
- cat
singular: clusteranalysistemplate
preserveUnknownFields: false
scope: Cluster
versions:
- name: v1alpha1
Expand Down Expand Up @@ -7364,6 +7367,7 @@ spec:
shortNames:
- exp
singular: experiment
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down Expand Up @@ -9698,6 +9702,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 @@ -2516,6 +2517,7 @@ spec:
shortNames:
- at
singular: analysistemplate
preserveUnknownFields: false
scope: Namespaced
versions:
- name: v1alpha1
Expand Down Expand Up @@ -4940,6 +4942,7 @@ spec:
shortNames:
- cat
singular: clusteranalysistemplate
preserveUnknownFields: false
scope: Cluster
versions:
- name: v1alpha1
Expand Down Expand Up @@ -7364,6 +7367,7 @@ spec:
shortNames:
- exp
singular: experiment
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down Expand Up @@ -9698,6 +9702,7 @@ spec:
shortNames:
- ro
singular: rollout
preserveUnknownFields: false
scope: Namespaced
versions:
- additionalPrinterColumns:
Expand Down