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: Fixes the regression of dropping resources from argo-rollouts crds. Fixes #1043 #1044

Merged
merged 8 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
51 changes: 31 additions & 20 deletions hack/gen-crd-spec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const metadataValidation = `properties:
type: object
type: object`

var preserveUnknownFields = map[string]interface{}{
"x-kubernetes-preserve-unknown-fields": true,
}

var crdPaths = map[string]string{
"Rollout": "manifests/crds/rollout-crd.yaml",
"Experiment": "manifests/crds/experiment-crd.yaml",
Expand All @@ -34,7 +38,7 @@ var crdPaths = map[string]string{
"AnalysisRun": "manifests/crds/analysis-run-crd.yaml",
}

func removeValidation(un *unstructured.Unstructured, path string) {
func setValidationOverride(un *unstructured.Unstructured, fieldOverride map[string]interface{}, path string) {
schemaPath := []string{"spec", "validation", "openAPIV3Schema"}
for _, part := range strings.Split(path, ".") {
if strings.HasSuffix(part, "[]") {
Expand All @@ -49,7 +53,8 @@ func removeValidation(un *unstructured.Unstructured, path string) {
if !ok {
panic(fmt.Sprintf("%s not found for kind %s", schemaPath, crdKind(un)))
}
unstructured.RemoveNestedField(un.Object, schemaPath...)

unstructured.SetNestedMap(un.Object, fieldOverride, schemaPath...)
}

func NewCustomResourceDefinition() []*extensionsobj.CustomResourceDefinition {
Expand Down Expand Up @@ -230,34 +235,40 @@ func removeK8S118Fields(un *unstructured.Unstructured) {
kind := crdKind(un)
switch kind {
case "Rollout":
removeValidation(un, "spec.template.spec.containers[].resources.limits")
removeValidation(un, "spec.template.spec.containers[].resources.requests")
removeValidation(un, "spec.template.spec.initContainers[].resources.limits")
removeValidation(un, "spec.template.spec.initContainers[].resources.requests")
removeValidation(un, "spec.template.spec.ephemeralContainers[].resources.limits")
removeValidation(un, "spec.template.spec.ephemeralContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.template.spec.containers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.template.spec.containers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.template.spec.initContainers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.template.spec.initContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.template.spec.ephemeralContainers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.template.spec.ephemeralContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.template.spec.volumes[].ephemeral.volumeClaimTemplate.spec.resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.template.spec.volumes[].ephemeral.volumeClaimTemplate.spec.resources.requests")
validation, _, _ := unstructured.NestedMap(un.Object, "spec", "validation", "openAPIV3Schema")
removeFieldHelper(validation, "x-kubernetes-list-type")
removeFieldHelper(validation, "x-kubernetes-list-map-keys")
unstructured.SetNestedMap(un.Object, validation, "spec", "validation", "openAPIV3Schema")
case "Experiment":
removeValidation(un, "spec.templates[].template.spec.containers[].resources.limits")
removeValidation(un, "spec.templates[].template.spec.containers[].resources.requests")
removeValidation(un, "spec.templates[].template.spec.initContainers[].resources.limits")
removeValidation(un, "spec.templates[].template.spec.initContainers[].resources.requests")
removeValidation(un, "spec.templates[].template.spec.ephemeralContainers[].resources.limits")
removeValidation(un, "spec.templates[].template.spec.ephemeralContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.templates[].template.spec.containers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.templates[].template.spec.containers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.templates[].template.spec.initContainers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.templates[].template.spec.initContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.templates[].template.spec.ephemeralContainers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.templates[].template.spec.ephemeralContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.templates[].template.spec.volumes[].ephemeral.volumeClaimTemplate.spec.resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.templates[].template.spec.volumes[].ephemeral.volumeClaimTemplate.spec.resources.requests")
validation, _, _ := unstructured.NestedMap(un.Object, "spec", "validation", "openAPIV3Schema")
removeFieldHelper(validation, "x-kubernetes-list-type")
removeFieldHelper(validation, "x-kubernetes-list-map-keys")
unstructured.SetNestedMap(un.Object, validation, "spec", "validation", "openAPIV3Schema")
case "ClusterAnalysisTemplate", "AnalysisTemplate", "AnalysisRun":
removeValidation(un, "spec.metrics[].provider.job.spec.template.spec.containers[].resources.limits")
removeValidation(un, "spec.metrics[].provider.job.spec.template.spec.containers[].resources.requests")
removeValidation(un, "spec.metrics[].provider.job.spec.template.spec.initContainers[].resources.limits")
removeValidation(un, "spec.metrics[].provider.job.spec.template.spec.initContainers[].resources.requests")
removeValidation(un, "spec.metrics[].provider.job.spec.template.spec.ephemeralContainers[].resources.limits")
removeValidation(un, "spec.metrics[].provider.job.spec.template.spec.ephemeralContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.metrics[].provider.job.spec.template.spec.containers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.metrics[].provider.job.spec.template.spec.containers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.metrics[].provider.job.spec.template.spec.initContainers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.metrics[].provider.job.spec.template.spec.initContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.metrics[].provider.job.spec.template.spec.ephemeralContainers[].resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.metrics[].provider.job.spec.template.spec.ephemeralContainers[].resources.requests")
setValidationOverride(un, preserveUnknownFields, "spec.metrics[].provider.job.spec.template.spec.volumes[].ephemeral.volumeClaimTemplate.spec.resources.limits")
setValidationOverride(un, preserveUnknownFields, "spec.metrics[].provider.job.spec.template.spec.volumes[].ephemeral.volumeClaimTemplate.spec.resources.requests")
validation, _, _ := unstructured.NestedMap(un.Object, "spec", "validation", "openAPIV3Schema")
removeFieldHelper(validation, "x-kubernetes-list-type")
removeFieldHelper(validation, "x-kubernetes-list-map-keys")
Expand Down
31 changes: 17 additions & 14 deletions manifests/crds/analysis-run-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -1337,6 +1342,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -1889,6 +1899,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -2373,21 +2388,9 @@ spec:
resources:
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
x-kubernetes-preserve-unknown-fields: true
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
selector:
properties:
Expand Down
31 changes: 17 additions & 14 deletions manifests/crds/analysis-template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -1331,6 +1336,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -1883,6 +1893,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -2367,21 +2382,9 @@ spec:
resources:
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
x-kubernetes-preserve-unknown-fields: true
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
selector:
properties:
Expand Down
31 changes: 17 additions & 14 deletions manifests/crds/cluster-analysis-template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -1331,6 +1336,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -1883,6 +1893,11 @@ spec:
type: integer
type: object
resources:
properties:
limits:
x-kubernetes-preserve-unknown-fields: true
requests:
x-kubernetes-preserve-unknown-fields: true
type: object
securityContext:
properties:
Expand Down Expand Up @@ -2367,21 +2382,9 @@ spec:
resources:
properties:
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
x-kubernetes-preserve-unknown-fields: true
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
selector:
properties:
Expand Down
Loading