From 36498063852ea16b637c3f8c78e9249d983085c9 Mon Sep 17 00:00:00 2001 From: Nitin Goyal Date: Wed, 27 Nov 2024 18:01:42 +0530 Subject: [PATCH] controllers: create odf-deps sub while starting manager creating odf-deps subscription while starting manager will speed up the process. Signed-off-by: Nitin Goyal --- controllers/subscription_controller.go | 9 +++++++++ controllers/subscriptions.go | 2 ++ controllers/subscriptions_test.go | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/controllers/subscription_controller.go b/controllers/subscription_controller.go index 6f64a2b30..f82e36c02 100644 --- a/controllers/subscription_controller.go +++ b/controllers/subscription_controller.go @@ -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" @@ -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)). diff --git a/controllers/subscriptions.go b/controllers/subscriptions.go index 9bd42ec14..f12aad3f2 100644 --- a/controllers/subscriptions.go +++ b/controllers/subscriptions.go @@ -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} } diff --git a/controllers/subscriptions_test.go b/controllers/subscriptions_test.go index 54ec512be..ce7d80b14 100644 --- a/controllers/subscriptions_test.go +++ b/controllers/subscriptions_test.go @@ -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 {