From 6ecb3b3eb3dca9ef3ec1618d67353269c1cd2b49 Mon Sep 17 00:00:00 2001 From: raaizik <132667934+raaizik@users.noreply.github.com> Date: Sun, 3 Nov 2024 15:54:39 +0200 Subject: [PATCH] Adds CEL rule for clusterID ClusterID is required field that's also immutable Signed-off-by: raaizik <132667934+raaizik@users.noreply.github.com> --- api/v1alpha1/drclusterconfig_types.go | 2 ++ config/crd/bases/ramendr.openshift.io_drclusterconfigs.yaml | 5 +++++ internal/controller/drclusterconfig_controller_test.go | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/drclusterconfig_types.go b/api/v1alpha1/drclusterconfig_types.go index eebc817b9..9113b4898 100644 --- a/api/v1alpha1/drclusterconfig_types.go +++ b/api/v1alpha1/drclusterconfig_types.go @@ -21,6 +21,8 @@ type DRClusterConfigSpec struct { // provider reconcilers ReplicationSchedules []string `json:"replicationSchedules,omitempty"` + // +kubebuilder:validation:Required + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ClusterID is immutable" // ClusterID would carry the ManagedCluster identity from the ManagedCluster claim value for `id.k8s.io` ClusterID string `json:"clusterID,omitempty"` diff --git a/config/crd/bases/ramendr.openshift.io_drclusterconfigs.yaml b/config/crd/bases/ramendr.openshift.io_drclusterconfigs.yaml index f687dff92..cbb4e86f0 100644 --- a/config/crd/bases/ramendr.openshift.io_drclusterconfigs.yaml +++ b/config/crd/bases/ramendr.openshift.io_drclusterconfigs.yaml @@ -49,6 +49,9 @@ spec: description: ClusterID would carry the ManagedCluster identity from the ManagedCluster claim value for `id.k8s.io` type: string + x-kubernetes-validations: + - message: ClusterID is immutable + rule: self == oldSelf replicationSchedules: description: |- ReplicationSchedules desired from storage providers for replicating Persistent Volume data to a peer cluster. @@ -59,6 +62,8 @@ spec: items: type: string type: array + required: + - clusterID type: object status: description: DRClusterConfigStatus defines the observed state of DRClusterConfig diff --git a/internal/controller/drclusterconfig_controller_test.go b/internal/controller/drclusterconfig_controller_test.go index 5a3d217fc..2dc7c3e50 100644 --- a/internal/controller/drclusterconfig_controller_test.go +++ b/internal/controller/drclusterconfig_controller_test.go @@ -159,7 +159,7 @@ var _ = Describe("DRClusterConfig-ClusterClaimsTests", Ordered, func() { drCConfig = &ramen.DRClusterConfig{ ObjectMeta: metav1.ObjectMeta{Name: "local"}, - Spec: ramen.DRClusterConfigSpec{}, + Spec: ramen.DRClusterConfigSpec{ClusterID: "local-cid"}, } Expect(k8sClient.Create(context.TODO(), drCConfig)).To(Succeed())