Skip to content

Commit

Permalink
refactor: use gatewayapiv1.GroupName
Browse files Browse the repository at this point in the history
  • Loading branch information
KevFan committed Feb 20, 2024
1 parent 0a4ee26 commit 0d4005a
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions api/v1beta2/authpolicy_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestAuthPolicyTargetKey(t *testing.T) {
},
Spec: AuthPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-route",
},
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestAuthPolicyGetRulesHostnames(t *testing.T) {
},
Spec: AuthPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-route",
},
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestAuthPolicyValidate(t *testing.T) {
},
Spec: AuthPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-route",
Namespace: ptr.To(gatewayapiv1.Namespace("other-namespace")),
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta2/ratelimitpolicy_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func testBuildBasicRLP(name string, kind gatewayapiv1.Kind) *RateLimitPolicy {
},
Spec: RateLimitPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: kind,
Name: "some-name",
},
Expand Down
19 changes: 9 additions & 10 deletions controllers/authpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

authorinoopapi "github.com/kuadrant/authorino-operator/api/v1beta1"
authorinoapi "github.com/kuadrant/authorino/api/v1beta2"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
secv1beta1resources "istio.io/client-go/pkg/apis/security/v1beta1"
Expand All @@ -24,9 +26,6 @@ import (
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

authorinoopapi "github.com/kuadrant/authorino-operator/api/v1beta1"
authorinoapi "github.com/kuadrant/authorino/api/v1beta2"

kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
api "github.com/kuadrant/kuadrant-operator/api/v1beta2"
"github.com/kuadrant/kuadrant-operator/pkg/library/utils"
Expand Down Expand Up @@ -62,7 +61,7 @@ var _ = Describe("AuthPolicy controller", func() {
},
Spec: api.AuthPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: testHTTPRouteName,
Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)),
Expand Down Expand Up @@ -90,7 +89,7 @@ var _ = Describe("AuthPolicy controller", func() {
It("Attaches policy to the Gateway", func() {
policy := policyFactory(func(policy *api.AuthPolicy) {
policy.Name = "gw-auth"
policy.Spec.TargetRef.Group = "gateway.networking.k8s.io"
policy.Spec.TargetRef.Group = gatewayapiv1.GroupName
policy.Spec.TargetRef.Kind = "Gateway"
policy.Spec.TargetRef.Name = testGatewayName
policy.Spec.AuthScheme.Authentication["apiKey"].ApiKey.Selector.MatchLabels["admin"] = "yes"
Expand Down Expand Up @@ -160,7 +159,7 @@ var _ = Describe("AuthPolicy controller", func() {

policy := policyFactory(func(policy *api.AuthPolicy) {
policy.Name = "gw-auth"
policy.Spec.TargetRef.Group = "gateway.networking.k8s.io"
policy.Spec.TargetRef.Group = gatewayapiv1.GroupName
policy.Spec.TargetRef.Kind = "Gateway"
policy.Spec.TargetRef.Name = gatewayapiv1.ObjectName(gatewayName)
})
Expand Down Expand Up @@ -261,7 +260,7 @@ var _ = Describe("AuthPolicy controller", func() {
// attach policy to the gatewaay
gwPolicy := policyFactory(func(policy *api.AuthPolicy) {
policy.Name = "gw-auth"
policy.Spec.TargetRef.Group = "gateway.networking.k8s.io"
policy.Spec.TargetRef.Group = gatewayapiv1.GroupName
policy.Spec.TargetRef.Kind = "Gateway"
policy.Spec.TargetRef.Name = testGatewayName
})
Expand Down Expand Up @@ -1217,7 +1216,7 @@ var _ = Describe("AuthPolicy controller", func() {
// attach policy to the gatewaay
gwPolicy := policyFactory(func(policy *api.AuthPolicy) {
policy.Name = "gw-auth"
policy.Spec.TargetRef.Group = "gateway.networking.k8s.io"
policy.Spec.TargetRef.Group = gatewayapiv1.GroupName
policy.Spec.TargetRef.Kind = "Gateway"
policy.Spec.TargetRef.Name = testGatewayName
})
Expand Down Expand Up @@ -1278,7 +1277,7 @@ var _ = Describe("AuthPolicy CEL Validations", func() {
},
Spec: api.AuthPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-target",
},
Expand Down Expand Up @@ -1355,7 +1354,7 @@ var _ = Describe("AuthPolicy CEL Validations", func() {
},
Spec: api.AuthPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "Gateway",
Name: "my-gw",
},
Expand Down
2 changes: 1 addition & 1 deletion controllers/httprouteparentrefs_eventmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (m *HTTPRouteParentRefsEventMapper) mapToPolicyRequest(obj client.Object, p

for _, parentRef := range route.Spec.ParentRefs {
// skips if parentRef is not a Gateway
if (parentRef.Group != nil && *parentRef.Group != "gateway.networking.k8s.io") || (parentRef.Kind != nil && *parentRef.Kind != "Gateway") {
if (parentRef.Group != nil && *parentRef.Group != gatewayapiv1.GroupName) || (parentRef.Kind != nil && *parentRef.Kind != "Gateway") {
continue
}
// list policies in the same namespace as the parent gateway of the route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var _ = Describe("Limitador Cluster EnvoyFilter controller", func() {
},
Spec: kuadrantv1beta2.RateLimitPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: gatewayapiv1.Group("gateway.networking.k8s.io"),
Group: gatewayapiv1.GroupName,
Kind: "Gateway",
Name: gatewayapiv1.ObjectName(gwName),
},
Expand Down
6 changes: 3 additions & 3 deletions controllers/ratelimitpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("RateLimitPolicy controller", func() {
},
Spec: kuadrantv1beta2.RateLimitPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: gatewayapiv1.Group("gateway.networking.k8s.io"),
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: gatewayapiv1.ObjectName(routeName),
},
Expand Down Expand Up @@ -661,7 +661,7 @@ var _ = Describe("RateLimitPolicy CEL Validations", func() {
},
Spec: kuadrantv1beta2.RateLimitPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-target",
},
Expand Down Expand Up @@ -719,7 +719,7 @@ var _ = Describe("RateLimitPolicy CEL Validations", func() {
},
Spec: kuadrantv1beta2.RateLimitPolicySpec{
TargetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "Gateway",
Name: "my-gw",
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/library/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Packages in this directory contains only contain common / useful functionality for policy controllers that will be
externalised to the https://github.com/Kuadrant/gateway-api-machinery
externalised to the https://github.com/Kuadrant/gateway-api-machinery
4 changes: 2 additions & 2 deletions pkg/library/reconcilers/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ func TestFetchTargetRefObject(t *testing.T) {
}

routeTargetRef := gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: gatewayapiv1.ObjectName(routeName),
}

gatewayTargetRef := gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "Gateway",
Name: gatewayapiv1.ObjectName(gatewayName),
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/library/utils/apimachinery_status_conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
apiErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gatewayapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)

Expand Down Expand Up @@ -146,7 +147,7 @@ func TestAcceptedCondition(t *testing.T) {
args: args{
policy: &FakePolicy{},
err: NewErrTargetNotFound("FakePolicy", gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-target-ref",
}, apiErrors.NewNotFound(schema.GroupResource{}, "my-target-ref")),
Expand All @@ -163,7 +164,7 @@ func TestAcceptedCondition(t *testing.T) {
args: args{
policy: &FakePolicy{},
err: NewErrTargetNotFound("FakePolicy", gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-target-ref",
}, errors.New("deletion err")),
Expand Down
6 changes: 3 additions & 3 deletions pkg/library/utils/gatewayapi_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ type HTTPRouteRule struct {
}

func IsTargetRefHTTPRoute(targetRef gatewayapiv1alpha2.PolicyTargetReference) bool {
return targetRef.Group == ("gateway.networking.k8s.io") && targetRef.Kind == ("HTTPRoute")
return targetRef.Group == (gatewayapiv1.GroupName) && targetRef.Kind == ("HTTPRoute")
}

func IsTargetRefGateway(targetRef gatewayapiv1alpha2.PolicyTargetReference) bool {
return targetRef.Group == ("gateway.networking.k8s.io") && targetRef.Kind == ("Gateway")
return targetRef.Group == (gatewayapiv1.GroupName) && targetRef.Kind == ("Gateway")
}

func RouteHTTPMethodToRuleMethod(httpMethod *gatewayapiv1.HTTPMethod) []string {
Expand Down Expand Up @@ -319,7 +319,7 @@ func HostnamesFromHTTPRoute(ctx context.Context, route *gatewayapiv1.HTTPRoute,
hosts := []string{}

for _, ref := range route.Spec.ParentRefs {
if (ref.Kind != nil && *ref.Kind != "Gateway") || (ref.Group != nil && *ref.Group != "gateway.networking.k8s.io") {
if (ref.Kind != nil && *ref.Kind != "Gateway") || (ref.Group != nil && *ref.Group != gatewayapiv1.GroupName) {
continue
}
gw := &gatewayapiv1.Gateway{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/library/utils/gatewayapi_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ func TestGetKuadrantNamespaceFromPolicyTargetRef(t *testing.T) {
},
},
targetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-httproute",
Namespace: ptr.To[gatewayapiv1.Namespace](gatewayapiv1.Namespace("my-ns")),
Expand Down Expand Up @@ -860,7 +860,7 @@ func TestGetKuadrantNamespaceFromPolicyTargetRef(t *testing.T) {
},
},
targetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-httproute",
},
Expand Down Expand Up @@ -901,7 +901,7 @@ func TestGetKuadrantNamespaceFromPolicyTargetRef(t *testing.T) {
},
},
targetRef: gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-httproute",
},
Expand Down

0 comments on commit 0d4005a

Please sign in to comment.