Skip to content

Commit

Permalink
Merge pull request #2291 from iamniting/noobaa
Browse files Browse the repository at this point in the history
skip NooBaa reconcile unless requested from same namespace as operator
  • Loading branch information
openshift-merge-bot[bot] authored Dec 1, 2023
2 parents 07bb8ae + 5e4ed8a commit 2272c2c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
10 changes: 10 additions & 0 deletions controllers/storagecluster/noobaa_system_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const (
type ocsNoobaaSystem struct{}

func (obj *ocsNoobaaSystem) ensureCreated(r *StorageClusterReconciler, sc *ocsv1.StorageCluster) (reconcile.Result, error) {
// skip noobaa reconcile if it is not requested from same namespace as operator
if sc.Namespace != r.OperatorNamespace {
return reconcile.Result{}, nil
}

var err error
var reconcileStrategy ReconcileStrategy

Expand Down Expand Up @@ -240,6 +245,11 @@ func (r *StorageClusterReconciler) setNooBaaDesiredState(nb *nbv1.NooBaa, sc *oc

// ensureDeleted Delete noobaa system in the namespace
func (obj *ocsNoobaaSystem) ensureDeleted(r *StorageClusterReconciler, sc *ocsv1.StorageCluster) (reconcile.Result, error) {
// skip noobaa reconcile if it is not requested from same namespace as operator
if sc.Namespace != r.OperatorNamespace {
return reconcile.Result{}, nil
}

// Delete only if this is being managed by the OCS operator
if sc.Spec.MultiCloudGateway != nil {
reconcileStrategy := ReconcileStrategy(sc.Spec.MultiCloudGateway.ReconcileStrategy)
Expand Down
61 changes: 56 additions & 5 deletions controllers/storagecluster/noobaa_system_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var noobaaReconcileTestLogger = logf.Log.WithName("noobaa_system_reconciler_test
func TestEnsureNooBaaSystem(t *testing.T) {
namespacedName := types.NamespacedName{
Name: "noobaa",
Namespace: "test_ns",
Namespace: "openshift-storage",
}
sc := v1.StorageCluster{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -130,10 +130,60 @@ func TestEnsureNooBaaSystem(t *testing.T) {
}
}

func TestNooBaaSkipUnskip(t *testing.T) {
t.Run("Ensure noobaa is skipped in namespace other than operator namespace", func(t *testing.T) {
var obj ocsNoobaaSystem
reconciler := getReconciler(t, &nbv1.NooBaa{})
sc := v1.StorageCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "ocs",
Namespace: "test-ns",
},
}
_, err := obj.ensureCreated(&reconciler, &sc)
assert.NoError(t, err)

noobaa := &nbv1.NooBaa{}
err = reconciler.Client.Get(context.TODO(), types.NamespacedName{Namespace: sc.Namespace, Name: "noobaa"}, noobaa)
assert.True(t, errors.IsNotFound(err))
})

t.Run("Ensure noobaa is created in namespace same as operator namespace", func(t *testing.T) {
var obj ocsNoobaaSystem
reconciler := getReconciler(t, &nbv1.NooBaa{})
sc := v1.StorageCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "ocs",
Namespace: "openshift-storage",
},
Status: v1.StorageClusterStatus{
Images: v1.ImagesStatus{
NooBaaCore: &v1.ComponentImageStatus{},
NooBaaDB: &v1.ComponentImageStatus{},
},
},
}

cephCluster := cephv1.CephCluster{}
cephCluster.Name = generateNameForCephClusterFromString(sc.Name)
cephCluster.Namespace = sc.Namespace
cephCluster.Status.State = cephv1.ClusterStateCreated
err := reconciler.Client.Create(context.TODO(), &cephCluster)
assert.NoError(t, err)

_, err = obj.ensureCreated(&reconciler, &sc)
assert.NoError(t, err)

noobaa := &nbv1.NooBaa{}
err = reconciler.Client.Get(context.TODO(), types.NamespacedName{Namespace: sc.Namespace, Name: "noobaa"}, noobaa)
assert.NoError(t, err)
})
}

func TestNooBaaReconcileStrategy(t *testing.T) {
namespacedName := types.NamespacedName{
Name: "noobaa",
Namespace: "test_ns",
Namespace: "openshift-storage",
}

cases := []struct {
Expand Down Expand Up @@ -404,9 +454,10 @@ func getReconciler(t *testing.T, objs ...runtime.Object) StorageClusterReconcile
client := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(registerObjs...).WithStatusSubresource(sc).Build()

return StorageClusterReconciler{
Scheme: scheme,
Client: client,
platform: &Platform{},
Scheme: scheme,
Client: client,
platform: &Platform{},
OperatorNamespace: "openshift-storage",
}
}

Expand Down

0 comments on commit 2272c2c

Please sign in to comment.