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 Jan 17, 2024
1 parent 61d173c commit e35926c
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 27 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 @@ -24,7 +24,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
14 changes: 7 additions & 7 deletions controllers/authpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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 @@ -85,7 +85,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 @@ -154,7 +154,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 @@ -252,7 +252,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 @@ -314,7 +314,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 @@ -1185,7 +1185,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 @@ -1262,7 +1262,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 @@ -48,7 +48,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 @@ -660,7 +660,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 @@ -718,7 +718,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
5 changes: 3 additions & 2 deletions pkg/common/apimachinery_status_conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"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 @@ -147,7 +148,7 @@ func TestAcceptedCondition(t *testing.T) {
args: args{
policy: &utils.FakePolicy{},
err: utils.NewErrTargetNotFound("FakePolicy", gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-target-ref",
}, errors.NewNotFound(schema.GroupResource{}, "my-target-ref")),
Expand All @@ -164,7 +165,7 @@ func TestAcceptedCondition(t *testing.T) {
args: args{
policy: &utils.FakePolicy{},
err: utils.NewErrTargetNotFound("FakePolicy", gatewayapiv1alpha2.PolicyTargetReference{
Group: "gateway.networking.k8s.io",
Group: gatewayapiv1.GroupName,
Kind: "HTTPRoute",
Name: "my-target-ref",
}, fmt.Errorf("deletion err")),
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
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")

Check warning on line 29 in pkg/library/utils/gatewayapi_utils.go

View check run for this annotation

Codecov / codecov/patch

pkg/library/utils/gatewayapi_utils.go#L29

Added line #L29 was not covered by tests
}

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) {

Check warning on line 322 in pkg/library/utils/gatewayapi_utils.go

View check run for this annotation

Codecov / codecov/patch

pkg/library/utils/gatewayapi_utils.go#L322

Added line #L322 was not covered by tests
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 e35926c

Please sign in to comment.