From 1bc2191bd6e4b29873f41792ac6f01976c83e11c Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Tue, 28 May 2024 14:41:52 +0200 Subject: [PATCH] improve deployment status report --- controllers/limitador_status.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/controllers/limitador_status.go b/controllers/limitador_status.go index 10ae7acf..562c7765 100644 --- a/controllers/limitador_status.go +++ b/controllers/limitador_status.go @@ -10,6 +10,7 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -115,25 +116,35 @@ func (r *LimitadorReconciler) checkLimitadorAvailable(ctx context.Context, limit Name: limitador.DeploymentName(limitadorObj), } err := r.Client().Get(ctx, dKey, deployment) - if err != nil && !apierrors.IsNotFound(err) { + if client.IgnoreNotFound(err) != nil { return nil, err } - if err != nil && apierrors.IsNotFound(err) { - tmp := err.Error() - return &tmp, nil + if apierrors.IsNotFound(err) { + return ptr.To(err.Error()), nil } - availableCondition := helpers.FindDeploymentStatusCondition(deployment.Status.Conditions, "Available") + if deployment.Status.ObservedGeneration != deployment.Generation { + return ptr.To("Deployment still in progress"), nil + } + + availableCondition := helpers.FindDeploymentStatusCondition(deployment.Status.Conditions, string(appsv1.DeploymentAvailable)) if availableCondition == nil { - tmp := "Available condition not found" - return &tmp, nil + return ptr.To("Available condition not found"), nil } if availableCondition.Status != corev1.ConditionTrue { return &availableCondition.Message, nil } + if deployment.Status.UnavailableReplicas != 0 { + return ptr.To("Deployment has unavailable replicas"), nil + } + + if deployment.Status.ReadyReplicas != deployment.Status.Replicas { + return ptr.To("Deployment has replicas not ready yet"), nil + } + return nil, nil }