Skip to content

Commit

Permalink
Adds CEL rule for clusterID
Browse files Browse the repository at this point in the history
ClusterID is required field that's also immutable

Signed-off-by: raaizik <[email protected]>
  • Loading branch information
raaizik committed Jan 2, 2025
1 parent 8f2da93 commit 6ecb3b3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/v1alpha1/drclusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/ramendr.openshift.io_drclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -59,6 +62,8 @@ spec:
items:
type: string
type: array
required:
- clusterID
type: object
status:
description: DRClusterConfigStatus defines the observed state of DRClusterConfig
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/drclusterconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit 6ecb3b3

Please sign in to comment.