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 2, 2024
1 parent c3a2d34 commit 351be0d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
9 changes: 7 additions & 2 deletions api/v1beta2/authpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
"github.com/kuadrant/kuadrant-operator/pkg/common"
)

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

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

View check run for this annotation

Codecov / codecov/patch

api/v1beta2/authpolicy_types.go#L293-L294

Added lines #L293 - L294 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

api/v1beta2/authpolicy_types.go#L297-L298

Added lines #L297 - L298 were not covered by tests
}

//+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 @@ -249,11 +252,11 @@ func (r *RateLimitPolicy) Kind() string {
}

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

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

View check run for this annotation

Codecov / codecov/patch

api/v1beta2/ratelimitpolicy_types.go#L254-L255

Added lines #L254 - L255 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

api/v1beta2/ratelimitpolicy_types.go#L258-L259

Added lines #L258 - L259 were not covered by tests
}

func init() {
Expand Down
10 changes: 5 additions & 5 deletions controllers/authpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
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 @@ -26,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
}

//+kubebuilder:rbac:groups=kuadrant.io,resources=authpolicies,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -62,7 +62,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 @@ -153,7 +153,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 @@ -177,7 +177,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 @@ -22,7 +22,7 @@ import (

"github.com/go-logr/logr"
"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"
apierrors "k8s.io/apimachinery/pkg/api/errors"
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 @@ -25,7 +25,7 @@ import (

authorinoopapi "github.com/kuadrant/authorino-operator/api/v1beta1"
authorinoapi "github.com/kuadrant/authorino/api/v1beta2"
reconcilers2 "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
reconcilerutils "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
limitadorv1alpha1 "github.com/kuadrant/limitador-operator/api/v1alpha1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -130,7 +130,7 @@ var _ = BeforeSuite(func() {

err = (&AuthPolicyReconciler{
BaseReconciler: authPolicyBaseReconciler,
TargetRefReconciler: reconcilers2.TargetRefReconciler{Client: mgr.GetClient()},
TargetRefReconciler: reconcilerutils.TargetRefReconciler{Client: mgr.GetClient()},
}).SetupWithManager(mgr)
Expect(err).NotTo(HaveOccurred())

Expand All @@ -142,7 +142,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 @@ -22,7 +22,7 @@ import (
"os"
"runtime"

reconcilers2 "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
reconcilerutils "github.com/kuadrant/kuadrant-operator/pkg/library/reconcilers"
"k8s.io/utils/env"
"sigs.k8s.io/controller-runtime/pkg/webhook"

Expand Down Expand Up @@ -154,7 +154,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 @@ -168,7 +168,7 @@ func main() {
)

if err = (&controllers.AuthPolicyReconciler{
TargetRefReconciler: reconcilers2.TargetRefReconciler{Client: mgr.GetClient()},
TargetRefReconciler: reconcilerutils.TargetRefReconciler{Client: mgr.GetClient()},
BaseReconciler: authPolicyBaseReconciler,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "AuthPolicy")
Expand Down

0 comments on commit 351be0d

Please sign in to comment.