From e1437c45388f33fae38a1199c0d83bb38105fd5e Mon Sep 17 00:00:00 2001 From: Chetan Banavikalmutt Date: Tue, 11 Jun 2024 17:53:13 +0530 Subject: [PATCH] fix: Rollout's selector field should be immutable Signed-off-by: Chetan Banavikalmutt --- docs/features/kustomize/rollout_cr_schema.json | 3 +++ manifests/crds/rollout-crd.yaml | 5 +++++ manifests/install.yaml | 5 +++++ pkg/apiclient/rollout/rollout.swagger.json | 2 +- pkg/apis/rollouts/v1alpha1/generated.proto | 3 ++- pkg/apis/rollouts/v1alpha1/openapi_generated.go | 1 + pkg/apis/rollouts/v1alpha1/types.go | 3 ++- 7 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/features/kustomize/rollout_cr_schema.json b/docs/features/kustomize/rollout_cr_schema.json index 038ebebf89..95a4989ad1 100644 --- a/docs/features/kustomize/rollout_cr_schema.json +++ b/docs/features/kustomize/rollout_cr_schema.json @@ -22183,6 +22183,9 @@ "type": "object" } }, + "required": [ + "selector" + ], "type": "object" } }, diff --git a/manifests/crds/rollout-crd.yaml b/manifests/crds/rollout-crd.yaml index 04e187dbea..7a50cdaba3 100755 --- a/manifests/crds/rollout-crd.yaml +++ b/manifests/crds/rollout-crd.yaml @@ -109,6 +109,9 @@ spec: type: object type: object x-kubernetes-map-type: atomic + x-kubernetes-validations: + - message: field is immutable + rule: self == oldSelf strategy: properties: blueGreen: @@ -3556,6 +3559,8 @@ spec: scaleDown: type: string type: object + required: + - selector type: object status: properties: diff --git a/manifests/install.yaml b/manifests/install.yaml index dfb8d18768..4083fe7530 100755 --- a/manifests/install.yaml +++ b/manifests/install.yaml @@ -12599,6 +12599,9 @@ spec: type: object type: object x-kubernetes-map-type: atomic + x-kubernetes-validations: + - message: field is immutable + rule: self == oldSelf strategy: properties: blueGreen: @@ -16046,6 +16049,8 @@ spec: scaleDown: type: string type: object + required: + - selector type: object status: properties: diff --git a/pkg/apiclient/rollout/rollout.swagger.json b/pkg/apiclient/rollout/rollout.swagger.json index b3c10e03f8..ccea326add 100755 --- a/pkg/apiclient/rollout/rollout.swagger.json +++ b/pkg/apiclient/rollout/rollout.swagger.json @@ -2062,7 +2062,7 @@ }, "selector": { "$ref": "#/definitions/k8s.io.apimachinery.pkg.apis.meta.v1.LabelSelector", - "title": "Label selector for pods. Existing ReplicaSets whose pods are\nselected by this will be the ones affected by this rollout.\nIt must match the pod template's labels.\n+optional" + "title": "Label selector for pods. Existing ReplicaSets whose pods are\nselected by this will be the ones affected by this rollout.\nIt must match the pod template's labels.\n+kubebuilder:validation:Required\n+kubebuilder:validation:XValidation:rule=\"self == oldSelf\",message=\"field is immutable\"" }, "template": { "$ref": "#/definitions/k8s.io.api.core.v1.PodTemplateSpec", diff --git a/pkg/apis/rollouts/v1alpha1/generated.proto b/pkg/apis/rollouts/v1alpha1/generated.proto index 0ea0a7bc2c..05a36d4b95 100644 --- a/pkg/apis/rollouts/v1alpha1/generated.proto +++ b/pkg/apis/rollouts/v1alpha1/generated.proto @@ -1404,7 +1404,8 @@ message RolloutSpec { // Label selector for pods. Existing ReplicaSets whose pods are // selected by this will be the ones affected by this rollout. // It must match the pod template's labels. - // +optional + // +kubebuilder:validation:Required + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable" optional k8s.io.apimachinery.pkg.apis.meta.v1.LabelSelector selector = 2; // Template describes the pods that will be created. diff --git a/pkg/apis/rollouts/v1alpha1/openapi_generated.go b/pkg/apis/rollouts/v1alpha1/openapi_generated.go index 2d4d68ff1e..9b5d13f12e 100644 --- a/pkg/apis/rollouts/v1alpha1/openapi_generated.go +++ b/pkg/apis/rollouts/v1alpha1/openapi_generated.go @@ -4411,6 +4411,7 @@ func schema_pkg_apis_rollouts_v1alpha1_RolloutSpec(ref common.ReferenceCallback) }, }, }, + Required: []string{"selector"}, }, }, Dependencies: []string{ diff --git a/pkg/apis/rollouts/v1alpha1/types.go b/pkg/apis/rollouts/v1alpha1/types.go index 2ab4ea1018..5f56083f24 100755 --- a/pkg/apis/rollouts/v1alpha1/types.go +++ b/pkg/apis/rollouts/v1alpha1/types.go @@ -43,7 +43,8 @@ type RolloutSpec struct { // Label selector for pods. Existing ReplicaSets whose pods are // selected by this will be the ones affected by this rollout. // It must match the pod template's labels. - // +optional + // +kubebuilder:validation:Required + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable" Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,2,opt,name=selector"` // Template describes the pods that will be created. // +optional