From ef231d1506c6d1a1dcddc0cfed4d0d2ef0456cc3 Mon Sep 17 00:00:00 2001 From: Wen Zhou Date: Tue, 25 Jun 2024 12:56:18 +0200 Subject: [PATCH] fix: do not redeploy segment-io's if it has been deployed previously (#1079) - dashboard is using segment-io's configmap to flip monitoring settings - upon upgrade, Operator redploy the same configmap to set data to "true" Signed-off-by: Wen Zhou --- .../dscinitialization_controller.go | 6 +-- controllers/dscinitialization/monitoring.go | 41 ++++++++++++++----- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/controllers/dscinitialization/dscinitialization_controller.go b/controllers/dscinitialization/dscinitialization_controller.go index 30ac1248378..f7670e8beec 100644 --- a/controllers/dscinitialization/dscinitialization_controller.go +++ b/controllers/dscinitialization/dscinitialization_controller.go @@ -245,8 +245,8 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re return reconcile.Result{}, err } if instance.Spec.Monitoring.ManagementState == operatorv1.Managed { - r.Log.Info("Monitoring enabled, won't apply changes", "cluster", "Self-Managed RHOAI Mode") - err = r.configureCommonMonitoring(instance) + r.Log.Info("Monitoring enabled, won't apply changes", "cluster", "Self-Managed RHODS Mode") + err = r.configureCommonMonitoring(ctx, instance) if err != nil { return reconcile.Result{}, err } @@ -265,7 +265,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re if err != nil { return reconcile.Result{}, err } - err = r.configureCommonMonitoring(instance) + err = r.configureCommonMonitoring(ctx, instance) if err != nil { return reconcile.Result{}, err } diff --git a/controllers/dscinitialization/monitoring.go b/controllers/dscinitialization/monitoring.go index d12efb9d1df..6f06a74bdb9 100644 --- a/controllers/dscinitialization/monitoring.go +++ b/controllers/dscinitialization/monitoring.go @@ -434,19 +434,38 @@ func createMonitoringProxySecret(ctx context.Context, cli client.Client, name st return nil } -func (r *DSCInitializationReconciler) configureCommonMonitoring(dsciInit *dsciv1.DSCInitialization) error { - // configure segment.io - segmentPath := filepath.Join(deploy.DefaultManifestPath, "monitoring", "segment") - if err := deploy.DeployManifestsFromPath( - r.Client, - dsciInit, - segmentPath, - dsciInit.Spec.ApplicationsNamespace, - "segment-io", - dsciInit.Spec.Monitoring.ManagementState == operatorv1.Managed); err != nil { - r.Log.Error(err, "error to deploy manifests under "+segmentPath) +func (r *DSCInitializationReconciler) configureSegmentIO(ctx context.Context, dsciInit *dsciv1.DSCInitialization) error { + // create segment.io only when configmap does not exist in the cluster + segmentioConfigMap := &corev1.ConfigMap{} + if err := r.Client.Get(ctx, client.ObjectKey{ + Namespace: dsciInit.Spec.ApplicationsNamespace, + Name: "odh-segment-key-config", + }, segmentioConfigMap); err != nil { + if !k8serr.IsNotFound(err) { + r.Log.Error(err, "error to get configmap 'odh-segment-key-config'") + return err + } else { + segmentPath := filepath.Join(deploy.DefaultManifestPath, "monitoring", "segment") + if err := deploy.DeployManifestsFromPath( + r.Client, + dsciInit, + segmentPath, + dsciInit.Spec.ApplicationsNamespace, + "segment-io", + dsciInit.Spec.Monitoring.ManagementState == operatorv1.Managed); err != nil { + r.Log.Error(err, "error to deploy manifests under "+segmentPath) + return err + } + } + } + return nil +} + +func (r *DSCInitializationReconciler) configureCommonMonitoring(ctx context.Context, dsciInit *dsciv1.DSCInitialization) error { + if err := r.configureSegmentIO(ctx, dsciInit); err != nil { return err } + // configure monitoring base monitoringBasePath := filepath.Join(deploy.DefaultManifestPath, "monitoring", "base") err := common.ReplaceStringsInFile(filepath.Join(monitoringBasePath, "rhods-servicemonitor.yaml"),