Skip to content

Commit

Permalink
reset KafkaInit as false (stolostron#889)
Browse files Browse the repository at this point in the history
* reset KafkaInit as false

Signed-off-by: clyang82 <[email protected]>

* mghReconciler was reset so that manager is nil

Signed-off-by: clyang82 <[email protected]>

---------

Signed-off-by: clyang82 <[email protected]>
  • Loading branch information
clyang82 authored Apr 22, 2024
1 parent 3b0baaf commit f3a5026
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
3 changes: 1 addition & 2 deletions operator/pkg/controllers/hubofhubs/globalhub_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions operator/pkg/controllers/hubofhubs/globalhub_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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())
}
Expand Down
7 changes: 1 addition & 6 deletions operator/pkg/controllers/hubofhubs/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f3a5026

Please sign in to comment.