From ebdc58bcd52b4505ac8b2713443e39250270cd29 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 24 Dec 2024 08:19:04 +0000 Subject: [PATCH] fix some issue about upgrade Signed-off-by: root --- operator/pkg/controllers/agent/addon_manager.go | 4 +++- .../controllers/transporter/protocol/strimzi_transporter.go | 6 ++++++ pkg/constants/constants.go | 3 ++- test/integration/operator/controllers/agent/suite_test.go | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/operator/pkg/controllers/agent/addon_manager.go b/operator/pkg/controllers/agent/addon_manager.go index 36056337a..8727b93b3 100644 --- a/operator/pkg/controllers/agent/addon_manager.go +++ b/operator/pkg/controllers/agent/addon_manager.go @@ -50,7 +50,9 @@ func ReadyToEnableAddonManager(mgh *v1alpha4.MulticlusterGlobalHub) bool { if !config.IsACMResourceReady() { return false } - + if config.GetTransporterConn() == nil { + return false + } if !meta.IsStatusConditionTrue(mgh.Status.Conditions, config.CONDITION_TYPE_GLOBALHUB_READY) { return false } diff --git a/operator/pkg/controllers/transporter/protocol/strimzi_transporter.go b/operator/pkg/controllers/transporter/protocol/strimzi_transporter.go index ef1e6d59f..8e5ffca4e 100644 --- a/operator/pkg/controllers/transporter/protocol/strimzi_transporter.go +++ b/operator/pkg/controllers/transporter/protocol/strimzi_transporter.go @@ -33,6 +33,7 @@ import ( operatorutils "github.com/stolostron/multicluster-global-hub/operator/pkg/utils" "github.com/stolostron/multicluster-global-hub/pkg/constants" "github.com/stolostron/multicluster-global-hub/pkg/transport" + "github.com/stolostron/multicluster-global-hub/pkg/utils" ) const ( @@ -629,6 +630,8 @@ func (k *strimziTransporter) kafkaClusterReady() (KafkaStatus, error) { return kafkaStatus, nil } + k.isNewKafkaCluster = utils.HasAnnotation(kafkaCluster, constants.UpgradeKafkaFromZookeeperAnnotation) + if kafkaCluster.Spec != nil && kafkaCluster.Spec.Kafka.Listeners != nil { // if the kafka cluster is already created, check if the tls is enabled enableTLS := false @@ -781,6 +784,9 @@ func (k *strimziTransporter) newKafkaCluster(mgh *operatorv1alpha4.MulticlusterG }, }, } + if k.isNewKafkaCluster { + kafkaCluster.Annotations[constants.UpgradeKafkaFromZookeeperAnnotation] = "true" + } k.setAffinity(mgh, kafkaCluster) k.setTolerations(mgh, kafkaCluster) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 26b4ca154..4ea0858da 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -115,7 +115,8 @@ const ( ManagedClusterManagedByAnnotation = "global-hub.open-cluster-management.io/managed-by" // identify the resource is from the global hub cluster OriginOwnerReferenceAnnotation = "global-hub.open-cluster-management.io/origin-ownerreference-uid" - + // identy the kafka is upgrade from zookeeper mode + UpgradeKafkaFromZookeeperAnnotation = "global-hub.open-cluster-management.io/upgrade-from-zookeeper" // resync the kafka client secret in agent ResyncKafkaClientSecretAnnotation = "global-hub.open-cluster-management.io/resign-kafka-client-secret" // #nosec G101 ) diff --git a/test/integration/operator/controllers/agent/suite_test.go b/test/integration/operator/controllers/agent/suite_test.go index 02d09da5f..2dd2a78ad 100644 --- a/test/integration/operator/controllers/agent/suite_test.go +++ b/test/integration/operator/controllers/agent/suite_test.go @@ -43,6 +43,7 @@ import ( "github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/agent" operatortrans "github.com/stolostron/multicluster-global-hub/operator/pkg/controllers/transporter/protocol" "github.com/stolostron/multicluster-global-hub/pkg/constants" + "github.com/stolostron/multicluster-global-hub/pkg/transport" "github.com/stolostron/multicluster-global-hub/pkg/utils" ) @@ -122,6 +123,11 @@ var _ = BeforeSuite(func() { EnablePprof: false, }, } + config.SetTransporterConn(&transport.KafkaConfig{ + ClusterID: "fake", + IsNewKafkaCluster: true, + }) + By("start the addon manager and add addon controller to manager") _, err = agent.StartAddonManagerController(controllerOption) Expect(err).ToNot(HaveOccurred())