Skip to content

Commit

Permalink
[refactor] Using Limitador CR condition ready instead of Deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
didierofrivia committed Nov 21, 2023
1 parent 0c9289d commit cbbdcd8
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions controllers/kuadrant_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package controllers
import (
"context"
"fmt"
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"

"github.com/go-logr/logr"
"golang.org/x/exp/slices"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -94,7 +94,7 @@ func (r *KuadrantReconciler) readyCondition(ctx context.Context, kObj *kuadrantv
return cond, nil
}

reason, err := r.checkLimitadorAvailable(ctx, kObj)
reason, err := r.checkLimitadorReady(ctx, kObj)
if err != nil {
return nil, err
}
Expand All @@ -119,29 +119,23 @@ func (r *KuadrantReconciler) readyCondition(ctx context.Context, kObj *kuadrantv
return cond, nil
}

func (r *KuadrantReconciler) checkLimitadorAvailable(ctx context.Context, kObj *kuadrantv1beta1.Kuadrant) (*string, error) {
// Should be implemented reading the Limitador CR's status conditions.
// Not implemented yet in the limitador's operator
deployment := &appsv1.Deployment{}
dKey := client.ObjectKey{Name: "limitador", Namespace: kObj.Namespace}
err := r.Client().Get(ctx, dKey, deployment)
func (r *KuadrantReconciler) checkLimitadorReady(ctx context.Context, kObj *kuadrantv1beta1.Kuadrant) (*string, error) {
limitadorObj := &limitadorv1alpha1.Limitador{}
limitadorKey := client.ObjectKey{Name: common.LimitadorName, Namespace: kObj.Namespace}

err := r.Client().Get(ctx, limitadorKey, limitadorObj)
if err != nil && !errors.IsNotFound(err) {
return nil, err
}

if err != nil && errors.IsNotFound(err) {
tmp := err.Error()
return &tmp, nil
}

availableCondition := common.FindDeploymentStatusCondition(deployment.Status.Conditions, "Available")
if availableCondition == nil {
tmp := "Available condition not found"
return &tmp, nil
reason := err.Error()
return &reason, nil
}

if availableCondition.Status != corev1.ConditionTrue {
return &availableCondition.Message, nil
if !meta.IsStatusConditionTrue(limitadorObj.Status.Conditions, "Ready") {
reason := "limitador is not ready"
return &reason, fmt.Errorf(reason)
}

return nil, nil
Expand Down

0 comments on commit cbbdcd8

Please sign in to comment.