diff --git a/operator/pkg/controllers/hubofhubs/globalhub_middleware.go b/operator/pkg/controllers/hubofhubs/globalhub_middleware.go index 170ee7770..99395f2e5 100644 --- a/operator/pkg/controllers/hubofhubs/globalhub_middleware.go +++ b/operator/pkg/controllers/hubofhubs/globalhub_middleware.go @@ -34,7 +34,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/stolostron/multicluster-global-hub/operator/apis/v1alpha4" - globalhubv1alpha4 "github.com/stolostron/multicluster-global-hub/operator/apis/v1alpha4" "github.com/stolostron/multicluster-global-hub/operator/pkg/config" "github.com/stolostron/multicluster-global-hub/operator/pkg/deployer" "github.com/stolostron/multicluster-global-hub/operator/pkg/postgres" @@ -266,7 +265,7 @@ func detectTransportProtocol(ctx context.Context, runtimeClient client.Client) ( // renderKafkaMetricsResources renders the kafka podmonitor and metrics func (r *MulticlusterGlobalHubReconciler) renderKafkaMetricsResources( - mgh *globalhubv1alpha4.MulticlusterGlobalHub, + mgh *v1alpha4.MulticlusterGlobalHub, ) error { if mgh.Spec.EnableMetrics { // render the kafka objects diff --git a/operator/pkg/controllers/hubofhubs/globalhub_upgrade_test.go b/operator/pkg/controllers/hubofhubs/globalhub_upgrade_test.go index 4c6b0d479..f8d5c9e58 100644 --- a/operator/pkg/controllers/hubofhubs/globalhub_upgrade_test.go +++ b/operator/pkg/controllers/hubofhubs/globalhub_upgrade_test.go @@ -23,13 +23,12 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" clusterv1 "open-cluster-management.io/api/cluster/v1" - ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "github.com/stolostron/multicluster-global-hub/operator/pkg/constants" - hubofhubscontroller "github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/hubofhubs" commonconstants "github.com/stolostron/multicluster-global-hub/pkg/constants" ) @@ -59,13 +58,24 @@ var _ = Describe("MulticlusterGlobalHub upgrade", Ordered, func() { } Expect(k8sClient.Create(ctx, testMangedCluster)).Should(Succeed()) - By("Create the reconciler") - mghReconciler = &hubofhubscontroller.MulticlusterGlobalHubReconciler{ - Client: k8sClient, - Log: ctrl.Log.WithName("multicluster-global-hub-reconciler"), - } - err := mghReconciler.Upgrade(ctx) - Expect(err).Should(Succeed()) + // ensure the cluster is created successfully + Eventually(func() error { + cluster := &clusterv1.ManagedCluster{} + if err := k8sClient.Get(ctx, types.NamespacedName{ + Name: "test-managed-hub", + }, cluster, &client.GetOptions{}); err != nil { + return err + } + return nil + }, 1*time.Second, 100*time.Millisecond).Should(Succeed()) + + Eventually(func() error { + err := mghReconciler.Upgrade(ctx) + if err != nil { + return err + } + return nil + }, 1*time.Second, 100*time.Millisecond).Should(Succeed()) By("Check the finalizer should be removed from the managed hub cluster") Eventually(func() error { @@ -80,7 +90,7 @@ var _ = Describe("MulticlusterGlobalHub upgrade", Ordered, func() { continue } - ok := controllerutil.RemoveFinalizer(managedHub, commonconstants.GlobalHubCleanupFinalizer) + ok := controllerutil.ContainsFinalizer(managedHub, commonconstants.GlobalHubCleanupFinalizer) if ok { return fmt.Errorf("the finalizer should be removed from cluster %s", managedHub.GetName()) } diff --git a/operator/pkg/controllers/hubofhubs/integration_test.go b/operator/pkg/controllers/hubofhubs/integration_test.go index f9b181be1..d5850bc3d 100644 --- a/operator/pkg/controllers/hubofhubs/integration_test.go +++ b/operator/pkg/controllers/hubofhubs/integration_test.go @@ -937,6 +937,7 @@ var _ = Describe("MulticlusterGlobalHub controller", Ordered, func() { if mghReconciler.MiddlewareConfig == nil { mghReconciler.MiddlewareConfig = &hubofhubs.MiddlewareConfig{} } + mghReconciler.KafkaInit = false mghReconciler.MiddlewareConfig.StorageConn = nil mghReconciler.MiddlewareConfig.TransportConn = nil mghReconciler.ReconcileMiddleware(ctx, mcgh) @@ -1032,12 +1033,6 @@ var _ = Describe("MulticlusterGlobalHub controller", Ordered, func() { It("Should get the postgres connection", func() { Eventually(func() error { - if mghReconciler.Manager == nil { - mghReconciler.Manager = k8sManager - } - if mghReconciler.Scheme == nil { - mghReconciler.Scheme = k8sManager.GetScheme() - } var err error mghReconciler.MiddlewareConfig.StorageConn, err = mghReconciler.InitPostgresByStatefulset(ctx, mcgh) if err != nil {