Skip to content

Commit

Permalink
feat: validate limitador operator crd is installed for rate limit pol…
Browse files Browse the repository at this point in the history
…icy status

Signed-off-by: KevFan <[email protected]>
  • Loading branch information
KevFan committed Nov 13, 2024
1 parent c57f528 commit 9fa5b2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions controllers/data_plane_policies_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ var (
//+kubebuilder:rbac:groups=kuadrant.io,resources=ratelimitpolicies/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=kuadrant.io,resources=ratelimitpolicies/finalizers,verbs=update

func NewDataPlanePoliciesWorkflow(client *dynamic.DynamicClient, isIstioInstalled, isEnvoyGatewayInstalled bool) *controller.Workflow {
func NewDataPlanePoliciesWorkflow(client *dynamic.DynamicClient, isIstioInstalled, isEnvoyGatewayInstalled, isLimitadorOperatorInstalled bool) *controller.Workflow {
dataPlanePoliciesValidation := &controller.Workflow{
Tasks: []controller.ReconcileFunc{
(&AuthPolicyValidator{}).Subscription().Reconcile,
(&RateLimitPolicyValidator{}).Subscription().Reconcile,
(&RateLimitPolicyValidator{isLimitadorOperatorInstalled: isLimitadorOperatorInstalled}).Subscription().Reconcile,
},
}

Expand Down
8 changes: 7 additions & 1 deletion controllers/ratelimit_policies_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import (
kuadrant "github.com/kuadrant/kuadrant-operator/pkg/kuadrant"
)

type RateLimitPolicyValidator struct{}
type RateLimitPolicyValidator struct {
isLimitadorOperatorInstalled bool
}

// RateLimitPolicyValidator subscribes to events with potential to flip the validity of rate limit policies
func (r *RateLimitPolicyValidator) Subscription() controller.Subscription {
Expand All @@ -41,6 +43,10 @@ func (r *RateLimitPolicyValidator) Validate(ctx context.Context, _ []controller.
defer logger.V(1).Info("finished validating rate limit policies")

state.Store(StateRateLimitPolicyValid, lo.SliceToMap(policies, func(policy machinery.Policy) (string, error) {
if !r.isLimitadorOperatorInstalled {
return policy.GetLocator(), kuadrant.NewErrDependencyNotInstalled("Limitador Operator")
}

var err error
if len(policy.GetTargetRefs()) > 0 && len(topology.Targetables().Children(policy)) == 0 {
ref := policy.GetTargetRefs()[0]
Expand Down

0 comments on commit 9fa5b2d

Please sign in to comment.