Skip to content

Commit

Permalink
update: change dsci monitoring type
Browse files Browse the repository at this point in the history
- move check into a function
- fix the case when user remove entire monitoring block from DSCI

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw committed Dec 2, 2024
1 parent 0b4b1f4 commit f46cfc2
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 33 deletions.
2 changes: 1 addition & 1 deletion apis/dscinitialization/v1/dscinitialization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type DSCInitializationSpec struct {
// Enable monitoring on specified namespace
// +operator-sdk:csv:customresourcedefinitions:type=spec,order=2
// +optional
Monitoring Monitoring `json:"monitoring,omitempty"`
Monitoring *Monitoring `json:"monitoring,omitempty"`
// Configures Service Mesh as networking layer for Data Science Clusters components.
// The Service Mesh is a mandatory prerequisite for single model serving (KServe) and
// you should review this configuration if you are planning to use KServe.
Expand Down
6 changes: 5 additions & 1 deletion apis/dscinitialization/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion components/codeflare/codeflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

Expand Down Expand Up @@ -79,7 +80,7 @@ func (c *CodeFlare) ReconcileComponent(ctx context.Context,
_ bool) error {
l := logf.FromContext(ctx)
enabled := c.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)

if enabled {
if c.DevFlags != nil {
Expand Down
3 changes: 2 additions & 1 deletion components/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

Expand Down Expand Up @@ -92,7 +93,7 @@ func (d *Dashboard) ReconcileComponent(ctx context.Context,
entryPath := DefaultPath
l := logf.FromContext(ctx)
enabled := d.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)

if enabled {
// 1. cleanup OAuth client related secret and CR if dashboard is in 'installed false' status
Expand Down
3 changes: 2 additions & 1 deletion components/datasciencepipelines/datasciencepipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
)
Expand Down Expand Up @@ -94,7 +95,7 @@ func (d *DataSciencePipelines) ReconcileComponent(ctx context.Context,
) error {
l := logf.FromContext(ctx)
enabled := d.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)

if enabled {
if d.DevFlags != nil {
Expand Down
3 changes: 2 additions & 1 deletion components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

Expand Down Expand Up @@ -115,7 +116,7 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := k.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)

if !enabled {
if err := deploy.ApplyParams(DependentPath, nil, map[string]string{"nim-state": "removed"}); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion components/kueue/kueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

Expand Down Expand Up @@ -71,7 +72,7 @@ func (k *Kueue) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := k.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)
if enabled {
if k.DevFlags != nil {
// Download manifests and update paths
Expand Down
3 changes: 2 additions & 1 deletion components/modelmeshserving/modelmeshserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

Expand Down Expand Up @@ -110,7 +111,7 @@ func (m *ModelMeshServing) ReconcileComponent(ctx context.Context,
) error {
l := logf.FromContext(ctx)
enabled := m.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)

// Update Default rolebinding
if enabled {
Expand Down
3 changes: 2 additions & 1 deletion components/modelregistry/modelregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/conversion"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"

Expand Down Expand Up @@ -100,7 +101,7 @@ func (m *ModelRegistry) ReconcileComponent(ctx context.Context, cli client.Clien
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := m.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)

if enabled {
// return error if ServiceMesh is not enabled, as it's a required feature
Expand Down
3 changes: 2 additions & 1 deletion components/ray/ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

Expand Down Expand Up @@ -72,7 +73,7 @@ func (r *Ray) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := r.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)

if enabled {
if r.DevFlags != nil {
Expand Down
3 changes: 2 additions & 1 deletion components/trainingoperator/trainingoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

Expand Down Expand Up @@ -73,7 +74,7 @@ func (r *TrainingOperator) ReconcileComponent(ctx context.Context, cli client.Cl
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := r.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)

if enabled {
if r.DevFlags != nil {
Expand Down
3 changes: 2 additions & 1 deletion components/trustyai/trustyai.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ func (t *TrustyAI) ReconcileComponent(ctx context.Context, cli client.Client,
owner metav1.Object, dscispec *dsciv1.DSCInitializationSpec, platform cluster.Platform, _ bool) error {
l := logf.FromContext(ctx)
enabled := t.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)
entryPath := DefaultPath

if enabled {
Expand Down
3 changes: 2 additions & 1 deletion components/workbenches/workbenches.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
)
Expand Down Expand Up @@ -116,7 +117,7 @@ func (w *Workbenches) ReconcileComponent(ctx context.Context, cli client.Client,
// Set default notebooks namespace
// Create rhods-notebooks namespace in managed platforms
enabled := w.GetManagementState() == operatorv1.Managed
monitoringEnabled := dscispec.Monitoring.ManagementState == operatorv1.Managed
monitoringEnabled := common.IsMonitoringEnabled(dscispec.Monitoring)
if enabled {
if w.DevFlags != nil {
// Download manifests and update paths
Expand Down
14 changes: 7 additions & 7 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"path/filepath"
"reflect"

operatorv1 "github.com/openshift/api/operator/v1"
routev1 "github.com/openshift/api/route/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -47,6 +46,7 @@ import (
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/logger"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/trustedcabundle"
Expand Down Expand Up @@ -193,7 +193,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re

switch req.Name {
case "prometheus": // prometheus configmap
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed && platform == cluster.ManagedRhoai {
if common.IsMonitoringEnabled(instance.Spec.Monitoring) && platform == cluster.ManagedRhoai {

Check warning on line 196 in controllers/dscinitialization/dscinitialization_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L196

Added line #L196 was not covered by tests
log.Info("Monitoring enabled to restart deployment", "cluster", "Managed Service Mode")
err := r.configureManagedMonitoring(ctx, instance, "updates")
if err != nil {
Expand All @@ -203,7 +203,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re

return ctrl.Result{}, nil
case "addon-managed-odh-parameters":
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed && platform == cluster.ManagedRhoai {
if common.IsMonitoringEnabled(instance.Spec.Monitoring) && platform == cluster.ManagedRhoai {

Check warning on line 206 in controllers/dscinitialization/dscinitialization_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L206

Added line #L206 was not covered by tests
log.Info("Monitoring enabled when notification updated", "cluster", "Managed Service Mode")
err := r.configureManagedMonitoring(ctx, instance, "updates")
if err != nil {
Expand All @@ -213,7 +213,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re

return ctrl.Result{}, nil
case "backup": // revert back to the original prometheus.yml
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed && platform == cluster.ManagedRhoai {
if common.IsMonitoringEnabled(instance.Spec.Monitoring) && platform == cluster.ManagedRhoai {

Check warning on line 216 in controllers/dscinitialization/dscinitialization_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L216

Added line #L216 was not covered by tests
log.Info("Monitoring enabled to restore back", "cluster", "Managed Service Mode")
err := r.configureManagedMonitoring(ctx, instance, "revertbackup")
if err != nil {
Expand All @@ -239,7 +239,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
return reconcile.Result{}, err
}
}
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed {
if common.IsMonitoringEnabled(instance.Spec.Monitoring) {

Check warning on line 242 in controllers/dscinitialization/dscinitialization_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L242

Added line #L242 was not covered by tests
log.Info("Monitoring enabled, won't apply changes", "cluster", "Self-Managed RHODS Mode")
err = r.configureCommonMonitoring(ctx, instance)
if err != nil {
Expand All @@ -255,7 +255,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re

return reconcile.Result{}, err
}
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed {
if common.IsMonitoringEnabled(instance.Spec.Monitoring) {

Check warning on line 258 in controllers/dscinitialization/dscinitialization_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L258

Added line #L258 was not covered by tests
log.Info("Monitoring enabled in initialization stage", "cluster", "Managed Service Mode")
err := r.configureManagedMonitoring(ctx, instance, "init")
if err != nil {
Expand All @@ -276,7 +276,7 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
return reconcile.Result{}, err
}
}
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed {
if common.IsMonitoringEnabled(instance.Spec.Monitoring) {
log.Info("Monitoring enabled, won't apply changes", "cluster", "ODH Mode")
}
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/dscinitialization/dscinitialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func createDSCI(enableMonitoring operatorv1.ManagementState, enableTrustedCABund
},
Spec: dsciv1.DSCInitializationSpec{
ApplicationsNamespace: applicationNamespace,
Monitoring: dsciv1.Monitoring{
Monitoring: &dsciv1.Monitoring{
Namespace: monitoringNS,
ManagementState: enableMonitoring,
},
Expand Down
11 changes: 5 additions & 6 deletions controllers/dscinitialization/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"path/filepath"
"strings"

operatorv1 "github.com/openshift/api/operator/v1"
routev1 "github.com/openshift/api/route/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -235,7 +234,7 @@ func configurePrometheus(ctx context.Context, dsciInit *dsciv1.DSCInitialization
prometheusConfigPath,
dsciInit.Spec.Monitoring.Namespace,
"prometheus",
dsciInit.Spec.Monitoring.ManagementState == operatorv1.Managed); err != nil {
common.IsMonitoringEnabled(dsciInit.Spec.Monitoring)); err != nil {

Check warning on line 237 in controllers/dscinitialization/monitoring.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/monitoring.go#L237

Added line #L237 was not covered by tests
log.Error(err, "error to deploy manifests for prometheus configs", "path", prometheusConfigPath)
return err
}
Expand Down Expand Up @@ -384,7 +383,7 @@ func configureBlackboxExporter(ctx context.Context, dsciInit *dsciv1.DSCInitiali
filepath.Join(blackBoxPath, "internal"),
dsciInit.Spec.Monitoring.Namespace,
"blackbox-exporter",
dsciInit.Spec.Monitoring.ManagementState == operatorv1.Managed); err != nil {
common.IsMonitoringEnabled(dsciInit.Spec.Monitoring)); err != nil {

Check warning on line 386 in controllers/dscinitialization/monitoring.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/monitoring.go#L386

Added line #L386 was not covered by tests
log.Error(err, "error to deploy manifests: %w", "error", err)
return err
}
Expand All @@ -394,7 +393,7 @@ func configureBlackboxExporter(ctx context.Context, dsciInit *dsciv1.DSCInitiali
filepath.Join(blackBoxPath, "external"),
dsciInit.Spec.Monitoring.Namespace,
"blackbox-exporter",
dsciInit.Spec.Monitoring.ManagementState == operatorv1.Managed); err != nil {
common.IsMonitoringEnabled(dsciInit.Spec.Monitoring)); err != nil {

Check warning on line 396 in controllers/dscinitialization/monitoring.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/monitoring.go#L396

Added line #L396 was not covered by tests
log.Error(err, "error to deploy manifests: %w", "error", err)
return err
}
Expand Down Expand Up @@ -458,7 +457,7 @@ func (r *DSCInitializationReconciler) configureSegmentIO(ctx context.Context, ds
segmentPath,
dsciInit.Spec.ApplicationsNamespace,
"segment-io",
dsciInit.Spec.Monitoring.ManagementState == operatorv1.Managed); err != nil {
common.IsMonitoringEnabled(dsciInit.Spec.Monitoring)); err != nil {

Check warning on line 460 in controllers/dscinitialization/monitoring.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/monitoring.go#L460

Added line #L460 was not covered by tests
log.Error(err, "error to deploy manifests under "+segmentPath)
return err
}
Expand Down Expand Up @@ -492,7 +491,7 @@ func (r *DSCInitializationReconciler) configureCommonMonitoring(ctx context.Cont
monitoringBasePath,
"",
"monitoring-base",
dsciInit.Spec.Monitoring.ManagementState == operatorv1.Managed); err != nil {
common.IsMonitoringEnabled(dsciInit.Spec.Monitoring)); err != nil {

Check warning on line 494 in controllers/dscinitialization/monitoring.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/monitoring.go#L494

Added line #L494 was not covered by tests
log.Error(err, "error to deploy manifests under "+monitoringBasePath)
return err
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/dscinitialization/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"
"time"

operatorv1 "github.com/openshift/api/operator/v1"
userv1 "github.com/openshift/api/user/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
Expand All @@ -22,6 +21,7 @@ import (

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
)
Expand Down Expand Up @@ -72,7 +72,7 @@ func (r *DSCInitializationReconciler) createOdhNamespace(ctx context.Context, ds
return err
}
// Patch Application Namespace if it exists
} else if dscInit.Spec.Monitoring.ManagementState == operatorv1.Managed {
} else if common.IsMonitoringEnabled(dscInit.Spec.Monitoring) {
log.Info("Patching application namespace for Managed cluster", "name", name)
labelPatch := `{"metadata":{"labels":{"openshift.io/cluster-monitoring":"true","pod-security.kubernetes.io/enforce":"baseline","opendatahub.io/generated-namespace": "true"}}}`
err = r.Patch(ctx, foundNamespace, client.RawPatch(types.MergePatchType,
Expand All @@ -82,7 +82,7 @@ func (r *DSCInitializationReconciler) createOdhNamespace(ctx context.Context, ds
}
}
// Create Monitoring Namespace if it is enabled and not exists
if dscInit.Spec.Monitoring.ManagementState == operatorv1.Managed {
if common.IsMonitoringEnabled(dscInit.Spec.Monitoring) {
foundMonitoringNamespace := &corev1.Namespace{}
monitoringName := dscInit.Spec.Monitoring.Namespace
err := r.Get(ctx, client.ObjectKey{Name: monitoringName}, foundMonitoringNamespace)
Expand Down
2 changes: 1 addition & 1 deletion controllers/webhook/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func newDSCI(appName string) *dsciv1.DSCInitialization {
},
Spec: dsciv1.DSCInitializationSpec{
ApplicationsNamespace: namespace,
Monitoring: dsciv1.Monitoring{
Monitoring: &dsciv1.Monitoring{
Namespace: monitoringNS,
ManagementState: operatorv1.Managed,
},
Expand Down
Loading

0 comments on commit f46cfc2

Please sign in to comment.