Skip to content

Commit

Permalink
add support for enabling clusterwide encryption as day-2 operation
Browse files Browse the repository at this point in the history
Signed-off-by: Santosh Pillai <[email protected]>
  • Loading branch information
sp98 committed Jan 20, 2025
1 parent 9ae10c8 commit f48e5c6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions controllers/storagecluster/cephcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ func (obj *ocsCephCluster) ensureCreated(r *StorageClusterReconciler, sc *ocsv1.
// Update OSD store to `bluestore`
cephCluster.Spec.Storage.Store = updateOSDStore(found.Spec.Storage.Store)

// confirm OSD migration if encryption is enabled as day-2 operation
if isEncrptionSettingUpdated(sc.Spec.Encryption.ClusterWide, found.Spec.Storage.StorageClassDeviceSets) {
cephCluster.Spec.Storage.Migration.Confirmation = "yes-really-migrate-osds"
} else {
// keeping the same expected state in the corresponding reconcile once encryption is enabled
cephCluster.Spec.Storage.Migration.Confirmation = found.Spec.Storage.Migration.Confirmation
}

// Add it to the list of RelatedObjects if found
objectRef, err := reference.GetReference(r.Scheme, found)
if err != nil {
Expand Down Expand Up @@ -1399,3 +1407,14 @@ func determineDefaultCephDeviceClass(foundDeviceClasses []rookCephv1.DeviceClass
// if no device classes are found in status return empty string
return ""
}

// isEncrptionSettingUpdated checks whether ecryption was enabled or disabled by comparing the new clusterWide encryption setting
// with the encryption setting on existing StorageClassDeviceSets.
func isEncrptionSettingUpdated(clusterWideEncrytion bool, existingDeviceSet []rookCephv1.StorageClassDeviceSet) bool {
for i := range existingDeviceSet {
if existingDeviceSet[i].Encrypted != clusterWideEncrytion {
return true
}
}
return false
}
21 changes: 21 additions & 0 deletions controllers/storagecluster/cephcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1675,3 +1675,24 @@ func TestDetermineDefaultCephDeviceClass(t *testing.T) {
assert.Equal(t, c.expectedDeviceClass, actual)
}
}

func TestIsEncrptionSettingUpdated(t *testing.T) {
newStorageClassDeviceSet := []rookCephv1.StorageClassDeviceSet{
{
Name: "set1",
Encrypted: false,
},
{
Name: "set2",
Encrypted: false,
},
}

// encryption setting has changed
actualResult := isEncrptionSettingUpdated(true, newStorageClassDeviceSet)
assert.Equal(t, true, actualResult)

// encryption setting has not changed
actualResult = isEncrptionSettingUpdated(false, newStorageClassDeviceSet)
assert.Equal(t, false, actualResult)
}

0 comments on commit f48e5c6

Please sign in to comment.