Skip to content

Commit

Permalink
feat: auth policy conflict reason
Browse files Browse the repository at this point in the history
  • Loading branch information
KevFan committed Dec 14, 2023
1 parent 132a7af commit 181bbd1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions controllers/authpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (r *AuthPolicyReconciler) reconcileResources(ctx context.Context, ap *api.A
return err
}

// set annotation of policies afftecting the gateway - should be the last step, only when all the reconciliation steps succeed
// set annotation of policies affecting the gateway - should be the last step, only when all the reconciliation steps succeed
return r.ReconcileGatewayPolicyReferences(ctx, ap, gatewayDiffObj)
}

Expand All @@ -181,7 +181,7 @@ func (r *AuthPolicyReconciler) deleteResources(ctx context.Context, ap *api.Auth
}
}

// update annotation of policies afftecting the gateway
// update annotation of policies affecting the gateway
return r.ReconcileGatewayPolicyReferences(ctx, ap, gatewayDiffObj)
}

Expand Down
9 changes: 5 additions & 4 deletions controllers/authpolicy_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
api "github.com/kuadrant/kuadrant-operator/api/v1beta2"
)

const APAvailableConditionType string = "Available"

// reconcileStatus makes sure status block of AuthPolicy is up-to-date.
func (r *AuthPolicyReconciler) reconcileStatus(ctx context.Context, ap *api.AuthPolicy, specErr error) (ctrl.Result, error) {
logger, _ := logr.FromContext(ctx)
Expand Down Expand Up @@ -82,14 +80,14 @@ func (r *AuthPolicyReconciler) calculateStatus(ap *api.AuthPolicy, specErr error
}

targetNetworkObjectKind := string(ap.Spec.TargetRef.Kind)
availableCond := r.availableCondition(targetNetworkObjectKind, specErr, authConfigReady)
availableCond := r.acceptedCondition(targetNetworkObjectKind, specErr, authConfigReady)

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

return newStatus
}

func (r *AuthPolicyReconciler) availableCondition(targetNetworkObjectKind string, specErr error, authConfigReady bool) *metav1.Condition {
func (r *AuthPolicyReconciler) acceptedCondition(targetNetworkObjectKind string, specErr error, authConfigReady bool) *metav1.Condition {
// Condition if there is no issue
cond := &metav1.Condition{
Type: string(gatewayapiv1alpha2.PolicyConditionAccepted),
Expand All @@ -109,6 +107,9 @@ func (r *AuthPolicyReconciler) availableCondition(targetNetworkObjectKind string
// Invalid
case errors.As(specErr, &common.ErrInvalid{}):
cond.Reason = string(gatewayapiv1alpha2.PolicyReasonInvalid)
// Conflicted
case errors.As(specErr, &common.ErrConflict{}):
cond.Reason = string(gatewayapiv1alpha2.PolicyReasonConflicted)
default:
cond.Reason = "ReconciliationError"
}
Expand Down
3 changes: 1 addition & 2 deletions controllers/ratelimitpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ 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 common.ErrInvalid{Kind: rlp.Kind(), Err: err}
Expand Down Expand Up @@ -181,7 +180,7 @@ func (r *RateLimitPolicyReconciler) reconcileResources(ctx context.Context, rlp
return err
}

// set annotation of policies afftecting the gateway - should be the last step, only when all the reconciliation steps succeed
// set annotation of policies affecting the gateway - should be the last step, only when all the reconciliation steps succeed
return r.ReconcileGatewayPolicyReferences(ctx, rlp, gatewayDiffObj)
}

Expand Down

0 comments on commit 181bbd1

Please sign in to comment.