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": [ 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) }