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

improve deployment status report #142

Merged
merged 1 commit into from
Jun 11, 2024
Merged
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
25 changes: 18 additions & 7 deletions controllers/limitador_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Comment on lines +144 to +147
Copy link
Contributor

Choose a reason for hiding this comment

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

Any thoughts about an edge case where an user sets limitador.spec.replicas to 0, so deployment.status.replicas is 0. The current logic will mark the CR status as Ready: true, would this be the expected status for this edge case? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. I think we should follow the same approach as the replication controller for the Deployment object.

I set limtiador CR with replica: 0

spec:
  replicas: 0

The operator updates the deployment object to:

spec:
  replicas: 0
  ....

And the status of the deployment is:

status:
  conditions:
  - lastTransitionTime: "2024-06-10T08:26:11Z"
    lastUpdateTime: "2024-06-10T08:26:11Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: "2024-06-10T08:25:51Z"
    lastUpdateTime: "2024-06-10T08:26:11Z"
    message: ReplicaSet "limitador-limitador-76c6d7bd46" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  observedGeneration: 2

Note that as status.availableReplicas, status.readyReplicas, status.replicas are all 0, they are not shown in the response (considered "empty").

Yet, the status condition Available is True. Thus, we can account that as "available".

Thus, IMO, limitador CR status should also be considered "Ready". I agree, though, that "Ready" does not reflect the actual state. It would be more meaningful, "Reconciled" or "Stable" or something that means, limitador is what it should be, what the user wanted to be. When the replicas are 0, I can leave "Ready" to "True", and the message would be "Limitador is ready, but without running instances". (or something like that).

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, sounds good 👍

return nil, nil
}

Expand Down
Loading