Skip to content

Commit

Permalink
update: add monitoring CR status on condition of prom deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
(cherry picked from commit e0b7c39)
  • Loading branch information
zdtsw authored and VaishnaviHire committed Jan 18, 2025
1 parent 090dae5 commit 633ff94
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion controllers/services/monitoring/monitoring_controller_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"

appsv1 "k8s.io/api/apps/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -110,8 +111,27 @@ func updateStatus(ctx context.Context, rr *odhtypes.ReconciliationRequest) error
if !ok {
return errors.New("instance is not of type *services.Monitoring")
}
promDeployment := &appsv1.DeploymentList{}
err := rr.Client.List(
ctx,
promDeployment,
client.InNamespace(rr.DSCI.Spec.Monitoring.Namespace),
)
if err != nil {
return fmt.Errorf("error fetching promethus deployments: %w", err)
}

ready := 0
for _, deployment := range promDeployment.Items {
if deployment.Status.ReadyReplicas == deployment.Status.Replicas {
ready++
}
}

m.Status.Phase = "Ready"
m.Status.Phase = "NotReady"
if len(promDeployment.Items) == 1 && ready == 1 {
m.Status.Phase = "Ready"
}
m.Status.ObservedGeneration = m.GetObjectMeta().GetGeneration()

return nil
Expand Down

0 comments on commit 633ff94

Please sign in to comment.