Skip to content

Commit

Permalink
fix: do not redeploy segment-io's if it has been deployed previously (o…
Browse files Browse the repository at this point in the history
…pendatahub-io#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 <[email protected]>
  • Loading branch information
zdtsw committed Jul 4, 2024
1 parent 4a383c1 commit ef231d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
6 changes: 3 additions & 3 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
41 changes: 30 additions & 11 deletions controllers/dscinitialization/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit ef231d1

Please sign in to comment.