Merge pull request #10241 from rook/mergify/bp/release-1.9/pr-10226

webhook: update the check-in cluster spec validation (backport #10226)
This commit is contained in:
mergify[bot] authored and GitHub committed 2022-05-10 14:43:26 +00:00
commit a58d1a8c26
3 files changed
+31 -4

No files matched your search

+2 -1
View File
@@ -31,7 +31,8 @@
"security",
"subvolumegroup",
"namespace",
"test"
"test",
"webhook"
]
],
"body-leading-blank": [
+5 -3
View File
@@ -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)
}
}
}
+24
View File
@@ -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)
}