Skip to content

Commit

Permalink
feat: rlp accepted condition
Browse files Browse the repository at this point in the history
  • Loading branch information
KevFan committed Dec 4, 2023
1 parent b736a7b commit 5d369a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions controllers/ratelimitpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (r *RateLimitPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl
// fetch the target network object
targetNetworkObject, err := r.FetchValidTargetRef(ctx, rlp.GetTargetRef(), rlp.Namespace)
if err != nil {
// TODO - Target not found status
if !markedForDeletion {
if apierrors.IsNotFound(err) {
logger.V(1).Info("Network object not found. Cleaning up")
Expand Down Expand Up @@ -151,6 +152,7 @@ func (r *RateLimitPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl

func (r *RateLimitPolicyReconciler) reconcileResources(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy, targetNetworkObject client.Object) error {
// validate
// TODO - Validation Error
err := rlp.Validate()
if err != nil {
return err
Expand Down
24 changes: 13 additions & 11 deletions controllers/ratelimitpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
)

const (
RLPAvailableConditionType string = "Available"
)

func (r *RateLimitPolicyReconciler) reconcileStatus(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy, specErr error) (ctrl.Result, error) {
logger, _ := logr.FromContext(ctx)
newStatus := r.calculateStatus(ctx, rlp, specErr)
Expand Down Expand Up @@ -62,26 +59,31 @@ func (r *RateLimitPolicyReconciler) calculateStatus(_ context.Context, rlp *kuad
ObservedGeneration: rlp.Status.ObservedGeneration,
}

availableCond := r.availableCondition(specErr)
acceptedCond := r.acceptedCondition(specErr)

meta.SetStatusCondition(&newStatus.Conditions, *availableCond)
meta.SetStatusCondition(&newStatus.Conditions, *acceptedCond)

return newStatus
}

func (r *RateLimitPolicyReconciler) availableCondition(specErr error) *metav1.Condition {
// TODO - Accepted Condition
func (r *RateLimitPolicyReconciler) acceptedCondition(specErr error) *metav1.Condition {
cond := &metav1.Condition{
Type: RLPAvailableConditionType,
Type: string(gatewayapiv1alpha2.PolicyConditionAccepted),
Status: metav1.ConditionTrue,
Reason: "HTTPRouteProtected",
Message: "HTTPRoute is ratelimited",
Reason: string(gatewayapiv1alpha2.PolicyReasonAccepted),
Message: "KuadrantPolicy has been accepted",
}

if specErr != nil {
cond.Status = metav1.ConditionFalse
cond.Reason = "ReconcilliationError"
cond.Reason = "ReconciliationError"
cond.Message = specErr.Error()
}

// TODO - Invalid Condition
// TODO - TargetNotFound Condition
// TODO - Conflicted Condition

return cond
}

0 comments on commit 5d369a4

Please sign in to comment.