diff --git a/operator/pkg/config/status.go b/operator/pkg/config/status.go index a638b6b67..a5b320746 100644 --- a/operator/pkg/config/status.go +++ b/operator/pkg/config/status.go @@ -232,6 +232,7 @@ func NeedUpdateConditions(conditions []metav1.Condition, func UpdateMGHComponent(ctx context.Context, c client.Client, desiredComponent v1alpha4.StatusCondition, + forceUpdate bool, ) error { now := metav1.Time{Time: time.Now()} desiredComponent.LastTransitionTime = now @@ -248,8 +249,7 @@ func UpdateMGHComponent(ctx context.Context, } else { originComponent := curmgh.Status.Components[desiredComponent.Name] originComponent.LastTransitionTime = now - - if reflect.DeepEqual(desiredComponent, originComponent) { + if !forceUpdate && reflect.DeepEqual(desiredComponent, originComponent) { return nil } } diff --git a/operator/pkg/config/storage_config.go b/operator/pkg/config/storage_config.go index c66f31630..8888a8008 100644 --- a/operator/pkg/config/storage_config.go +++ b/operator/pkg/config/storage_config.go @@ -141,14 +141,16 @@ func GetPGConnectionFromBuildInPostgres(ctx context.Context, client client.Clien // SetStorageConnection update the postgres connection func SetStorageConnection(conn *PostgresConnection) bool { + log.Debugf("Set Storage Connection: %v", conn == nil) if conn != nil && !reflect.DeepEqual(conn, postgresConn) { postgresConn = conn + log.Debugf("Update Storage Connection") return true } return false } func GetStorageConnection() *PostgresConnection { - log.Debugf("Set Storage Connection: %v", postgresConn != nil) + log.Debugf("Get Storage Connection: %v", postgresConn != nil) return postgresConn } diff --git a/operator/pkg/config/transport_config.go b/operator/pkg/config/transport_config.go index 00ab71157..cb0883be9 100644 --- a/operator/pkg/config/transport_config.go +++ b/operator/pkg/config/transport_config.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "reflect" "regexp" "strings" @@ -42,9 +43,14 @@ var ( inventoryConn *transport.RestfulConfig ) -func SetTransporterConn(conn *transport.KafkaConfig) { - log.Debug("Set Transporter Conn") - transporterConn = conn +func SetTransporterConn(conn *transport.KafkaConfig) bool { + log.Debug("set Transporter Conn") + if conn != nil && !reflect.DeepEqual(conn, transporterConn) { + transporterConn = conn + log.Debug("update Transporter Conn") + return true + } + return false } func GetTransporterConn() *transport.KafkaConfig { diff --git a/operator/pkg/controllers/acm/resources.go b/operator/pkg/controllers/acm/resources.go index 9d2f4e4c8..55f0d05e0 100644 --- a/operator/pkg/controllers/acm/resources.go +++ b/operator/pkg/controllers/acm/resources.go @@ -58,6 +58,7 @@ func (r *ACMResourceController) IsResourceRemoved() bool { } func (r *ACMResourceController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log.Debugf("reconcile acm controller: %v", req) r.Resources[req.Name] = true if !r.readyToWatchACMResources() { @@ -89,6 +90,7 @@ func (r *ACMResourceController) readyToWatchACMResources() bool { } func StartController(opts config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start acm controller") if acmResourceController != nil { return acmResourceController, nil } @@ -116,5 +118,6 @@ func StartController(opts config.ControllerOption) (config.ControllerInterface, return nil, err } acmResourceController = acmController + log.Infof("inited acm controller") return acmResourceController, nil } diff --git a/operator/pkg/controllers/agent/addon_manager.go b/operator/pkg/controllers/agent/addon_manager.go index c4484f905..20396eee9 100644 --- a/operator/pkg/controllers/agent/addon_manager.go +++ b/operator/pkg/controllers/agent/addon_manager.go @@ -61,6 +61,8 @@ func ReadyToEnableAddonManager(mgh *v1alpha4.MulticlusterGlobalHub) bool { } func StartAddonManagerController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start addon manager controller") + if addonManagerController != nil { return addonManagerController, nil } diff --git a/operator/pkg/controllers/agent/default_agent_controller.go b/operator/pkg/controllers/agent/default_agent_controller.go index 9601d4ca4..3347162fb 100644 --- a/operator/pkg/controllers/agent/default_agent_controller.go +++ b/operator/pkg/controllers/agent/default_agent_controller.go @@ -128,6 +128,7 @@ func NewDefaultAgentController(c client.Client) *DefaultAgentController { } func StartDefaultAgentController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start default agent controller") if defaultAgentController != nil { return defaultAgentController, nil } @@ -166,7 +167,7 @@ func StartDefaultAgentController(initOption config.ControllerOption) (config.Con defaultAgentController = nil return nil, err } - log.Info("the default addon reconciler is started") + log.Info("the default agent controller is started") return defaultAgentController, nil } @@ -176,6 +177,8 @@ func (c *DefaultAgentController) IsResourceRemoved() bool { } func (r *DefaultAgentController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log.Debugf("reconcile default agent controller: %v", req) + mgh, err := config.GetMulticlusterGlobalHub(ctx, r.Client) if err != nil { return ctrl.Result{RequeueAfter: 5 * time.Second}, nil diff --git a/operator/pkg/controllers/agent/hosted_agent_controller.go b/operator/pkg/controllers/agent/hosted_agent_controller.go index dd801ccf4..a7fd1a8a9 100644 --- a/operator/pkg/controllers/agent/hosted_agent_controller.go +++ b/operator/pkg/controllers/agent/hosted_agent_controller.go @@ -56,6 +56,8 @@ var ( ) func StartHostedAgentController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start hosted agent controller") + if hostedAgentController != nil { return hostedAgentController, nil } @@ -72,6 +74,7 @@ func StartHostedAgentController(initOption config.ControllerOption) (config.Cont hostedAgentController = nil return nil, err } + log.Info("inited hosted agent controller") return hostedAgentController, nil } @@ -138,7 +141,7 @@ var mghPred = predicate.Funcs{ } func (r *HostedAgentController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - log.Debug("Reconcile ClusterManagementAddOn: %v", req.NamespacedName) + log.Debugf("reconcile ClusterManagementAddOn: %v", req.NamespacedName) mgh, err := config.GetMulticlusterGlobalHub(ctx, r.c) if err != nil { log.Error(err) diff --git a/operator/pkg/controllers/backup/backup_reconcile.go b/operator/pkg/controllers/backup/backup_reconcile.go index 3bfe3f8b1..0b3ba311a 100644 --- a/operator/pkg/controllers/backup/backup_reconcile.go +++ b/operator/pkg/controllers/backup/backup_reconcile.go @@ -53,6 +53,8 @@ var log = logger.DefaultZapLogger() // So for request.Namespace, we set it as request type, like "Secret","Configmap","MulticlusterGlobalHub" and so on. // In the reconcile, we identy the request kind and get it by request.Name. func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log.Debugf("reconcile backup") + // mgh is used to update backup condition mghList := &globalhubv1alpha4.MulticlusterGlobalHubList{} err := r.Client.List(ctx, mghList) diff --git a/operator/pkg/controllers/backup/backup_start.go b/operator/pkg/controllers/backup/backup_start.go index a517bf99a..1088346f1 100644 --- a/operator/pkg/controllers/backup/backup_start.go +++ b/operator/pkg/controllers/backup/backup_start.go @@ -69,6 +69,7 @@ func GetBackupController() *BackupReconciler { } func StartController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Infof("start backup controller") if backupController != nil { return backupController, nil } @@ -85,6 +86,7 @@ func StartController(initOption config.ControllerOption) (config.ControllerInter return nil, err } backupController = c + log.Infof("inited backup controller") return backupController, nil } diff --git a/operator/pkg/controllers/grafana/grafana_reconciler.go b/operator/pkg/controllers/grafana/grafana_reconciler.go index f552f2ba7..2a026eda9 100644 --- a/operator/pkg/controllers/grafana/grafana_reconciler.go +++ b/operator/pkg/controllers/grafana/grafana_reconciler.go @@ -125,6 +125,7 @@ func (r *GrafanaReconciler) IsResourceRemoved() bool { } func StartController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start grafana controller") if grafanaController != nil { return grafanaController, nil } @@ -141,7 +142,7 @@ func StartController(initOption config.ControllerOption) (config.ControllerInter grafanaController = nil return grafanaController, err } - log.Infof("inited grafana controller") + log.Infof("Inited grafana controller") return grafanaController, nil } @@ -249,6 +250,7 @@ var secretPred = predicate.Funcs{ } func (r *GrafanaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log.Debugf("reconcile grafana controller") mgh, err := config.GetMulticlusterGlobalHub(ctx, r.GetClient()) if err != nil { return ctrl.Result{}, err @@ -262,6 +264,7 @@ func (r *GrafanaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct err = config.UpdateMGHComponent(ctx, r.GetClient(), config.GetComponentStatusWithReconcileError(ctx, r.GetClient(), mgh.Namespace, config.COMPONENTS_GRAFANA_NAME, reconcileErr), + false, ) if err != nil { log.Errorf("failed to update mgh status, err:%v", err) diff --git a/operator/pkg/controllers/inventory/inventory_reconciler.go b/operator/pkg/controllers/inventory/inventory_reconciler.go index 58532cb85..f0fd3d985 100644 --- a/operator/pkg/controllers/inventory/inventory_reconciler.go +++ b/operator/pkg/controllers/inventory/inventory_reconciler.go @@ -68,6 +68,7 @@ func (r *InventoryReconciler) IsResourceRemoved() bool { } func StartController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start inventory controller") if inventoryReconciler != nil { return inventoryReconciler, nil } @@ -128,6 +129,7 @@ func NewInventoryReconciler(mgr ctrl.Manager, kubeClient kubernetes.Interface) * func (r *InventoryReconciler) Reconcile(ctx context.Context, req ctrl.Request, ) (ctrl.Result, error) { + log.Debugf("reconcile inventory controller") mgh, err := config.GetMulticlusterGlobalHub(ctx, r.GetClient()) if err != nil { return ctrl.Result{}, nil @@ -142,6 +144,7 @@ func (r *InventoryReconciler) Reconcile(ctx context.Context, err = config.UpdateMGHComponent(ctx, r.GetClient(), config.GetComponentStatusWithReconcileError(ctx, r.GetClient(), mgh.Namespace, config.COMPONENTS_INVENTORY_API_NAME, reconcileErr), + false, ) if err != nil { log.Errorf("failed to update mgh status, err:%v", err) diff --git a/operator/pkg/controllers/managedhub/managedhub_controller.go b/operator/pkg/controllers/managedhub/managedhub_controller.go index e51eb52bd..85c6c63fc 100644 --- a/operator/pkg/controllers/managedhub/managedhub_controller.go +++ b/operator/pkg/controllers/managedhub/managedhub_controller.go @@ -50,11 +50,12 @@ var ( var log = logger.DefaultZapLogger() func (r *ManagedHubController) IsResourceRemoved() bool { - log.Infof("ManagedHubController resource removed: %v", isResourceRemoved) + log.Infof("managedHubController resource removed: %v", isResourceRemoved) return isResourceRemoved } func StartController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start managedhub controller") if managedHubController != nil { return managedHubController, nil } @@ -72,6 +73,8 @@ func StartController(initOption config.ControllerOption) (config.ControllerInter } func (r *ManagedHubController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log.Debugf("reconcile managedhub controller") + mgh, err := config.GetMulticlusterGlobalHub(ctx, r.c) if err != nil { return ctrl.Result{}, nil diff --git a/operator/pkg/controllers/manager/manager_reconciler.go b/operator/pkg/controllers/manager/manager_reconciler.go index 51ee489bb..631c3a818 100644 --- a/operator/pkg/controllers/manager/manager_reconciler.go +++ b/operator/pkg/controllers/manager/manager_reconciler.go @@ -85,6 +85,8 @@ var ( ) func StartController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start manager controller") + if managerController != nil { return managerController, nil } @@ -107,7 +109,7 @@ func StartController(initOption config.ControllerOption) (config.ControllerInter } func (r *ManagerReconciler) IsResourceRemoved() bool { - log.Infof("ManagerController resource removed: %v", isResourceRemoved) + log.Infof("managerController resource removed: %v", isResourceRemoved) return isResourceRemoved } @@ -149,6 +151,7 @@ func NewManagerReconciler(mgr ctrl.Manager, kubeClient kubernetes.Interface, func (r *ManagerReconciler) Reconcile(ctx context.Context, req ctrl.Request, ) (ctrl.Result, error) { + log.Debug("reconcile manager controller") mgh, err := config.GetMulticlusterGlobalHub(ctx, r.GetClient()) if err != nil { return ctrl.Result{}, nil @@ -170,6 +173,7 @@ func (r *ManagerReconciler) Reconcile(ctx context.Context, err = config.UpdateMGHComponent(ctx, r.GetClient(), config.GetComponentStatusWithReconcileError(ctx, r.GetClient(), mgh.Namespace, config.COMPONENTS_MANAGER_NAME, reconcileErr), + false, ) if err != nil { log.Errorf("failed to update mgh status, err:%v", err) diff --git a/operator/pkg/controllers/storage/storage_reconciler.go b/operator/pkg/controllers/storage/storage_reconciler.go index 4996a59d2..7ade3404e 100644 --- a/operator/pkg/controllers/storage/storage_reconciler.go +++ b/operator/pkg/controllers/storage/storage_reconciler.go @@ -75,13 +75,18 @@ var WatchedConfigMap = sets.NewString( constants.PostgresCAConfigMap, ) -var storageReconciler *StorageReconciler +var ( + storageReconciler *StorageReconciler + updateConnection bool +) func (r *StorageReconciler) IsResourceRemoved() bool { return true } func StartController(initOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start storage controller") + if storageReconciler != nil { return storageReconciler, nil } @@ -158,6 +163,7 @@ var secretPred = predicate.Funcs{ } func (r *StorageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log.Debug("reconcile storage controller") mgh, err := config.GetMulticlusterGlobalHub(ctx, r.GetClient()) if err != nil { return ctrl.Result{}, err @@ -183,6 +189,7 @@ func (r *StorageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct defer func() { err = config.UpdateMGHComponent(ctx, r.GetClient(), getDatabaseComponentStatus(ctx, r.GetClient(), mgh.Namespace, reconcileErr), + updateConnection, ) if err != nil { log.Errorf("failed to update mgh status, err:%v", err) @@ -193,7 +200,7 @@ func (r *StorageReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct reconcileErr = fmt.Errorf("storage not ready, Error: %v", err) return ctrl.Result{}, reconcileErr } - _ = config.SetStorageConnection(storageConn) + updateConnection = config.SetStorageConnection(storageConn) needRequeue, err := r.reconcileDatabase(ctx, mgh) if err != nil { @@ -288,6 +295,7 @@ func (r *StorageReconciler) reconcileDatabase(ctx context.Context, mgh *v1alpha4 log.Infof("wait database ready") return true, nil } + defer func() { if err := conn.Close(ctx); err != nil { log.Error(err, "failed to close connection to database") diff --git a/operator/pkg/controllers/transporter/protocol/strimzi_kafka_controller.go b/operator/pkg/controllers/transporter/protocol/strimzi_kafka_controller.go index 1907dabf7..1030a0059 100644 --- a/operator/pkg/controllers/transporter/protocol/strimzi_kafka_controller.go +++ b/operator/pkg/controllers/transporter/protocol/strimzi_kafka_controller.go @@ -35,6 +35,7 @@ var manifests embed.FS var ( startedKafkaController = false isResourceRemoved = false + updateConn bool ) var log = logger.DefaultZapLogger() @@ -91,6 +92,7 @@ func (r *KafkaController) Reconcile(ctx context.Context, request ctrl.Request) ( defer func() { err = config.UpdateMGHComponent(ctx, r.c, r.getKafkaComponentStatus(reconcileErr, r.kafkaStatus), + updateConn, ) if err != nil { log.Errorf("failed to update mgh status, err:%v", err) @@ -128,7 +130,7 @@ func (r *KafkaController) Reconcile(ctx context.Context, request ctrl.Request) ( if needRequeue { return ctrl.Result{RequeueAfter: 5 * time.Second}, nil } - config.SetTransporterConn(conn) + updateConn = config.SetTransporterConn(conn) return ctrl.Result{}, nil } @@ -146,6 +148,7 @@ var kafkaPred = predicate.Funcs{ } func StartKafkaController(ctx context.Context, mgr ctrl.Manager, transporter transport.Transporter) error { + log.Info("start kafka controller") if startedKafkaController { return nil } diff --git a/operator/pkg/controllers/transporter/transport_reconciler.go b/operator/pkg/controllers/transporter/transport_reconciler.go index 6527550a5..f4019573a 100644 --- a/operator/pkg/controllers/transporter/transport_reconciler.go +++ b/operator/pkg/controllers/transporter/transport_reconciler.go @@ -37,6 +37,7 @@ var ( log = logger.DefaultZapLogger() isResourceRemoved = true transportReconciler *TransportReconciler + updateConn bool ) type TransportReconciler struct { @@ -50,6 +51,7 @@ func (c *TransportReconciler) IsResourceRemoved() bool { } func StartController(controllerOption config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start transport controller") if transportReconciler != nil { return transportReconciler, nil } @@ -114,6 +116,7 @@ func NewTransportReconciler(mgr ctrl.Manager) *TransportReconciler { // Resources reconcile the transport resources and also update transporter on the configuration func (r *TransportReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log.Debugf("reconcile transport controller") mgh, err := config.GetMulticlusterGlobalHub(ctx, r.GetClient()) if err != nil { return ctrl.Result{}, err @@ -143,6 +146,7 @@ func (r *TransportReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( err = config.UpdateMGHComponent(ctx, r.GetClient(), getTransportComponentStatus(reconcileErr), + updateConn, ) if err != nil { log.Errorf("failed to update mgh status, err:%v", err) @@ -187,8 +191,7 @@ func (r *TransportReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( if err != nil { return ctrl.Result{}, err } - config.SetTransporterConn(conn) - + updateConn = config.SetTransporterConn(conn) } return ctrl.Result{}, nil } diff --git a/operator/pkg/controllers/webhook/webhook_controller.go b/operator/pkg/controllers/webhook/webhook_controller.go index 697c389d0..bad59a531 100644 --- a/operator/pkg/controllers/webhook/webhook_controller.go +++ b/operator/pkg/controllers/webhook/webhook_controller.go @@ -59,6 +59,7 @@ func NewWebhookReconciler(mgr ctrl.Manager, } func StartController(opts config.ControllerOption) (config.ControllerInterface, error) { + log.Info("start webhook controller") if webhookReconciler != nil { return webhookReconciler, nil } @@ -74,11 +75,12 @@ func StartController(opts config.ControllerOption) (config.ControllerInterface, } func (r *WebhookReconciler) IsResourceRemoved() bool { - log.Infof("WebhookController resource removed: %v", isResourceRemoved) + log.Infof("webhookController resource removed: %v", isResourceRemoved) return isResourceRemoved } func (r *WebhookReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + log.Debugf("reconcile webhook controller") mgh, err := config.GetMulticlusterGlobalHub(ctx, r.c) if err != nil { return ctrl.Result{}, err