Skip to content

Commit

Permalink
refactor: package import naming & use consts for reference annotation…
Browse files Browse the repository at this point in the history
… strings
  • Loading branch information
KevFan committed Feb 20, 2024
1 parent 865c1c4 commit 15753fd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
9 changes: 7 additions & 2 deletions api/v1beta2/authpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
)

const (
AuthPolicyBackReferenceAnnotationName = "kuadrant.io/authpolicies"
AuthPolicyDirectReferenceAnnotationName = "kuadrant.io/authpolicy"
)

type AuthSchemeSpec struct {
// Authentication configs.
// At least one config MUST evaluate to a valid identity object for the auth request to be successful.
Expand Down Expand Up @@ -286,11 +291,11 @@ func (ap *AuthPolicy) Kind() string {
}

func (ap *AuthPolicy) BackReferenceAnnotationName() string {
return "kuadrant.io/authpolicies"
return AuthPolicyBackReferenceAnnotationName
}

func (ap *AuthPolicy) DirectReferenceAnnotationName() string {
return "kuadrant.io/authpolicy"
return AuthPolicyDirectReferenceAnnotationName
}

//+kubebuilder:object:root=true
Expand Down
7 changes: 5 additions & 2 deletions api/v1beta2/ratelimitpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const (
IncludeOperator WhenConditionOperator = "incl"
ExcludeOperator WhenConditionOperator = "excl"
MatchesOperator WhenConditionOperator = "matches"

RateLimitPolicyBackReferenceAnnotationName = "kuadrant.io/ratelimitpolicies"
RateLimitPolicyDirectReferenceAnnotationName = "kuadrant.io/ratelimitpolicy"
)

// +kubebuilder:validation:Enum:=second;minute;hour;day
Expand Down Expand Up @@ -250,11 +253,11 @@ func (r *RateLimitPolicy) Kind() string {
}

func (r *RateLimitPolicy) BackReferenceAnnotationName() string {
return "kuadrant.io/ratelimitpolicies"
return RateLimitPolicyBackReferenceAnnotationName
}

func (r *RateLimitPolicy) DirectReferenceAnnotationName() string {
return "kuadrant.io/ratelimitpolicy"
return RateLimitPolicyDirectReferenceAnnotationName
}

func init() {
Expand Down
13 changes: 6 additions & 7 deletions controllers/authpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"

"github.com/go-logr/logr"
authorinoapi "github.com/kuadrant/authorino/api/v1beta2"
apierrors "k8s.io/apimachinery/pkg/api/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -13,11 +14,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"

authorinoapi "github.com/kuadrant/authorino/api/v1beta2"

api "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/kuadrant/kuadrant-operator/pkg/library/mappers"
reconcilers2 "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
reconcilerutils "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
"github.com/kuadrant/kuadrant-operator/pkg/reconcilers"
)
Expand All @@ -27,7 +26,7 @@ const authPolicyFinalizer = "authpolicy.kuadrant.io/finalizer"
// AuthPolicyReconciler reconciles a AuthPolicy object
type AuthPolicyReconciler struct {
*reconcilers.BaseReconciler
TargetRefReconciler reconcilers2.TargetRefReconciler
TargetRefReconciler reconcilerutils.TargetRefReconciler
// OverriddenPolicyMap tracks the overridden policies to report their status.
OverriddenPolicyMap *utils.OverriddenPolicyMap
}
Expand Down Expand Up @@ -65,7 +64,7 @@ func (r *AuthPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl.Requ
markedForDeletion := ap.GetDeletionTimestamp() != nil

// fetch the target network object
targetNetworkObject, err := reconcilers2.FetchTargetRefObject(ctx, r.Client(), ap.GetTargetRef(), ap.Namespace)
targetNetworkObject, err := reconcilerutils.FetchTargetRefObject(ctx, r.Client(), ap.GetTargetRef(), ap.Namespace)
if err != nil {
if !markedForDeletion {
if apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -156,7 +155,7 @@ func (r *AuthPolicyReconciler) reconcileResources(ctx context.Context, ap *api.A
}

// reconcile based on gateway diffs
gatewayDiffObj, err := reconcilers2.ComputeGatewayDiffs(ctx, r.Client(), ap, targetNetworkObject)
gatewayDiffObj, err := reconcilerutils.ComputeGatewayDiffs(ctx, r.Client(), ap, targetNetworkObject)
if err != nil {
return err
}
Expand All @@ -180,7 +179,7 @@ func (r *AuthPolicyReconciler) reconcileResources(ctx context.Context, ap *api.A

func (r *AuthPolicyReconciler) deleteResources(ctx context.Context, ap *api.AuthPolicy, targetNetworkObject client.Object) error {
// delete based on gateway diffs
gatewayDiffObj, err := reconcilers2.ComputeGatewayDiffs(ctx, r.Client(), ap, targetNetworkObject)
gatewayDiffObj, err := reconcilerutils.ComputeGatewayDiffs(ctx, r.Client(), ap, targetNetworkObject)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions controllers/ratelimitpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/kuadrant/kuadrant-operator/pkg/library/mappers"
reconcilers2 "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
reconcilerutils "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
"github.com/kuadrant/kuadrant-operator/pkg/reconcilers"
)
Expand All @@ -41,7 +41,7 @@ const rateLimitPolicyFinalizer = "ratelimitpolicy.kuadrant.io/finalizer"
// RateLimitPolicyReconciler reconciles a RateLimitPolicy object
type RateLimitPolicyReconciler struct {
*reconcilers.BaseReconciler
TargetRefReconciler reconcilers2.TargetRefReconciler
TargetRefReconciler reconcilerutils.TargetRefReconciler
}

//+kubebuilder:rbac:groups=kuadrant.io,resources=ratelimitpolicies,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -88,7 +88,7 @@ func (r *RateLimitPolicyReconciler) Reconcile(eventCtx context.Context, req ctrl
markedForDeletion := rlp.GetDeletionTimestamp() != nil

// fetch the target network object
targetNetworkObject, err := reconcilers2.FetchTargetRefObject(ctx, r.Client(), rlp.GetTargetRef(), rlp.Namespace)
targetNetworkObject, err := reconcilerutils.FetchTargetRefObject(ctx, r.Client(), rlp.GetTargetRef(), rlp.Namespace)
if err != nil {
if !markedForDeletion {
if apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -172,7 +172,7 @@ func (r *RateLimitPolicyReconciler) reconcileResources(ctx context.Context, rlp
}

// reconcile based on gateway diffs
gatewayDiffObj, err := reconcilers2.ComputeGatewayDiffs(ctx, r.Client(), rlp, targetNetworkObject)
gatewayDiffObj, err := reconcilerutils.ComputeGatewayDiffs(ctx, r.Client(), rlp, targetNetworkObject)
if err != nil {
return err
}
Expand All @@ -196,7 +196,7 @@ func (r *RateLimitPolicyReconciler) reconcileResources(ctx context.Context, rlp

func (r *RateLimitPolicyReconciler) deleteResources(ctx context.Context, rlp *kuadrantv1beta2.RateLimitPolicy, targetNetworkObject client.Object) error {
// delete based on gateway diffs
gatewayDiffObj, err := reconcilers2.ComputeGatewayDiffs(ctx, r.Client(), rlp, targetNetworkObject)
gatewayDiffObj, err := reconcilerutils.ComputeGatewayDiffs(ctx, r.Client(), rlp, targetNetworkObject)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (

kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
reconcilers2 "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
reconcilerutils "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
"github.com/kuadrant/kuadrant-operator/pkg/log"
"github.com/kuadrant/kuadrant-operator/pkg/reconcilers"
Expand Down Expand Up @@ -131,7 +131,7 @@ var _ = BeforeSuite(func() {

err = (&AuthPolicyReconciler{
BaseReconciler: authPolicyBaseReconciler,
TargetRefReconciler: reconcilers2.TargetRefReconciler{Client: mgr.GetClient()},
TargetRefReconciler: reconcilerutils.TargetRefReconciler{Client: mgr.GetClient()},
OverriddenPolicyMap: utils.NewOverriddenPolicyMap(),
}).SetupWithManager(mgr)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -144,7 +144,7 @@ var _ = BeforeSuite(func() {

err = (&RateLimitPolicyReconciler{
BaseReconciler: rateLimitPolicyBaseReconciler,
TargetRefReconciler: reconcilers2.TargetRefReconciler{Client: mgr.GetClient()},
TargetRefReconciler: reconcilerutils.TargetRefReconciler{Client: mgr.GetClient()},
}).SetupWithManager(mgr)

Expect(err).NotTo(HaveOccurred())
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (
kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
kuadrantv1beta2 "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/kuadrant/kuadrant-operator/controllers"
reconcilers2 "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
reconcilerutils "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
"github.com/kuadrant/kuadrant-operator/pkg/log"
"github.com/kuadrant/kuadrant-operator/pkg/reconcilers"
Expand Down Expand Up @@ -151,7 +151,7 @@ func main() {
)

if err = (&controllers.RateLimitPolicyReconciler{
TargetRefReconciler: reconcilers2.TargetRefReconciler{Client: mgr.GetClient()},
TargetRefReconciler: reconcilerutils.TargetRefReconciler{Client: mgr.GetClient()},
BaseReconciler: rateLimitPolicyBaseReconciler,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "RateLimitPolicy")
Expand All @@ -165,7 +165,7 @@ func main() {
)

if err = (&controllers.AuthPolicyReconciler{
TargetRefReconciler: reconcilers2.TargetRefReconciler{Client: mgr.GetClient()},
TargetRefReconciler: reconcilerutils.TargetRefReconciler{Client: mgr.GetClient()},
BaseReconciler: authPolicyBaseReconciler,
OverriddenPolicyMap: utils.NewOverriddenPolicyMap(),
}).SetupWithManager(mgr); err != nil {
Expand Down

0 comments on commit 15753fd

Please sign in to comment.