From 5b822cc2809dc02fd8b44f2cc3118e92b660cebc Mon Sep 17 00:00:00 2001 From: subhamkrai Date: Mon, 9 May 2022 11:26:23 +0530 Subject: [PATCH 1/2] ci: add webhook to commitlint title Signed-off-by: subhamkrai (cherry picked from commit 99420ad779137c837bfa04ef889fb4247644953b) --- .commitlintrc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.commitlintrc.json b/.commitlintrc.json index ab1b61bd0..67ec23933 100644 --- a/.commitlintrc.json +++ b/.commitlintrc.json @@ -31,7 +31,8 @@ "security", "subvolumegroup", "namespace", - "test" + "test", + "webhook" ] ], "body-leading-blank": [ From e582035c88556571f37e13c64cd282b301b039b3 Mon Sep 17 00:00:00 2001 From: subhamkrai Date: Mon, 9 May 2022 11:20:51 +0530 Subject: [PATCH 2/2] webhook: update the check-in cluster spec validation we should iterate older clusters spec instead of new cluster spec since in case of new storageClassdeviceset added in spec. The total count of the new clusters and older spec cluster is will not be the same and we'll get panic. Closes: https://github.com/rook/rook/issues/10222 Signed-off-by: subhamkrai (cherry picked from commit 0c593d5420f10bf73de9c4a1a927e32f08e77ddb) --- pkg/apis/ceph.rook.io/v1/cluster.go | 8 +++++--- pkg/apis/ceph.rook.io/v1/cluster_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pkg/apis/ceph.rook.io/v1/cluster.go b/pkg/apis/ceph.rook.io/v1/cluster.go index 94763d46d..bfe14b57b 100644 --- a/pkg/apis/ceph.rook.io/v1/cluster.go +++ b/pkg/apis/ceph.rook.io/v1/cluster.go @@ -81,9 +81,11 @@ func validateUpdatedCephCluster(updatedCephCluster *CephCluster, found *CephClus return errors.Errorf("invalid update: Provider change from %q to %q is not allowed", found.Spec.Network.Provider, updatedCephCluster.Spec.Network.Provider) } - for i, storageClassDeviceSet := range updatedCephCluster.Spec.Storage.StorageClassDeviceSets { - if storageClassDeviceSet.Encrypted != found.Spec.Storage.StorageClassDeviceSets[i].Encrypted { - return errors.Errorf("invalid update: StorageClassDeviceSet %q encryption change from %t to %t is not allowed", storageClassDeviceSet.Name, found.Spec.Storage.StorageClassDeviceSets[i].Encrypted, storageClassDeviceSet.Encrypted) + if len(updatedCephCluster.Spec.Storage.StorageClassDeviceSets) == len(found.Spec.Storage.StorageClassDeviceSets) { + for i, storageClassDeviceSet := range found.Spec.Storage.StorageClassDeviceSets { + if storageClassDeviceSet.Encrypted != updatedCephCluster.Spec.Storage.StorageClassDeviceSets[i].Encrypted { + return errors.Errorf("invalid update: StorageClassDeviceSet %q encryption change from %t to %t is not allowed", storageClassDeviceSet.Name, found.Spec.Storage.StorageClassDeviceSets[i].Encrypted, storageClassDeviceSet.Encrypted) + } } } diff --git a/pkg/apis/ceph.rook.io/v1/cluster_test.go b/pkg/apis/ceph.rook.io/v1/cluster_test.go index 675a62190..22e896284 100644 --- a/pkg/apis/ceph.rook.io/v1/cluster_test.go +++ b/pkg/apis/ceph.rook.io/v1/cluster_test.go @@ -76,6 +76,14 @@ func TestCephClusterValidateUpdate(t *testing.T) { }, Spec: ClusterSpec{ DataDirHostPath: "/var/lib/rook", + Storage: StorageScopeSpec{ + StorageClassDeviceSets: []StorageClassDeviceSet{ + { + Name: "sc1", + Encrypted: true, + }, + }, + }, }, } err := c.ValidateCreate() @@ -84,6 +92,22 @@ func TestCephClusterValidateUpdate(t *testing.T) { // Updating the CRD specs with invalid values uc := c.DeepCopy() uc.Spec.DataDirHostPath = "var/rook" + uc.Spec.Storage.StorageClassDeviceSets[0].Encrypted = false err = uc.ValidateUpdate(c) assert.Error(t, err) + + // reverting the to older hostPath + uc.Spec.DataDirHostPath = "/var/lib/rook" + uc.Spec.Storage.StorageClassDeviceSets = []StorageClassDeviceSet{ + { + Name: "sc1", + Encrypted: true, + }, + { + Name: "sc2", + }, + } + + err = uc.ValidateUpdate(c) + assert.NoError(t, err) }