Skip to content

Commit

Permalink
Merge pull request #2971 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2970-to-release-4.18

DFBUGS-1357:[release-4.18] Avoid reconciling rook-ceph-operator-config via the external controller
  • Loading branch information
openshift-merge-bot[bot] authored Jan 21, 2025
2 parents 7fedea3 + 09896a1 commit 3a27363
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 78 deletions.
3 changes: 3 additions & 0 deletions controllers/ocsinitialization/ocsinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ func (r *OCSInitializationReconciler) ensureRookCephOperatorConfigExists(initial
return err // nolint:revive
}

// TODO: remove this in the next release, look at commit msg for more info
delete(rookCephOperatorConfig.Data, "ROOK_CSI_ENABLE_CEPHFS")

return nil
})

Expand Down
36 changes: 0 additions & 36 deletions controllers/storagecluster/external_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ const (
cephRgwTLSSecretKey = "ceph-rgw-tls-cert"
)

const (
rookCephOperatorConfigName = "rook-ceph-operator-config"
rookEnableCephFSCSIKey = "ROOK_CSI_ENABLE_CEPHFS"
)

// store the name of the rados-namespace
var radosNamespaceName string

Expand All @@ -59,29 +54,6 @@ type ExternalResource struct {

type ocsExternalResources struct{}

// setRookCSICephFS function enables or disables the 'ROOK_CSI_ENABLE_CEPHFS' key
func (r *StorageClusterReconciler) setRookCSICephFS(
enableDisableFlag bool, instance *ocsv1.StorageCluster) error {
rookCephOperatorConfig := &corev1.ConfigMap{}
err := r.Client.Get(context.TODO(),
types.NamespacedName{Name: rookCephOperatorConfigName, Namespace: instance.ObjectMeta.Namespace},
rookCephOperatorConfig)
if err != nil {
r.Log.Error(err, "Unable to get RookCeph ConfigMap.", "RookCephConfigMap", klog.KRef(instance.Namespace, rookCephOperatorConfigName))
return err
}
enableDisableFlagStr := fmt.Sprintf("%v", enableDisableFlag)
if rookCephOperatorConfig.Data == nil {
rookCephOperatorConfig.Data = map[string]string{}
}
// if the current state of 'ROOK_CSI_ENABLE_CEPHFS' flag is same, just return
if rookCephOperatorConfig.Data[rookEnableCephFSCSIKey] == enableDisableFlagStr {
return nil
}
rookCephOperatorConfig.Data[rookEnableCephFSCSIKey] = enableDisableFlagStr
return r.Client.Update(context.TODO(), rookCephOperatorConfig)
}

func checkEndpointReachable(endpoint string, timeout time.Duration) error {
rxp := regexp.MustCompile(`^http[s]?://`)
// remove any http or https protocols from the endpoint string
Expand Down Expand Up @@ -288,8 +260,6 @@ func (r *StorageClusterReconciler) createExternalStorageClusterResources(instanc
Kind: instance.Kind,
Name: instance.Name,
}
// this flag sets the 'ROOK_CSI_ENABLE_CEPHFS' flag
enableRookCSICephFS := false
// this stores only the StorageClasses specified in the Secret
availableSCCs := []StorageClassConfiguration{}

Expand Down Expand Up @@ -372,7 +342,6 @@ func (r *StorageClusterReconciler) createExternalStorageClusterResources(instanc
var err error
if d.Name == cephFsStorageClassName {
scc = newCephFilesystemStorageClassConfiguration(instance)
enableRookCSICephFS = true
} else if d.Name == cephRbdStorageClassName {
scc = newCephBlockPoolStorageClassConfiguration(instance)
} else if strings.HasPrefix(d.Name, cephRbdRadosNamespaceStorageClassNamePrefix) { // ceph-rbd-rados-namespace-<radosNamespaceName>
Expand Down Expand Up @@ -421,11 +390,6 @@ func (r *StorageClusterReconciler) createExternalStorageClusterResources(instanc
return err
}

if err = r.setRookCSICephFS(enableRookCSICephFS, instance); err != nil {
r.Log.Error(err, "Failed to set RookEnableCephFSCSIKey to EnableRookCSICephFS.", "RookEnableCephFSCSIKey", rookEnableCephFSCSIKey, "EnableRookCSICephFS", enableRookCSICephFS)
return err
}

if rgwEndpoint != "" {
if err := checkEndpointReachable(rgwEndpoint, 5*time.Second); err != nil {
r.Log.Error(err, "RGW endpoint is not reachable.", "RGWEndpoint", rgwEndpoint)
Expand Down
47 changes: 5 additions & 42 deletions controllers/storagecluster/external_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ func TestEnsureExternalStorageClusterResources(t *testing.T) {
assertExpectedExternalResources(t, reconciler)
}

func newRookCephOperatorConfig(namespace string) *corev1.ConfigMap {
config := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: rookCephOperatorConfigName,
Namespace: namespace,
},
}
data := make(map[string]string)
config.Data = data
return config
}

func createExternalCephClusterSecret(extResources []ExternalResource) (*corev1.Secret, error) {
jsonBlob, err := json.Marshal(extResources)
if err != nil {
Expand Down Expand Up @@ -156,9 +144,8 @@ func createExternalClusterReconcilerFromCustomResources(
if err != nil {
t.Fatalf("failed to create external secret: %v", err)
}
rookCephConfig := newRookCephOperatorConfig("")
reconciler := createFakeInitializationStorageClusterReconciler(t, &nbv1.NooBaa{})
clientObjs := []client.Object{cr, externalSecret, rookCephConfig}
clientObjs := []client.Object{cr, externalSecret}
for _, obj := range clientObjs {
if err = reconciler.Client.Create(context.TODO(), obj); err != nil {
t.Fatalf("failed to create a needed runtime object: %v", err)
Expand Down Expand Up @@ -292,14 +279,12 @@ func TestOptionalExternalStorageClusterResources(t *testing.T) {
expectedRookCephConfigVal string
}{
{
label: "RemoveRGW",
resourceToBeRemoved: "ceph-rgw",
expectedRookCephConfigVal: "true",
label: "RemoveRGW",
resourceToBeRemoved: "ceph-rgw",
},
{
label: "RemoveCephFS",
resourceToBeRemoved: "cephfs",
expectedRookCephConfigVal: "false",
label: "RemoveCephFS",
resourceToBeRemoved: "cephfs",
},
}

Expand All @@ -314,34 +299,12 @@ func TestOptionalExternalStorageClusterResources(t *testing.T) {
assertExpectedExternalResources(t, reconciler)
// make sure we are missing the provided resource
assertMissingExternalResource(t, reconciler, testParam.resourceToBeRemoved)
// make sure that we have expected rook ceph config value
assertRookCephOperatorConfigValue(t, reconciler, testParam.expectedRookCephConfigVal)
// make sure about the availability of 'CephObjectStore' according to the resource removed
assertCephObjectStore(t, reconciler, testParam.resourceToBeRemoved)
})
}
}

func assertRookCephOperatorConfigValue(t *testing.T, reconciler StorageClusterReconciler, checkValue string) {
request := reconcile.Request{
NamespacedName: types.NamespacedName{
Name: "ocsinit",
Namespace: "",
},
}
sc := &api.StorageCluster{}
err := reconciler.Client.Get(context.TODO(), request.NamespacedName, sc)
assert.NoError(t, err)
rookCephOperatorConfig := &corev1.ConfigMap{}
err = reconciler.Client.Get(context.TODO(),
types.NamespacedName{Name: rookCephOperatorConfigName, Namespace: sc.ObjectMeta.Namespace},
rookCephOperatorConfig)
assert.NoErrorf(t, err, "Unable to get '%s' config", rookCephOperatorConfigName)
assert.Truef(t,
rookCephOperatorConfig.Data[rookEnableCephFSCSIKey] == checkValue,
"'%s' key is supposed to be '%s'", rookEnableCephFSCSIKey, checkValue)
}

func assertMissingExternalResource(t *testing.T, reconciler StorageClusterReconciler, resourceName string) {
request := reconcile.Request{
NamespacedName: types.NamespacedName{
Expand Down

0 comments on commit 3a27363

Please sign in to comment.