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

feat: accepted policy status condition #347

Merged
merged 13 commits into from
Jan 9, 2024
6 changes: 6 additions & 0 deletions api/v1beta2/authpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
return true
}

var _ common.KuadrantPolicy = &AuthPolicy{}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=direct"
Expand Down Expand Up @@ -277,6 +279,10 @@
return
}

func (ap *AuthPolicy) Kind() string {
return ap.TypeMeta.Kind

Check warning on line 283 in api/v1beta2/authpolicy_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta2/authpolicy_types.go#L282-L283

Added lines #L282 - L283 were not covered by tests
}

//+kubebuilder:object:root=true

// AuthPolicyList contains a list of AuthPolicy
Expand Down
6 changes: 6 additions & 0 deletions api/v1beta2/ratelimitpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
return true
}

var _ common.KuadrantPolicy = &RateLimitPolicy{}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=direct"
Expand Down Expand Up @@ -240,6 +242,10 @@
return
}

func (r *RateLimitPolicy) Kind() string {
return r.TypeMeta.Kind

Check warning on line 246 in api/v1beta2/ratelimitpolicy_types.go

View check run for this annotation

Codecov / codecov/patch

api/v1beta2/ratelimitpolicy_types.go#L245-L246

Added lines #L245 - L246 were not covered by tests
}

func init() {
SchemeBuilder.Register(&RateLimitPolicy{}, &RateLimitPolicyList{})
}
24 changes: 16 additions & 8 deletions controllers/authpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
if delResErr == nil {
delResErr = err
}
return r.reconcileStatus(ctx, ap, delResErr)
return r.reconcileStatus(ctx, ap, common.NewErrTargetNotFound(ap.Kind(), ap.GetTargetRef(), delResErr))
}
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -130,13 +130,21 @@
return ctrl.Result{}, nil
}

func (r *AuthPolicyReconciler) reconcileResources(ctx context.Context, ap *api.AuthPolicy, targetNetworkObject client.Object) error {
// validate
// validate performs validation before proceeding with the reconcile loop, returning a common.ErrInvalid on any failing validation
func (r *AuthPolicyReconciler) validate(ap *api.AuthPolicy, targetNetworkObject client.Object) error {
if err := ap.Validate(); err != nil {
return err
return common.NewErrInvalid(ap.Kind(), err)
}

if err := common.ValidateHierarchicalRules(ap, targetNetworkObject); err != nil {
return common.NewErrInvalid(ap.Kind(), err)
}

Check warning on line 141 in controllers/authpolicy_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/authpolicy_controller.go#L140-L141

Added lines #L140 - L141 were not covered by tests

return nil
}

func (r *AuthPolicyReconciler) reconcileResources(ctx context.Context, ap *api.AuthPolicy, targetNetworkObject client.Object) error {
if err := r.validate(ap, targetNetworkObject); err != nil {
return err
}

Expand All @@ -159,7 +167,7 @@
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,13 +189,13 @@
}
}

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

// Ensures only one RLP targets the network resource
func (r *AuthPolicyReconciler) reconcileNetworkResourceDirectBackReference(ctx context.Context, ap *api.AuthPolicy, targetNetworkObject client.Object) error {
return r.ReconcileTargetBackReference(ctx, client.ObjectKeyFromObject(ap), targetNetworkObject, common.AuthPolicyBackRefAnnotation)
func (r *AuthPolicyReconciler) reconcileNetworkResourceDirectBackReference(ctx context.Context, ap common.KuadrantPolicy, targetNetworkObject client.Object) error {
return r.ReconcileTargetBackReference(ctx, ap, targetNetworkObject, common.AuthPolicyBackRefAnnotation)
}

func (r *AuthPolicyReconciler) deleteNetworkResourceDirectBackReference(ctx context.Context, targetNetworkObject client.Object) error {
Expand Down
Loading
Loading