Skip to content

Commit

Permalink
refactor: use common acception condition function instead
Browse files Browse the repository at this point in the history
  • Loading branch information
KevFan committed Dec 14, 2023
1 parent 59aaaa0 commit ba26ec2
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 371 deletions.
2 changes: 2 additions & 0 deletions api/v1beta2/authpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ func (s *AuthPolicyStatus) Equals(other *AuthPolicyStatus, logger logr.Logger) b
return true
}

var _ common.KuadrantPolicy = &AuthPolicy{}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=direct"
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta2/ratelimitpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ func (s *RateLimitPolicyStatus) Equals(other *RateLimitPolicyStatus, logger logr
return true
}

var _ common.KuadrantPolicy = &RateLimitPolicy{}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:metadata:labels="gateway.networking.k8s.io/policy=direct"
Expand Down
6 changes: 3 additions & 3 deletions controllers/authpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (r *AuthPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl.Requ
if delResErr == nil {
delResErr = err
}
return r.reconcileStatus(ctx, ap, common.ErrTargetNotFound{Kind: ap.Kind(), TargetRef: ap.GetTargetRef(), Err: delResErr})
return r.reconcileStatus(ctx, ap, common.NewErrTargetNotFound(ap.Kind(), ap.GetTargetRef(), delResErr))
}
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -133,11 +133,11 @@ func (r *AuthPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl.Requ
func (r *AuthPolicyReconciler) reconcileResources(ctx context.Context, ap *api.AuthPolicy, targetNetworkObject client.Object) error {
// validate
if err := ap.Validate(); err != nil {
return common.ErrInvalid{Kind: ap.Kind(), Err: err}
return common.NewErrInvalid(ap.Kind(), err)
}

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

Check warning on line 140 in controllers/authpolicy_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/authpolicy_controller.go#L140

Added line #L140 was not covered by tests
}

// reconcile based on gateway diffs
Expand Down
Loading

0 comments on commit ba26ec2

Please sign in to comment.