Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: monitoring stack only apply if it is managed cluster + do not create monitoring namespace for non-Managed offering #1321

Open
wants to merge 1 commit into
base: incubation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,35 +234,24 @@
if !createUsergroup {
log.Info("DSCI disabled usergroup creation")
} else {
err := r.createUserGroup(ctx, instance, "rhods-admins")
if err != nil {
return reconcile.Result{}, err
}
}
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed {
log.Info("Monitoring enabled, won't apply changes", "cluster", "Self-Managed RHODS Mode")
err = r.configureCommonMonitoring(ctx, instance)
if err != nil {
if err := r.createUserGroup(ctx, instance, "rhods-admins"); err != nil {

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

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L237

Added line #L237 was not covered by tests
return reconcile.Result{}, err
}
}
case cluster.ManagedRhoai:
osdConfigsPath := filepath.Join(deploy.DefaultManifestPath, "osd-configs")
err = deploy.DeployManifestsFromPath(ctx, r.Client, instance, osdConfigsPath, r.ApplicationsNamespace, "osd", true)
if err != nil {
if err = deploy.DeployManifestsFromPath(ctx, r.Client, instance, osdConfigsPath, r.ApplicationsNamespace, "osd", true); err != nil {

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

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L243

Added line #L243 was not covered by tests
log.Error(err, "Failed to apply osd specific configs from manifests", "Manifests path", osdConfigsPath)
r.Recorder.Eventf(instance, corev1.EventTypeWarning, "DSCInitializationReconcileError", "Failed to apply "+osdConfigsPath)

return reconcile.Result{}, err
}
if instance.Spec.Monitoring.ManagementState == operatorv1.Managed {
log.Info("Monitoring enabled in initialization stage", "cluster", "Managed Service Mode")
err := r.configureManagedMonitoring(ctx, instance, "init")
if err != nil {
if err := r.configureManagedMonitoring(ctx, instance, "init"); err != nil {

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

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L251

Added line #L251 was not covered by tests
return reconcile.Result{}, err
}
err = r.configureCommonMonitoring(ctx, instance)
if err != nil {
if err = r.configureCommonMonitoring(ctx, instance); err != nil {

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

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/dscinitialization_controller.go#L254

Added line #L254 was not covered by tests
return reconcile.Result{}, err
}
}
Expand Down
5 changes: 2 additions & 3 deletions controllers/dscinitialization/dscinitialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var _ = Describe("DataScienceCluster initialization", func() {
WithPolling(interval).
Should(BeFalse())
})
It("Should create default monitoring namespace if monitoring enabled", func(ctx context.Context) {
It("Should not create default monitoring namespace even monitoring enabled for non-managed cluster", func(ctx context.Context) {
// when
desiredDsci := createDSCI(operatorv1.Managed, operatorv1.Managed, monitoringNamespace2)
Expect(k8sClient.Create(ctx, desiredDsci)).Should(Succeed())
Expand All @@ -159,8 +159,7 @@ var _ = Describe("DataScienceCluster initialization", func() {
WithContext(ctx).
WithTimeout(timeout).
WithPolling(interval).
Should(BeTrue())
Expect(foundMonitoringNamespace.Name).Should(Equal(monitoringNamespace2))
Should(BeFalse())
})
})

Expand Down
18 changes: 10 additions & 8 deletions controllers/dscinitialization/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
return err
}
}
// Create Monitoring Namespace if it is enabled and not exists
if dscInit.Spec.Monitoring.ManagementState == operatorv1.Managed {
// Create Monitoring Namespace if it is enabled and not exists and only for Managed cluster
if dscInit.Spec.Monitoring.ManagementState == operatorv1.Managed && platform == cluster.ManagedRhoai {
foundMonitoringNamespace := &corev1.Namespace{}
monitoringName := dscInit.Spec.Monitoring.Namespace
err := r.Get(ctx, client.ObjectKey{Name: monitoringName}, foundMonitoringNamespace)
Expand Down Expand Up @@ -205,18 +205,20 @@
log.Error(err, "error to set networkpolicy in operator namespace", "path", networkpolicyPath)
return err
}
// Deploy networkpolicy for monitoring namespace
err = deploy.DeployManifestsFromPath(ctx, r.Client, dscInit, networkpolicyPath+"/monitoring", dscInit.Spec.Monitoring.Namespace, "networkpolicy", true)
if err != nil {
log.Error(err, "error to set networkpolicy in monitroing namespace", "path", networkpolicyPath)
return err
}
// Deploy networkpolicy for applications namespace
err = deploy.DeployManifestsFromPath(ctx, r.Client, dscInit, networkpolicyPath+"/applications", dscInit.Spec.ApplicationsNamespace, "networkpolicy", true)
if err != nil {
log.Error(err, "error to set networkpolicy in applications namespace", "path", networkpolicyPath)
return err
}
if platform == cluster.ManagedRhoai {
// Deploy networkpolicy for monitoring namespace
err = deploy.DeployManifestsFromPath(ctx, r.Client, dscInit, networkpolicyPath+"/monitoring", dscInit.Spec.Monitoring.Namespace, "networkpolicy", true)
if err != nil {
log.Error(err, "error to set networkpolicy in monitroing namespace", "path", networkpolicyPath)
return err
}

Check warning on line 220 in controllers/dscinitialization/utils.go

View check run for this annotation

Codecov / codecov/patch

controllers/dscinitialization/utils.go#L214-L220

Added lines #L214 - L220 were not covered by tests
}
} else { // Expected namespace for the given name in ODH
desiredNetworkPolicy := &networkingv1.NetworkPolicy{
TypeMeta: metav1.TypeMeta{
Expand Down
17 changes: 14 additions & 3 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func CleanupExistingResource(ctx context.Context,
oldReleaseVersion cluster.Release,
) error {
var multiErr *multierror.Error
// Special Handling of cleanup of deprecated model monitoring stack
// Special Handling of cleanup of deprecated model monitoring stack on managed
if platform == cluster.ManagedRhoai {
deprecatedDeployments := []string{"rhods-prometheus-operator"}
multiErr = multierror.Append(multiErr, deleteDeprecatedResources(ctx, cli, dscMonitoringNamespace, deprecatedDeployments, &appsv1.DeploymentList{}))
Expand Down Expand Up @@ -247,9 +247,20 @@ func CleanupExistingResource(ctx context.Context,
deprecatedServicemonitors := []string{"modelmesh-federated-metrics"}
multiErr = multierror.Append(multiErr, deleteDeprecatedServiceMonitors(ctx, cli, dscMonitoringNamespace, deprecatedServicemonitors))
}
// Special Handling of cleanup of deprecated SRE monitoring stack on self-managed
if platform == cluster.SelfManagedRhoai {
deprecatedOperatorSM := []string{"rhods-monitor-federation"}
multiErr = multierror.Append(multiErr, deleteDeprecatedServiceMonitors(ctx, cli, dscMonitoringNamespace, deprecatedOperatorSM))

deprecatedRolebindings := []string{"rhods-prometheus-cluster-monitoring-viewer-binding", "redhat-ods-monitoring"}
multiErr = multierror.Append(multiErr, deleteDeprecatedResources(ctx, cli, dscMonitoringNamespace, deprecatedRolebindings, &rbacv1.RoleBindingList{}))

deprecatedRroles := []string{"redhat-ods-monitoring"}
multiErr = multierror.Append(multiErr, deleteDeprecatedResources(ctx, cli, dscMonitoringNamespace, deprecatedRroles, &rbacv1.RoleList{}))
}
// common logic for both self-managed and managed
deprecatedOperatorSM := []string{"rhods-monitor-federation2"}
multiErr = multierror.Append(multiErr, deleteDeprecatedServiceMonitors(ctx, cli, dscMonitoringNamespace, deprecatedOperatorSM))
deprecatedOperatorSM2 := []string{"rhods-monitor-federation2"}
multiErr = multierror.Append(multiErr, deleteDeprecatedServiceMonitors(ctx, cli, dscMonitoringNamespace, deprecatedOperatorSM2))

// Remove deprecated opendatahub namespace(previously owned by kuberay and Kueue)
multiErr = multierror.Append(multiErr, deleteDeprecatedNamespace(ctx, cli, "opendatahub"))
Expand Down