diff --git a/api/v1beta2/authpolicy_types_test.go b/api/v1beta2/authpolicy_types_test.go index 2f4153acd..ef3d0d773 100644 --- a/api/v1beta2/authpolicy_types_test.go +++ b/api/v1beta2/authpolicy_types_test.go @@ -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", }, @@ -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", }, @@ -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")), diff --git a/api/v1beta2/ratelimitpolicy_types_test.go b/api/v1beta2/ratelimitpolicy_types_test.go index 321ec79f8..a2eba1eda 100644 --- a/api/v1beta2/ratelimitpolicy_types_test.go +++ b/api/v1beta2/ratelimitpolicy_types_test.go @@ -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", }, diff --git a/controllers/authpolicy_controller_test.go b/controllers/authpolicy_controller_test.go index 43de2e34b..eb34149da 100644 --- a/controllers/authpolicy_controller_test.go +++ b/controllers/authpolicy_controller_test.go @@ -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" @@ -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" @@ -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)), @@ -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" @@ -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) }) @@ -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 }) @@ -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 }) @@ -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", }, @@ -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", }, diff --git a/controllers/httprouteparentrefs_eventmapper.go b/controllers/httprouteparentrefs_eventmapper.go index 1161a1a1c..e79441d3c 100644 --- a/controllers/httprouteparentrefs_eventmapper.go +++ b/controllers/httprouteparentrefs_eventmapper.go @@ -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 diff --git a/controllers/limitador_cluster_envoyfilter_controller_test.go b/controllers/limitador_cluster_envoyfilter_controller_test.go index 8bec8cd93..a932aad82 100644 --- a/controllers/limitador_cluster_envoyfilter_controller_test.go +++ b/controllers/limitador_cluster_envoyfilter_controller_test.go @@ -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), }, diff --git a/controllers/ratelimitpolicy_controller_test.go b/controllers/ratelimitpolicy_controller_test.go index 018d5c1f5..41c954f87 100644 --- a/controllers/ratelimitpolicy_controller_test.go +++ b/controllers/ratelimitpolicy_controller_test.go @@ -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), }, @@ -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", }, @@ -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", }, diff --git a/pkg/library/README.md b/pkg/library/README.md index f27929865..167a7145d 100644 --- a/pkg/library/README.md +++ b/pkg/library/README.md @@ -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 \ No newline at end of file +externalised to the https://github.com/Kuadrant/gateway-api-machinery diff --git a/pkg/library/reconcilers/fetcher_test.go b/pkg/library/reconcilers/fetcher_test.go index 09541a92e..4a6be5d2e 100644 --- a/pkg/library/reconcilers/fetcher_test.go +++ b/pkg/library/reconcilers/fetcher_test.go @@ -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), } diff --git a/pkg/library/utils/apimachinery_status_conditions_test.go b/pkg/library/utils/apimachinery_status_conditions_test.go index 150037db3..974480023 100644 --- a/pkg/library/utils/apimachinery_status_conditions_test.go +++ b/pkg/library/utils/apimachinery_status_conditions_test.go @@ -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" ) @@ -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")), @@ -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")), diff --git a/pkg/library/utils/gatewayapi_utils.go b/pkg/library/utils/gatewayapi_utils.go index 8cae74a82..292e6ffc3 100644 --- a/pkg/library/utils/gatewayapi_utils.go +++ b/pkg/library/utils/gatewayapi_utils.go @@ -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 { @@ -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{} diff --git a/pkg/library/utils/gatewayapi_utils_test.go b/pkg/library/utils/gatewayapi_utils_test.go index 675b36a6d..652973515 100644 --- a/pkg/library/utils/gatewayapi_utils_test.go +++ b/pkg/library/utils/gatewayapi_utils_test.go @@ -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")), @@ -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", }, @@ -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", },