Skip to content

Commit

Permalink
controllers: create odf-deps sub while starting manager
Browse files Browse the repository at this point in the history
creating odf-deps subscription while starting manager will speed up the
process.

Signed-off-by: Nitin Goyal <nigoyal@redhat.com>
  • Loading branch information
iamniting committed Dec 4, 2024
1 parent dbd6113 commit 3649806
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/subscription_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -290,6 +291,14 @@ func (r *SubscriptionReconciler) SetupWithManager(mgr ctrl.Manager) error {
},
)

err := mgr.Add(manager.RunnableFunc(func(ctx context.Context) error {
odfDepsSub := GetStorageClusterSubscriptions()[0]
return EnsureDesiredSubscription(r.Client, odfDepsSub)
}))
if err != nil {
return err
}

return ctrl.NewControllerManagedBy(mgr).
For(&operatorv1alpha1.Subscription{},
builder.WithPredicates(generationChangedPredicate, subscriptionPredicate)).
Expand Down
2 changes: 2 additions & 0 deletions controllers/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ func GetStorageClusterSubscriptions() []*operatorv1alpha1.Subscription {
},
}

// Do not change the inxex of odfDepsSubscription. The 0 index is being used to create this subscription
// while starting in the subscription controller in SetupWithManager.
return []*operatorv1alpha1.Subscription{odfDepsSubscription, ocsSubscription, rookSubscription, noobaaSubscription,
csiAddonsSubscription, cephCsiSubscription, ocsClientSubscription, prometheusSubscription, recipeSubscription}
}
Expand Down
7 changes: 7 additions & 0 deletions controllers/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import (
odfv1alpha1 "github.com/red-hat-storage/odf-operator/api/v1alpha1"
)

func TestSubscriptionIndex(t *testing.T) {
odfDepsSub := GetStorageClusterSubscriptions()[0]
msg := "odfDepsSub variable is expected to contain the 'odf-dependencies' subscription. " +
"Ensure the 'odf-dependencies' subscription indexed at 0."
assert.Equal(t, OdfDepsSubscriptionPackage, odfDepsSub.Spec.Package, msg)
}

func TestEnsureSubscription(t *testing.T) {

testCases := []struct {
Expand Down

0 comments on commit 3649806

Please sign in to comment.