diff --git a/controllers/backplaneconfig_controller.go b/controllers/backplaneconfig_controller.go index 160f75052..0fb862951 100644 --- a/controllers/backplaneconfig_controller.go +++ b/controllers/backplaneconfig_controller.go @@ -26,7 +26,6 @@ import ( "strings" "time" - "github.com/go-co-op/gocron" "github.com/go-logr/logr" backplanev1 "github.com/stolostron/backplane-operator/api/v1" "github.com/stolostron/backplane-operator/pkg/foundation" @@ -58,7 +57,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/log" + logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -91,9 +90,7 @@ const ( ) var ( - scheduler *gocron.Scheduler - cronResyncTag = "multiclusterengine-operator-resync" - reconciliationInterval = 10 // minutes + log = logf.Log.WithName("reconcile") ) //+kubebuilder:rbac:groups=multicluster.openshift.io,resources=multiclusterengines,verbs=get;list;watch;create;update;patch;delete @@ -158,15 +155,9 @@ var ( // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. func (r *MultiClusterEngineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (retRes ctrl.Result, retErr error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log r.Log.Info("Reconciling MultiClusterEngine") - // Initalize sceduler instance for operator resync cronjob. - if scheduler == nil { - r.Log.Info("Setting up scheduler for operator resync") - r.InitScheduler() - } - // Fetch the BackplaneConfig instance backplaneConfig, err := r.getBackplaneConfig(ctx, req) if err != nil && !apierrors.IsNotFound(err) { @@ -376,10 +367,6 @@ func (r *MultiClusterEngineReconciler) Reconcile(ctx context.Context, req ctrl.R // Do not reconcile objects if this instance of mce is labeled "paused" if utils.IsPaused(backplaneConfig) { r.Log.Info("MultiClusterEngine reconciliation is paused. Nothing more to do.") - if ok := scheduler.IsRunning(); ok { - r.Log.Info("Pausing MultiClusterEngine operator controller resync job.") - go r.StopScheduleOperatorControllerResync() - } cond := status.NewCondition( backplanev1.MultiClusterEngineProgressing, @@ -389,8 +376,6 @@ func (r *MultiClusterEngineReconciler) Reconcile(ctx context.Context, req ctrl.R ) r.StatusManager.AddCondition(cond) return ctrl.Result{}, nil - } else if ok := scheduler.IsRunning(); !ok { - defer r.ScheduleOperatorControllerResync(ctx, req) } var crdsDir string @@ -473,7 +458,8 @@ func (r *MultiClusterEngineReconciler) Reconcile(ctx context.Context, req ctrl.R r.StatusManager.AddCondition(status.NewCondition(backplanev1.MultiClusterEngineProgressing, metav1.ConditionTrue, status.DeploySuccessReason, "All components deployed")) - return ctrl.Result{}, nil + r.Log.Info("Reconcile completed. Requeuing after " + utils.ShortRefreshInterval.String()) + return ctrl.Result{RequeueAfter: utils.ShortRefreshInterval}, nil } // This function set the operator condition created by OLM to either allow or disallow upgrade based on whether X.Y desired version matches current version @@ -585,7 +571,6 @@ func (r *MultiClusterEngineReconciler) SetupWithManager(mgr ctrl.Manager) error // trusted CA bundle for use with the OCP cluster wide proxy func (r *MultiClusterEngineReconciler) createTrustBundleConfigmap(ctx context.Context, mce *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") // Get Trusted Bundle configmap name trustBundleName := defaultTrustBundleName @@ -640,7 +625,6 @@ func (r *MultiClusterEngineReconciler) createTrustBundleConfigmap(ctx context.Co func (r *MultiClusterEngineReconciler) createMetricsService(ctx context.Context, mce *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") const Port = 8080 @@ -705,7 +689,6 @@ func (r *MultiClusterEngineReconciler) createMetricsService(ctx context.Context, func (r *MultiClusterEngineReconciler) createMetricsServiceMonitor(ctx context.Context, mce *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") smName := utils.MCEOperatorMetricsServiceMonitorName smNamespace := mce.Spec.TargetNamespace @@ -776,7 +759,6 @@ func (r *MultiClusterEngineReconciler) createMetricsServiceMonitor(ctx context.C // DeployAlwaysSubcomponents ensures all subcomponents exist func (r *MultiClusterEngineReconciler) DeployAlwaysSubcomponents(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") chartsDir := renderer.AlwaysChartsDir // Renders all templates from charts @@ -813,7 +795,6 @@ func (r *MultiClusterEngineReconciler) DeployAlwaysSubcomponents(ctx context.Con func (r *MultiClusterEngineReconciler) ensureToggleableComponents(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") errs := map[string]error{} requeue := false @@ -1111,7 +1092,6 @@ func (r *MultiClusterEngineReconciler) applyTemplate(ctx context.Context, // means the resource is in the process of deleting. func (r *MultiClusterEngineReconciler) deleteTemplate(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine, template *unstructured.Unstructured) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") err := r.Client.Get(ctx, types.NamespacedName{Name: template.GetName(), Namespace: template.GetNamespace()}, template) if err != nil && (apierrors.IsNotFound(err) || apimeta.IsNoMatchError(err)) { @@ -1136,7 +1116,6 @@ func (r *MultiClusterEngineReconciler) deleteTemplate(ctx context.Context, func (r *MultiClusterEngineReconciler) ensureCustomResources(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") if foundation.CanInstallAddons(ctx, r.Client) { addonTemplates, err := foundation.GetAddons() @@ -1167,7 +1146,6 @@ func (r *MultiClusterEngineReconciler) ensureCustomResources(ctx context.Context func (r *MultiClusterEngineReconciler) ensureOpenShiftNamespaceLabel(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") existingNs := &corev1.Namespace{} err := r.Client.Get(ctx, types.NamespacedName{Name: backplaneConfig.Spec.TargetNamespace}, existingNs) @@ -1199,7 +1177,6 @@ func (r *MultiClusterEngineReconciler) ensureOpenShiftNamespaceLabel(ctx context func (r *MultiClusterEngineReconciler) finalizeBackplaneConfig(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) error { - log := log.Log.WithName("reconcile") ocpConsole, err := r.CheckConsole(ctx) if err != nil { @@ -1366,7 +1343,6 @@ func (r *MultiClusterEngineReconciler) finalizeBackplaneConfig(ctx context.Conte func (r *MultiClusterEngineReconciler) getBackplaneConfig(ctx context.Context, req ctrl.Request) ( *backplanev1.MultiClusterEngine, error) { - r.Log = log.Log.WithName("reconcile") backplaneConfig := &backplanev1.MultiClusterEngine{} err := r.Client.Get(ctx, req.NamespacedName, backplaneConfig) if err != nil { @@ -1386,7 +1362,6 @@ func (r *MultiClusterEngineReconciler) getBackplaneConfig(ctx context.Context, r // ensureUnstructuredResource ensures that the unstructured resource is applied in the cluster properly func (r *MultiClusterEngineReconciler) ensureUnstructuredResource(ctx context.Context, bpc *backplanev1.MultiClusterEngine, u *unstructured.Unstructured) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") found := &unstructured.Unstructured{} found.SetGroupVersionKind(u.GroupVersionKind()) @@ -1422,7 +1397,6 @@ func (r *MultiClusterEngineReconciler) ensureUnstructuredResource(ctx context.Co } func (r *MultiClusterEngineReconciler) setDefaults(ctx context.Context, m *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") updateNecessary := false if !utils.AvailabilityConfigIsValid(m.Spec.AvailabilityConfig) { @@ -1524,7 +1498,7 @@ func (r *MultiClusterEngineReconciler) setDefaults(ctx context.Context, m *backp func (r *MultiClusterEngineReconciler) validateNamespace(ctx context.Context, m *backplanev1.MultiClusterEngine) ( ctrl.Result, error) { - log := log.Log.WithName("reconcile") + newNs := &corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: m.Spec.TargetNamespace, @@ -1584,7 +1558,6 @@ func (r *MultiClusterEngineReconciler) validateImagePullSecret(ctx context.Conte } func (r *MultiClusterEngineReconciler) getClusterVersion(ctx context.Context) (string, error) { - r.Log = log.Log.WithName("reconcile") // If Unit test if val, ok := os.LookupEnv("UNIT_TEST"); ok && val == "true" { if _, exists := os.LookupEnv("ACM_HUB_OCP_VERSION"); exists { @@ -1610,7 +1583,6 @@ func (r *MultiClusterEngineReconciler) getClusterVersion(ctx context.Context) (s //+kubebuilder:rbac:groups="config.openshift.io",resources="ingresses",verbs=get;list;watch func (r *MultiClusterEngineReconciler) getClusterIngressDomain(ctx context.Context, mce *backplanev1.MultiClusterEngine) (string, error) { - r.Log = log.Log.WithName("reconcile") // If Unit test if val, ok := os.LookupEnv("UNIT_TEST"); ok && val == "true" { return "apps.installer-test-cluster.dev00.red-chesterfield.com", nil @@ -1630,35 +1602,6 @@ func (r *MultiClusterEngineReconciler) getClusterIngressDomain(ctx context.Conte return clusterIngress.Spec.Domain, nil } -func (r *MultiClusterEngineReconciler) InitScheduler() { - scheduler = gocron.NewScheduler(time.UTC) -} - -func (r *MultiClusterEngineReconciler) ScheduleOperatorControllerResync(ctx context.Context, req ctrl.Request) { - r.Log = log.Log.WithName("reconcile") - - if ok := scheduler.IsRunning(); !ok { - _, err := scheduler.Tag(cronResyncTag).Every(reconciliationInterval).Minutes().Do(r.Reconcile, ctx, req) - - if err != nil { - r.Log.Error(err, "failed to schedule scheduler job for operator controller resync") - } else { - r.Log.Info(fmt.Sprintf("Starting scheduler job for operator controller. Reconciling every %v minutes", - reconciliationInterval)) - scheduler.StartAsync() - } - } -} - -// StopScheduleOperatorControllerResync ... -func (r *MultiClusterEngineReconciler) StopScheduleOperatorControllerResync() { - scheduler.Stop() - - if ok := scheduler.IsRunning(); !ok { - r.InitScheduler() - } -} - func (r *MultiClusterEngineReconciler) CheckDeprecatedFieldUsage(m *backplanev1.MultiClusterEngine) { a := m.GetAnnotations() df := []struct { diff --git a/controllers/backplaneconfig_controller_test.go b/controllers/backplaneconfig_controller_test.go index a96204f92..59e05511b 100644 --- a/controllers/backplaneconfig_controller_test.go +++ b/controllers/backplaneconfig_controller_test.go @@ -496,8 +496,7 @@ var _ = Describe("BackplaneConfig controller", func() { backplaneConfig.Annotations = annotations _ = k8sClient.Update(ctx, backplaneConfig) - reconciler.StopScheduleOperatorControllerResync() - return utils.IsPaused(backplaneConfig) && !scheduler.IsRunning() + return utils.IsPaused(backplaneConfig) }, timeout, interval).Should(BeTrue()) }) }) diff --git a/controllers/hosted.go b/controllers/hosted.go index 1f5a7421f..0b0f12753 100644 --- a/controllers/hosted.go +++ b/controllers/hosted.go @@ -26,14 +26,13 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/log" ) var ErrBadFormat = errors.New("bad format") func (r *MultiClusterEngineReconciler) HostedReconcile(ctx context.Context, mce *backplanev1.MultiClusterEngine) ( retRes ctrl.Result, retErr error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log defer func() { mce.Status = r.StatusManager.ReportStatus(*mce) @@ -293,8 +292,6 @@ func parseKubeCreds(secret *corev1.Secret) ([]byte, error) { func (r *MultiClusterEngineReconciler) ensureHostedImport(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine, hostedClient client.Client) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") - r.StatusManager.AddComponent(toggle.EnabledStatus(types.NamespacedName{Name: "managedcluster-import-controller-v2", Namespace: backplaneConfig.Spec.TargetNamespace})) @@ -343,8 +340,6 @@ func (r *MultiClusterEngineReconciler) ensureHostedImport(ctx context.Context, func (r *MultiClusterEngineReconciler) ensureNoHostedImport(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine, hostedClient client.Client) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") - r.StatusManager.RemoveComponent(toggle.EnabledStatus( types.NamespacedName{Name: "managedcluster-import-controller-v2", Namespace: backplaneConfig.Spec.TargetNamespace})) @@ -394,7 +389,6 @@ func (r *MultiClusterEngineReconciler) ensureNoHostedImport(ctx context.Context, func (r *MultiClusterEngineReconciler) ensureHostedClusterManager(ctx context.Context, mce *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") cmName := fmt.Sprintf("%s-cluster-manager", mce.Name) r.StatusManager.AddComponent(status.ClusterManagerStatus{ @@ -520,7 +514,7 @@ func (r *MultiClusterEngineReconciler) ensureNoHostedClusterManager(ctx context. // setHostedDefaults configures the MCE with default values and updates func (r *MultiClusterEngineReconciler) setHostedDefaults(ctx context.Context, m *backplanev1.MultiClusterEngine) ( ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log updateNecessary := false if !utils.AvailabilityConfigIsValid(m.Spec.AvailabilityConfig) { @@ -606,7 +600,7 @@ A false response without error means the resource is in the process of deleting. func (r *MultiClusterEngineReconciler) hostedDeleteTemplate(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine, template *unstructured.Unstructured, hostedClient client.Client) ( ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log err := hostedClient.Get(ctx, types.NamespacedName{Name: template.GetName(), Namespace: template.GetNamespace()}, template) diff --git a/controllers/toggle_components.go b/controllers/toggle_components.go index 81b4907ba..dcea73918 100644 --- a/controllers/toggle_components.go +++ b/controllers/toggle_components.go @@ -27,7 +27,6 @@ import ( "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/log" operatorv1 "github.com/openshift/api/operator/v1" @@ -42,7 +41,7 @@ var clusterManagementAddOnGVK = schema.GroupVersionKind{ func (r *MultiClusterEngineReconciler) ensureConsoleMCE(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "console-mce-console", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) @@ -87,7 +86,7 @@ func (r *MultiClusterEngineReconciler) ensureConsoleMCE(ctx context.Context, func (r *MultiClusterEngineReconciler) ensureNoConsoleMCE(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine, ocpConsole bool) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "console-mce-console", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.EnabledStatus(namespacedName)) @@ -131,7 +130,7 @@ func (r *MultiClusterEngineReconciler) ensureNoConsoleMCE(ctx context.Context, func (r *MultiClusterEngineReconciler) ensureManagedServiceAccount(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log r.StatusManager.RemoveComponent(toggle.DisabledStatus(types.NamespacedName{Name: "managedservice", Namespace: backplaneConfig.Spec.TargetNamespace}, []*unstructured.Unstructured{})) // from 2.9, we change the managed-serviceaccount to a template type addon, so the agent will be managed by the @@ -193,8 +192,8 @@ func (r *MultiClusterEngineReconciler) ensureManagedServiceAccount(ctx context.C return ctrl.Result{}, nil } -func (r *MultiClusterEngineReconciler) ensureNoManagedServiceAccount(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") +func (r *MultiClusterEngineReconciler) ensureNoManagedServiceAccount(ctx context.Context, + backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { // Renders all templates from charts chartPath := toggle.ManagedServiceAccountChartDir @@ -244,7 +243,7 @@ func (r *MultiClusterEngineReconciler) ensureNoManagedServiceAccount(ctx context // addPluginToConsoleResource ... func (r *MultiClusterEngineReconciler) addPluginToConsoleResource(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log console := &operatorv1.Console{} // If trying to check this resource from the CLI run - `oc get consoles.operator.openshift.io cluster`. @@ -277,7 +276,7 @@ func (r *MultiClusterEngineReconciler) addPluginToConsoleResource(ctx context.Co // removePluginFromConsoleResource ... func (r *MultiClusterEngineReconciler) removePluginFromConsoleResource(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log if val, ok := os.LookupEnv("UNIT_TEST"); ok && val == "true" { return ctrl.Result{}, nil @@ -313,7 +312,7 @@ func (r *MultiClusterEngineReconciler) removePluginFromConsoleResource(ctx conte } func (r *MultiClusterEngineReconciler) ensureDiscovery(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "discovery-operator", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) @@ -342,7 +341,6 @@ func (r *MultiClusterEngineReconciler) ensureDiscovery(ctx context.Context, back } func (r *MultiClusterEngineReconciler) ensureNoDiscovery(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") namespacedName := types.NamespacedName{Name: "discovery-operator", Namespace: backplaneConfig.Spec.TargetNamespace} // Renders all templates from charts @@ -371,7 +369,7 @@ func (r *MultiClusterEngineReconciler) ensureNoDiscovery(ctx context.Context, ba } func (r *MultiClusterEngineReconciler) ensureHive(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "hive-operator", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) @@ -410,7 +408,7 @@ func (r *MultiClusterEngineReconciler) ensureHive(ctx context.Context, backplane } func (r *MultiClusterEngineReconciler) ensureNoHive(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "hive-operator", Namespace: backplaneConfig.Spec.TargetNamespace} // Renders all templates from charts @@ -451,7 +449,7 @@ func (r *MultiClusterEngineReconciler) ensureNoHive(ctx context.Context, backpla } func (r *MultiClusterEngineReconciler) ensureAssistedService(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log targetNamespace := backplaneConfig.Spec.TargetNamespace if backplaneConfig.Spec.Overrides != nil && backplaneConfig.Spec.Overrides.InfrastructureCustomNamespace != "" { @@ -486,7 +484,7 @@ func (r *MultiClusterEngineReconciler) ensureAssistedService(ctx context.Context func (r *MultiClusterEngineReconciler) ensureNoAssistedService(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log targetNamespace := backplaneConfig.Spec.TargetNamespace if backplaneConfig.Spec.Overrides != nil && backplaneConfig.Spec.Overrides.InfrastructureCustomNamespace != "" { @@ -521,7 +519,7 @@ func (r *MultiClusterEngineReconciler) ensureNoAssistedService(ctx context.Conte func (r *MultiClusterEngineReconciler) ensureServerFoundation(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "ocm-controller", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) @@ -557,7 +555,6 @@ func (r *MultiClusterEngineReconciler) ensureServerFoundation(ctx context.Contex func (r *MultiClusterEngineReconciler) ensureNoServerFoundation(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") // Renders all templates from charts templates, errs := renderer.RenderChart(toggle.ServerFoundationChartDir, backplaneConfig, @@ -592,7 +589,7 @@ func (r *MultiClusterEngineReconciler) ensureNoServerFoundation(ctx context.Cont } func (r *MultiClusterEngineReconciler) ensureImageBasedInstallOperator(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log targetNamespace := backplaneConfig.Spec.TargetNamespace @@ -624,7 +621,7 @@ func (r *MultiClusterEngineReconciler) ensureImageBasedInstallOperator(ctx conte func (r *MultiClusterEngineReconciler) ensureNoImageBasedInstallOperator(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log targetNamespace := backplaneConfig.Spec.TargetNamespace namespacedName := types.NamespacedName{Name: "image-based-install-operator", Namespace: targetNamespace} @@ -656,7 +653,7 @@ func (r *MultiClusterEngineReconciler) ensureNoImageBasedInstallOperator(ctx con func (r *MultiClusterEngineReconciler) ensureClusterLifecycle(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "cluster-curator-controller", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) @@ -698,7 +695,6 @@ func (r *MultiClusterEngineReconciler) ensureClusterLifecycle(ctx context.Contex func (r *MultiClusterEngineReconciler) ensureNoClusterLifecycle(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") // Renders all templates from charts templates, errs := renderer.RenderChart(toggle.ClusterLifecycleChartDir, backplaneConfig, @@ -737,7 +733,7 @@ func (r *MultiClusterEngineReconciler) ensureNoClusterLifecycle(ctx context.Cont func (r *MultiClusterEngineReconciler) ensureClusterManager(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "cluster-manager", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) @@ -780,7 +776,6 @@ func (r *MultiClusterEngineReconciler) ensureClusterManager(ctx context.Context, } func (r *MultiClusterEngineReconciler) ensureNoClusterManager(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") namespacedName := types.NamespacedName{Name: "cluster-manager", Namespace: backplaneConfig.Spec.TargetNamespace} // Renders all templates from charts @@ -841,7 +836,7 @@ func (r *MultiClusterEngineReconciler) ensureNoClusterManager(ctx context.Contex } func (r *MultiClusterEngineReconciler) ensureHyperShift(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "hypershift-addon-manager", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) @@ -884,7 +879,6 @@ func (r *MultiClusterEngineReconciler) ensureHyperShift(ctx context.Context, bac func (r *MultiClusterEngineReconciler) ensureNoHyperShift(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") namespacedName := types.NamespacedName{Name: "hypershift-addon-manager", Namespace: backplaneConfig.Spec.TargetNamespace} @@ -995,7 +989,7 @@ func (r *MultiClusterEngineReconciler) reconcileHypershiftLocalHosting(ctx conte Message: "Waiting for namespace 'local-cluster'", }, }) - log.Log.WithName("reconcile").Info("Can't apply hypershift-addon, waiting for local-cluster namespace") + log.Info("Can't apply hypershift-addon, waiting for local-cluster namespace") return ctrl.Result{RequeueAfter: requeuePeriod}, nil } r.StatusManager.AddComponent(status.ManagedClusterAddOnStatus{ @@ -1014,7 +1008,7 @@ func (r *MultiClusterEngineReconciler) applyHypershiftLocalHosting(ctx context.C if err != nil { if apimeta.IsNoMatchError(errors.Unwrap(err)) || apierrors.IsNotFound(errors.Unwrap(err)) { // addon CRD does not yet exist. Replace status. - log.Log.WithName("reconcile").Info("Couldn't apply template for hypershiftlocalhosting due to missing CRD", "error is", err.Error()) + log.Info("Couldn't apply template for hypershiftlocalhosting due to missing CRD", "error is", err.Error()) r.StatusManager.RemoveComponent(status.ManagedClusterAddOnStatus{ NamespacedName: types.NamespacedName{Name: addon.GetName(), Namespace: addon.GetNamespace()}, @@ -1036,7 +1030,8 @@ func (r *MultiClusterEngineReconciler) applyHypershiftLocalHosting(ctx context.C } if apierrors.IsInternalError(errors.Unwrap(err)) { // likely failed to call webhook - log.Log.WithName("reconcile").Info("Couldn't apply template for hypershiftlocalhosting likely due to webhook not ready", "error is", err.Error()) + log.Info("Couldn't apply template for hypershiftlocalhosting likely due to webhook not ready", "error is", + err.Error()) r.StatusManager.RemoveComponent(status.ManagedClusterAddOnStatus{ NamespacedName: types.NamespacedName{Name: addon.GetName(), Namespace: addon.GetNamespace()}, @@ -1074,7 +1069,7 @@ func (r *MultiClusterEngineReconciler) removeHypershiftLocalHosting(ctx context. } func (r *MultiClusterEngineReconciler) ensureClusterProxyAddon(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - r.Log = log.Log.WithName("reconcile") + r.Log = log namespacedName := types.NamespacedName{Name: "cluster-proxy-addon-manager", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.AddComponent(toggle.EnabledStatus(namespacedName)) @@ -1116,7 +1111,6 @@ func (r *MultiClusterEngineReconciler) ensureClusterProxyAddon(ctx context.Conte } func (r *MultiClusterEngineReconciler) ensureNoClusterProxyAddon(ctx context.Context, backplaneConfig *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") namespacedName := types.NamespacedName{Name: "cluster-proxy-addon-manager", Namespace: backplaneConfig.Spec.TargetNamespace} r.StatusManager.RemoveComponent(toggle.EnabledStatus(namespacedName)) r.StatusManager.AddComponent(toggle.DisabledStatus(namespacedName, []*unstructured.Unstructured{})) @@ -1185,7 +1179,6 @@ func (r *MultiClusterEngineReconciler) CheckConsole(ctx context.Context) (bool, func (r *MultiClusterEngineReconciler) ensureLocalCluster(ctx context.Context, mce *backplanev1.MultiClusterEngine) ( ctrl.Result, error) { - log := log.Log.WithName("reconcile") if utils.IsUnitTest() { r.Log.Info("skipping local cluster creation in unit tests") @@ -1315,7 +1308,6 @@ func (r *MultiClusterEngineReconciler) ensureLocalCluster(ctx context.Context, m } func (r *MultiClusterEngineReconciler) ensureNoLocalCluster(ctx context.Context, mce *backplanev1.MultiClusterEngine) (ctrl.Result, error) { - log := log.Log.WithName("reconcile") if utils.IsUnitTest() { r.Log.Info("skipping local cluster removal in unit tests") diff --git a/controllers/uninstall.go b/controllers/uninstall.go index 599115048..047a6ddc9 100644 --- a/controllers/uninstall.go +++ b/controllers/uninstall.go @@ -10,7 +10,6 @@ import ( backplanev1 "github.com/stolostron/backplane-operator/api/v1" "github.com/stolostron/backplane-operator/pkg/toggle" apimeta "k8s.io/apimachinery/pkg/api/meta" - "sigs.k8s.io/controller-runtime/pkg/log" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -132,7 +131,6 @@ instead. */ func (r *MultiClusterEngineReconciler) removeLegacyPrometheusConfigurations(ctx context.Context, targetNamespace string, kind string) error { - log := log.Log.WithName("reconcile") obj := &unstructured.Unstructured{} obj.SetGroupVersionKind(schema.GroupVersionKind{ diff --git a/pkg/status/status.go b/pkg/status/status.go index 7e782eb02..a5b42d1df 100644 --- a/pkg/status/status.go +++ b/pkg/status/status.go @@ -7,6 +7,12 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" +) + +var ( + prevAvailability = make(map[string]bool) + log = logf.Log.WithName("status") ) type StatusTracker struct { @@ -133,12 +139,35 @@ func allComponentsReady(components []bpv1.ComponentCondition) bool { if len(components) == 0 { return false } + + // Track availability status. + allAvailable := true + for _, val := range components { if !val.Available { - return false + // Check if the component's availability status has changed since the last reconciliation. + if prevStatus, exists := prevAvailability[val.Name]; !exists || prevStatus { + // Log the information about the newly unavailable component + log.Info("The component is not yet available.", "Kind", val.Kind, "Name", val.Name, "Reason", val.Reason) + } + + // Update the previous availability status for this component + prevAvailability[val.Name] = false + allAvailable = false + } else { + // Check if the component's availability status has changed since the last reconciliation + if prevStatus, exists := prevAvailability[val.Name]; !exists || !prevStatus { + // Log the information about the newly available component + log.Info("The component is now available.", "Kind", val.Kind, "Name", val.Name) + } + + // Update the previous availability status for this component + prevAvailability[val.Name] = true } } - return true + + // Return the overall availability status + return allAvailable } // StatusReporter is a resource that can report back a status diff --git a/pkg/utils/defaults.go b/pkg/utils/defaults.go new file mode 100644 index 000000000..376d4c081 --- /dev/null +++ b/pkg/utils/defaults.go @@ -0,0 +1,27 @@ +// Copyright Contributors to the Open Cluster Management project + +package utils + +import ( + "time" +) + +const ( + // ShortRefreshInterval is ideal for frequently changing or moderately critical state requiring timely updates. + ShortRefreshInterval = 5 * time.Minute + + // ErrorRefreshInterval is used for handling critical errors that require immediate attention. + ErrorRefreshInterval = 30 * time.Second + + /* + WarningRefreshInterval is suitable for addressing warnings or non-critical issues that should still be addressed + relatively promptly. + */ + WarningRefreshInterval = 1 * time.Minute + + /* + DefaultRefreshInterval serves as a fallback for any other conditions not explicitly covered by the above + intervals. + */ + DefaultRefreshInterval = 20 * time.Minute +)