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

chore: address comments for monitoring component #1520

Open
wants to merge 1 commit into
base: main
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
3 changes: 3 additions & 0 deletions controllers/services/monitoring/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import (
"path/filepath"
"strings"

conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
"gopkg.in/yaml.v2"
logf "sigs.k8s.io/controller-runtime/pkg/log"

serviceApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/services/v1alpha1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

var (
ComponentName = serviceApi.MonitoringServiceName
prometheusConfigPath = filepath.Join(odhdeploy.DefaultManifestPath, ComponentName, "prometheus", "apps", "prometheus-configs.yaml")
ReadyConditionType = conditionsv1.ConditionType(serviceApi.MonitoringKind + status.ReadySuffix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for service/component, the ready condition should just be Ready, the suffix is only needed if the service/component specific readiness condition is exposed in an higher level API (i.e. DSC/DSCI)

)

// UpdatePrometheusConfig update prometheus-configs.yaml to include/exclude <component>.rules
Expand Down
29 changes: 23 additions & 6 deletions controllers/services/monitoring/monitoring_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
appsv1 "k8s.io/api/apps/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"

Expand Down Expand Up @@ -79,13 +80,13 @@
// read the component instance to get tha actual status
err := rr.Client.Get(ctx, client.ObjectKeyFromObject(ci), ci)
switch {
case err != nil:
case err == nil:
enabled = meta.IsStatusConditionTrue(ci.GetStatus().Conditions, status.ConditionTypeReady)
case k8serr.IsNotFound(err):

Check warning on line 85 in controllers/services/monitoring/monitoring_controller_actions.go

View check run for this annotation

Codecov / codecov/patch

controllers/services/monitoring/monitoring_controller_actions.go#L83-L85

Added lines #L83 - L85 were not covered by tests
enabled = false
if !k8serr.IsNotFound(err) {
return fmt.Errorf("error getting component state: component=%s, enabled=%t, error=%w", ch.GetName(), enabled, err)
}
default:
enabled = meta.IsStatusConditionTrue(ci.GetStatus().Conditions, status.ConditionTypeReady)
enabled = false
return fmt.Errorf("error getting component state: component=%s, enabled=%t, error=%w", ch.GetName(), enabled, err)

Check warning on line 89 in controllers/services/monitoring/monitoring_controller_actions.go

View check run for this annotation

Codecov / codecov/patch

controllers/services/monitoring/monitoring_controller_actions.go#L88-L89

Added lines #L88 - L89 were not covered by tests
}

// Check for shared components
Expand All @@ -111,6 +112,17 @@
if !ok {
return errors.New("instance is not of type *services.Monitoring")
}

// TODO: deprecate phase
m.Status.Phase = "NotReady"
// condition
nc := metav1.Condition{
Type: string(ReadyConditionType),
Status: metav1.ConditionFalse,
Reason: status.ReconcileInit,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if ReconcileInit makes any sense to be honest, so if the deployment won't get up and running, then we would leave the reason to ReconcileInit forever

Message: status.PhaseNotReady,
}

Check warning on line 125 in controllers/services/monitoring/monitoring_controller_actions.go

View check run for this annotation

Codecov / codecov/patch

controllers/services/monitoring/monitoring_controller_actions.go#L117-L125

Added lines #L117 - L125 were not covered by tests
promDeployment := &appsv1.DeploymentList{}
err := rr.Client.List(
ctx,
Expand All @@ -128,10 +140,15 @@
}
}

m.Status.Phase = "NotReady"
if len(promDeployment.Items) == 1 && ready == 1 {
// TODO: deprecate phase

Check warning on line 144 in controllers/services/monitoring/monitoring_controller_actions.go

View check run for this annotation

Codecov / codecov/patch

controllers/services/monitoring/monitoring_controller_actions.go#L144

Added line #L144 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the if before should either be rewritten like len(promDeployment.Items) == ready or there are more than the expected number of deployment should be reported as part of the failure condition

m.Status.Phase = "Ready"
// condition
nc.Status = metav1.ConditionTrue
nc.Reason = status.ReconcileCompleted
nc.Message = status.ReconcileCompletedMessage

Check warning on line 149 in controllers/services/monitoring/monitoring_controller_actions.go

View check run for this annotation

Codecov / codecov/patch

controllers/services/monitoring/monitoring_controller_actions.go#L146-L149

Added lines #L146 - L149 were not covered by tests
}
meta.SetStatusCondition(&m.Status.Conditions, nc)

Check warning on line 151 in controllers/services/monitoring/monitoring_controller_actions.go

View check run for this annotation

Codecov / codecov/patch

controllers/services/monitoring/monitoring_controller_actions.go#L151

Added line #L151 was not covered by tests
m.Status.ObservedGeneration = m.GetObjectMeta().GetGeneration()

return nil
Expand Down
Loading