From 8bfe794b67eff7ef95bea4ab1b64a972db5751ae Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Fri, 29 Mar 2024 15:23:15 +0800 Subject: [PATCH] fix: Fix Gateway API v1 package references --- api/v1alpha1/zz_generated.deepcopy.go | 20 +- internal/cmd/egctl/translate.go | 31 ++- internal/envoygateway/scheme.go | 2 +- internal/gatewayapi/contexts.go | 85 +++--- internal/gatewayapi/contexts_test.go | 29 +- internal/gatewayapi/filters.go | 145 +++++----- internal/gatewayapi/helpers.go | 63 ++--- internal/gatewayapi/helpers_test.go | 33 +-- internal/gatewayapi/listener.go | 5 +- internal/gatewayapi/route.go | 131 ++++----- internal/gatewayapi/validate.go | 80 +++--- internal/gatewayapi/zz_generated.deepcopy.go | 11 +- internal/provider/kubernetes/controller.go | 40 +-- .../provider/kubernetes/controller_test.go | 129 ++++----- internal/provider/kubernetes/helpers.go | 41 +-- internal/provider/kubernetes/helpers_test.go | 201 +++++++------- internal/provider/kubernetes/indexers.go | 20 +- internal/provider/kubernetes/routes.go | 21 +- internal/provider/kubernetes/routes_test.go | 259 +++++++++--------- internal/status/conditions.go | 9 +- internal/status/gateway.go | 7 +- 21 files changed, 688 insertions(+), 674 deletions(-) diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 4b40fd1088d2..c98edb892ae2 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -536,7 +536,7 @@ func (in *ClientValidationContext) DeepCopyInto(out *ClientValidationContext) { *out = *in if in.CACertificateRefs != nil { in, out := &in.CACertificateRefs, &out.CACertificateRefs - *out = make([]v1.SecretObjectReference, len(*in)) + *out = make([]v1beta1.SecretObjectReference, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -598,7 +598,7 @@ func (in *ConnectionLimit) DeepCopyInto(out *ConnectionLimit) { *out = *in if in.CloseDelay != nil { in, out := &in.CloseDelay, &out.CloseDelay - *out = new(v1.Duration) + *out = new(v1beta1.Duration) **out = **in } } @@ -1846,12 +1846,12 @@ func (in *HTTPClientTimeout) DeepCopyInto(out *HTTPClientTimeout) { *out = *in if in.RequestReceivedTimeout != nil { in, out := &in.RequestReceivedTimeout, &out.RequestReceivedTimeout - *out = new(v1.Duration) + *out = new(v1beta1.Duration) **out = **in } if in.IdleTimeout != nil { in, out := &in.IdleTimeout, &out.IdleTimeout - *out = new(v1.Duration) + *out = new(v1beta1.Duration) **out = **in } } @@ -1897,12 +1897,12 @@ func (in *HTTPTimeout) DeepCopyInto(out *HTTPTimeout) { *out = *in if in.ConnectionIdleTimeout != nil { in, out := &in.ConnectionIdleTimeout, &out.ConnectionIdleTimeout - *out = new(v1.Duration) + *out = new(v1beta1.Duration) **out = **in } if in.MaxConnectionDuration != nil { in, out := &in.MaxConnectionDuration, &out.MaxConnectionDuration - *out = new(v1.Duration) + *out = new(v1beta1.Duration) **out = **in } } @@ -3193,7 +3193,7 @@ func (in *RedisTLSSettings) DeepCopyInto(out *RedisTLSSettings) { *out = *in if in.CertificateRef != nil { in, out := &in.CertificateRef, &out.CertificateRef - *out = new(v1.SecretObjectReference) + *out = new(v1beta1.SecretObjectReference) (*in).DeepCopyInto(*out) } } @@ -3540,12 +3540,12 @@ func (in *TCPKeepalive) DeepCopyInto(out *TCPKeepalive) { } if in.IdleTime != nil { in, out := &in.IdleTime, &out.IdleTime - *out = new(v1.Duration) + *out = new(v1beta1.Duration) **out = **in } if in.Interval != nil { in, out := &in.Interval, &out.Interval - *out = new(v1.Duration) + *out = new(v1beta1.Duration) **out = **in } } @@ -3565,7 +3565,7 @@ func (in *TCPTimeout) DeepCopyInto(out *TCPTimeout) { *out = *in if in.ConnectTimeout != nil { in, out := &in.ConnectTimeout, &out.ConnectTimeout - *out = new(v1.Duration) + *out = new(v1beta1.Duration) **out = **in } } diff --git a/internal/cmd/egctl/translate.go b/internal/cmd/egctl/translate.go index 4140aea02647..b9b379e3e8e5 100644 --- a/internal/cmd/egctl/translate.go +++ b/internal/cmd/egctl/translate.go @@ -28,8 +28,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/util/sets" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/api/v1alpha1/validation" @@ -277,7 +278,7 @@ func translateGatewayAPIToIR(resources *gatewayapi.Resources) (*gatewayapi.Trans t := &gatewayapi.Translator{ GatewayControllerName: egv1a1.GatewayControllerName, - GatewayClassName: gwapiv1.ObjectName(resources.GatewayClass.Name), + GatewayClassName: gwapiv1beta1.ObjectName(resources.GatewayClass.Name), GlobalRateLimitEnabled: true, EndpointRoutingDisabled: true, EnvoyPatchPolicyEnabled: true, @@ -304,7 +305,7 @@ func translateGatewayAPIToGatewayAPI(resources *gatewayapi.Resources) (gatewayap // Translate from Gateway API to Xds IR gTranslator := &gatewayapi.Translator{ GatewayControllerName: egv1a1.GatewayControllerName, - GatewayClassName: gwapiv1.ObjectName(resources.GatewayClass.Name), + GatewayClassName: gwapiv1beta1.ObjectName(resources.GatewayClass.Name), GlobalRateLimitEnabled: true, EndpointRoutingDisabled: true, EnvoyPatchPolicyEnabled: true, @@ -336,7 +337,7 @@ func translateGatewayAPIToXds(dnsDomain string, resourceType string, resources * // Translate from Gateway API to Xds IR gTranslator := &gatewayapi.Translator{ GatewayControllerName: egv1a1.GatewayControllerName, - GatewayClassName: gwapiv1.ObjectName(resources.GatewayClass.Name), + GatewayClassName: gwapiv1beta1.ObjectName(resources.GatewayClass.Name), GlobalRateLimitEnabled: true, EndpointRoutingDisabled: true, EnvoyPatchPolicyEnabled: true, @@ -542,9 +543,9 @@ func addMissingServices(requiredServices map[string]*v1.Service, obj interface{} var objNamespace string protocol := v1.Protocol(gatewayapi.TCPProtocol) - refs := []gwapiv1.BackendRef{} + refs := []gwapiv1beta1.BackendRef{} switch route := obj.(type) { - case *gwapiv1.HTTPRoute: + case *gwapiv1beta1.HTTPRoute: objNamespace = route.Namespace for _, rule := range route.Spec.Rules { for _, httpBakcendRef := range rule.BackendRefs { @@ -681,22 +682,22 @@ func kubernetesYAMLToResources(str string, addMissingResources bool) (*gatewayap resources.EnvoyProxy = envoyProxy case gatewayapi.KindGatewayClass: typedSpec := spec.Interface() - gatewayClass := &gwapiv1.GatewayClass{ + gatewayClass := &gwapiv1beta1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, }, - Spec: typedSpec.(gwapiv1.GatewayClassSpec), + Spec: typedSpec.(gwapiv1beta1.GatewayClassSpec), } resources.GatewayClass = gatewayClass case gatewayapi.KindGateway: typedSpec := spec.Interface() - gateway := &gwapiv1.Gateway{ + gateway := &gwapiv1beta1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: namespace, }, - Spec: typedSpec.(gwapiv1.GatewaySpec), + Spec: typedSpec.(gwapiv1beta1.GatewaySpec), } resources.Gateways = append(resources.Gateways, gateway) case gatewayapi.KindTCPRoute: @@ -740,7 +741,7 @@ func kubernetesYAMLToResources(str string, addMissingResources bool) (*gatewayap resources.TLSRoutes = append(resources.TLSRoutes, tlsRoute) case gatewayapi.KindHTTPRoute: typedSpec := spec.Interface() - httpRoute := &gwapiv1.HTTPRoute{ + httpRoute := &gwapiv1beta1.HTTPRoute{ TypeMeta: metav1.TypeMeta{ Kind: gatewayapi.KindHTTPRoute, }, @@ -748,7 +749,7 @@ func kubernetesYAMLToResources(str string, addMissingResources bool) (*gatewayap Name: name, Namespace: namespace, }, - Spec: typedSpec.(gwapiv1.HTTPRouteSpec), + Spec: typedSpec.(gwapiv1beta1.HTTPRouteSpec), } resources.HTTPRoutes = append(resources.HTTPRoutes, httpRoute) case gatewayapi.KindGRPCRoute: @@ -945,9 +946,9 @@ func addDefaultEnvoyProxy(resources *gatewayapi.Resources) error { }, } resources.EnvoyProxy = ep - ns := gwapiv1.Namespace(namespace) - resources.GatewayClass.Spec.ParametersRef = &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), + ns := gwapiv1beta1.Namespace(namespace) + resources.GatewayClass.Spec.ParametersRef = &gwapiv1beta1.ParametersReference{ + Group: gwapiv1beta1.Group(egv1a1.GroupVersion.Group), Kind: gatewayapi.KindEnvoyProxy, Name: defaultEnvoyProxyName, Namespace: &ns, diff --git a/internal/envoygateway/scheme.go b/internal/envoygateway/scheme.go index ad83d5d3fd18..911ae7083513 100644 --- a/internal/envoygateway/scheme.go +++ b/internal/envoygateway/scheme.go @@ -8,8 +8,8 @@ package envoygateway import ( "k8s.io/apimachinery/pkg/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" mcsapi "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" diff --git a/internal/gatewayapi/contexts.go b/internal/gatewayapi/contexts.go index 6b1a33e05e99..c60a57880bda 100644 --- a/internal/gatewayapi/contexts.go +++ b/internal/gatewayapi/contexts.go @@ -13,14 +13,15 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "sigs.k8s.io/controller-runtime/pkg/client" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" ) // GatewayContext wraps a Gateway and provides helper methods for // setting conditions, accessing Listeners, etc. type GatewayContext struct { - *gwapiv1.Gateway + *gwapiv1beta1.Gateway listeners []*ListenerContext } @@ -29,11 +30,11 @@ type GatewayContext struct { // ListenerContexts from the Gateway spec. func (g *GatewayContext) ResetListeners() { numListeners := len(g.Spec.Listeners) - g.Status.Listeners = make([]gwapiv1.ListenerStatus, numListeners) + g.Status.Listeners = make([]gwapiv1beta1.ListenerStatus, numListeners) g.listeners = make([]*ListenerContext, numListeners) for i := range g.Spec.Listeners { listener := &g.Spec.Listeners[i] - g.Status.Listeners[i] = gwapiv1.ListenerStatus{Name: listener.Name} + g.Status.Listeners[i] = gwapiv1beta1.ListenerStatus{Name: listener.Name} g.listeners[i] = &ListenerContext{ Listener: listener, gateway: g.Gateway, @@ -46,15 +47,15 @@ func (g *GatewayContext) ResetListeners() { // setting conditions and other status information on the associated // Gateway, etc. type ListenerContext struct { - *gwapiv1.Listener + *gwapiv1beta1.Listener - gateway *gwapiv1.Gateway + gateway *gwapiv1beta1.Gateway listenerStatusIdx int namespaceSelector labels.Selector tlsSecrets []*v1.Secret } -func (l *ListenerContext) SetCondition(conditionType gwapiv1.ListenerConditionType, status metav1.ConditionStatus, reason gwapiv1.ListenerConditionReason, message string) { +func (l *ListenerContext) SetCondition(conditionType gwapiv1beta1.ListenerConditionType, status metav1.ConditionStatus, reason gwapiv1beta1.ListenerConditionReason, message string) { cond := metav1.Condition{ Type: string(conditionType), Status: status, @@ -86,7 +87,7 @@ func (l *ListenerContext) SetCondition(conditionType gwapiv1.ListenerConditionTy } } -func (l *ListenerContext) SetSupportedKinds(kinds ...gwapiv1.RouteGroupKind) { +func (l *ListenerContext) SetSupportedKinds(kinds ...gwapiv1beta1.RouteGroupKind) { l.gateway.Status.Listeners[l.listenerStatusIdx].SupportedKinds = kinds } @@ -98,7 +99,7 @@ func (l *ListenerContext) AttachedRoutes() int32 { return l.gateway.Status.Listeners[l.listenerStatusIdx].AttachedRoutes } -func (l *ListenerContext) AllowsKind(kind gwapiv1.RouteGroupKind) bool { +func (l *ListenerContext) AllowsKind(kind gwapiv1beta1.RouteGroupKind) bool { for _, allowed := range l.gateway.Status.Listeners[l.listenerStatusIdx].SupportedKinds { if GroupDerefOr(allowed.Group, "") == GroupDerefOr(kind.Group, "") && allowed.Kind == kind.Kind { @@ -162,9 +163,9 @@ type HTTPRouteContext struct { // GatewayControllerName is the name of the Gateway API controller. GatewayControllerName string - *gwapiv1.HTTPRoute + *gwapiv1beta1.HTTPRoute - ParentRefs map[gwapiv1.ParentReference]*RouteParentContext + ParentRefs map[gwapiv1beta1.ParentReference]*RouteParentContext } // GRPCRouteContext wraps a GRPCRoute and provides helper methods for @@ -175,7 +176,7 @@ type GRPCRouteContext struct { *v1alpha2.GRPCRoute - ParentRefs map[gwapiv1.ParentReference]*RouteParentContext + ParentRefs map[gwapiv1beta1.ParentReference]*RouteParentContext } // TLSRouteContext wraps a TLSRoute and provides helper methods for @@ -186,7 +187,7 @@ type TLSRouteContext struct { *v1alpha2.TLSRoute - ParentRefs map[gwapiv1.ParentReference]*RouteParentContext + ParentRefs map[gwapiv1beta1.ParentReference]*RouteParentContext } // UDPRouteContext wraps a UDPRoute and provides helper methods for @@ -197,7 +198,7 @@ type UDPRouteContext struct { *v1alpha2.UDPRoute - ParentRefs map[gwapiv1.ParentReference]*RouteParentContext + ParentRefs map[gwapiv1beta1.ParentReference]*RouteParentContext } // TCPRouteContext wraps a TCPRoute and provides helper methods for @@ -208,18 +209,18 @@ type TCPRouteContext struct { *v1alpha2.TCPRoute - ParentRefs map[gwapiv1.ParentReference]*RouteParentContext + ParentRefs map[gwapiv1beta1.ParentReference]*RouteParentContext } // GetRouteType returns the Kind of the Route object, HTTPRoute, // TLSRoute, TCPRoute, UDPRoute etc. -func GetRouteType(route RouteContext) gwapiv1.Kind { +func GetRouteType(route RouteContext) gwapiv1beta1.Kind { rv := reflect.ValueOf(route).Elem() - return gwapiv1.Kind(rv.FieldByName("Kind").String()) + return gwapiv1beta1.Kind(rv.FieldByName("Kind").String()) } -// TODO: [v1alpha2-gwapiv1] This should not be required once all Route -// objects being implemented are of type gwapiv1. +// TODO: [v1alpha2-gwapiv1beta1] This should not be required once all Route +// objects being implemented are of type gwapiv1beta1. // GetHostnames returns the hosts targeted by the Route object. func GetHostnames(route RouteContext) []string { rv := reflect.ValueOf(route).Elem() @@ -236,39 +237,39 @@ func GetHostnames(route RouteContext) []string { return hostnames } -// TODO: [v1alpha2-gwapiv1] This should not be required once all Route -// objects being implemented are of type gwapiv1. +// TODO: [v1alpha2-gwapiv1beta1] This should not be required once all Route +// objects being implemented are of type gwapiv1beta1. // GetParentReferences returns the ParentReference of the Route object. -func GetParentReferences(route RouteContext) []gwapiv1.ParentReference { +func GetParentReferences(route RouteContext) []gwapiv1beta1.ParentReference { rv := reflect.ValueOf(route).Elem() kind := rv.FieldByName("Kind").String() pr := rv.FieldByName("Spec").FieldByName("ParentRefs") if kind == KindHTTPRoute || kind == KindGRPCRoute { - return pr.Interface().([]gwapiv1.ParentReference) + return pr.Interface().([]gwapiv1beta1.ParentReference) } - parentReferences := make([]gwapiv1.ParentReference, pr.Len()) + parentReferences := make([]gwapiv1beta1.ParentReference, pr.Len()) for i := 0; i < len(parentReferences); i++ { - p := pr.Index(i).Interface().(gwapiv1.ParentReference) + p := pr.Index(i).Interface().(gwapiv1beta1.ParentReference) parentReferences[i] = UpgradeParentReference(p) } return parentReferences } // GetRouteStatus returns the RouteStatus object associated with the Route. -func GetRouteStatus(route RouteContext) *gwapiv1.RouteStatus { +func GetRouteStatus(route RouteContext) *gwapiv1beta1.RouteStatus { rv := reflect.ValueOf(route).Elem() - rs := rv.FieldByName("Status").FieldByName("RouteStatus").Interface().(gwapiv1.RouteStatus) + rs := rv.FieldByName("Status").FieldByName("RouteStatus").Interface().(gwapiv1beta1.RouteStatus) return &rs } // GetRouteParentContext returns RouteParentContext by using the Route // objects' ParentReference. -func GetRouteParentContext(route RouteContext, forParentRef gwapiv1.ParentReference) *RouteParentContext { +func GetRouteParentContext(route RouteContext, forParentRef gwapiv1beta1.ParentReference) *RouteParentContext { rv := reflect.ValueOf(route).Elem() pr := rv.FieldByName("ParentRefs") if pr.IsNil() { - mm := reflect.MakeMap(reflect.TypeOf(map[gwapiv1.ParentReference]*RouteParentContext{})) + mm := reflect.MakeMap(reflect.TypeOf(map[gwapiv1beta1.ParentReference]*RouteParentContext{})) pr.Set(mm) } @@ -282,10 +283,10 @@ func GetRouteParentContext(route RouteContext, forParentRef gwapiv1.ParentRefere isHTTPRoute = true } - var parentRef *gwapiv1.ParentReference + var parentRef *gwapiv1beta1.ParentReference specParentRefs := rv.FieldByName("Spec").FieldByName("ParentRefs") for i := 0; i < specParentRefs.Len(); i++ { - p := specParentRefs.Index(i).Interface().(gwapiv1.ParentReference) + p := specParentRefs.Index(i).Interface().(gwapiv1beta1.ParentReference) up := p if !isHTTPRoute { up = UpgradeParentReference(p) @@ -307,10 +308,10 @@ func GetRouteParentContext(route RouteContext, forParentRef gwapiv1.ParentRefere routeParentStatusIdx := -1 statusParents := rv.FieldByName("Status").FieldByName("Parents") for i := 0; i < statusParents.Len(); i++ { - p := statusParents.Index(i).FieldByName("ParentRef").Interface().(gwapiv1.ParentReference) + p := statusParents.Index(i).FieldByName("ParentRef").Interface().(gwapiv1beta1.ParentReference) if !isHTTPRoute { p = UpgradeParentReference(p) - defaultNamespace := gwapiv1.Namespace(metav1.NamespaceDefault) + defaultNamespace := gwapiv1beta1.Namespace(metav1.NamespaceDefault) if forParentRef.Namespace == nil { forParentRef.Namespace = &defaultNamespace } @@ -350,11 +351,11 @@ func GetRouteParentContext(route RouteContext, forParentRef gwapiv1.ParentRefere // setting conditions and other status information on the associated // HTTPRoute, TLSRoute etc. type RouteParentContext struct { - *gwapiv1.ParentReference + *gwapiv1beta1.ParentReference - // TODO: [v1alpha2-gwapiv1] This can probably be replaced with - // a single field pointing to *gwapiv1.RouteStatus. - HTTPRoute *gwapiv1.HTTPRoute + // TODO: [v1alpha2-gwapiv1beta1] This can probably be replaced with + // a single field pointing to *gwapiv1beta1.RouteStatus. + HTTPRoute *gwapiv1beta1.HTTPRoute GRPCRoute *v1alpha2.GRPCRoute TLSRoute *v1alpha2.TLSRoute TCPRoute *v1alpha2.TCPRoute @@ -368,7 +369,7 @@ func (r *RouteParentContext) SetListeners(listeners ...*ListenerContext) { r.listeners = append(r.listeners, listeners...) } -func (r *RouteParentContext) SetCondition(route RouteContext, conditionType gwapiv1.RouteConditionType, status metav1.ConditionStatus, reason gwapiv1.RouteConditionReason, message string) { +func (r *RouteParentContext) SetCondition(route RouteContext, conditionType gwapiv1beta1.RouteConditionType, status metav1.ConditionStatus, reason gwapiv1beta1.RouteConditionReason, message string) { cond := metav1.Condition{ Type: string(conditionType), Status: status, @@ -406,7 +407,7 @@ func (r *RouteParentContext) ResetConditions(route RouteContext) { routeStatus.Parents[r.routeParentStatusIdx].Conditions = make([]metav1.Condition, 0) } -func (r *RouteParentContext) HasCondition(route RouteContext, condType gwapiv1.RouteConditionType, status metav1.ConditionStatus) bool { +func (r *RouteParentContext) HasCondition(route RouteContext, condType gwapiv1beta1.RouteConditionType, status metav1.ConditionStatus) bool { var conditions []metav1.Condition routeStatus := GetRouteStatus(route) conditions = routeStatus.Parents[r.routeParentStatusIdx].Conditions @@ -421,15 +422,15 @@ func (r *RouteParentContext) HasCondition(route RouteContext, condType gwapiv1.R // BackendRefContext represents a generic BackendRef object (HTTPBackendRef, GRPCBackendRef or BackendRef itself) type BackendRefContext any -func GetBackendRef(b BackendRefContext) *gwapiv1.BackendRef { +func GetBackendRef(b BackendRefContext) *gwapiv1beta1.BackendRef { rv := reflect.ValueOf(b) br := rv.FieldByName("BackendRef") if br.IsValid() { - backendRef := br.Interface().(gwapiv1.BackendRef) + backendRef := br.Interface().(gwapiv1beta1.BackendRef) return &backendRef } - backendRef := b.(gwapiv1.BackendRef) + backendRef := b.(gwapiv1beta1.BackendRef) return &backendRef } diff --git a/internal/gatewayapi/contexts_test.go b/internal/gatewayapi/contexts_test.go index ca00be25ce23..42ab4dfde9a0 100644 --- a/internal/gatewayapi/contexts_test.go +++ b/internal/gatewayapi/contexts_test.go @@ -10,17 +10,18 @@ import ( "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" ) func TestContexts(t *testing.T) { - gateway := &gwapiv1.Gateway{ + gateway := &gwapiv1b1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Namespace: "envoy-gateway", Name: "gateway-1", }, - Spec: gwapiv1.GatewaySpec{ - Listeners: []gwapiv1.Listener{ + Spec: gwapiv1b1.GatewaySpec{ + Listeners: []gwapiv1b1.Listener{ { Name: "http", }, @@ -47,7 +48,7 @@ func TestContexts(t *testing.T) { require.EqualValues(t, gwapiv1.ListenerReasonUnsupportedProtocol, gateway.Status.Listeners[0].Conditions[0].Reason) require.EqualValues(t, "HTTPS protocol is not supported yet", gateway.Status.Listeners[0].Conditions[0].Message) - lctx.SetSupportedKinds(gwapiv1.RouteGroupKind{Group: GroupPtr(gwapiv1.GroupName), Kind: "HTTPRoute"}) + lctx.SetSupportedKinds(gwapiv1b1.RouteGroupKind{Group: GroupPtr(gwapiv1b1.GroupName), Kind: "HTTPRoute"}) require.Len(t, gateway.Status.Listeners, 1) require.Len(t, gateway.Status.Listeners[0].SupportedKinds, 1) @@ -58,13 +59,13 @@ func TestContexts(t *testing.T) { } func TestContextsStaleListener(t *testing.T) { - gateway := &gwapiv1.Gateway{ + gateway := &gwapiv1b1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Namespace: "envoy-gateway", Name: "gateway-1", }, - Spec: gwapiv1.GatewaySpec{ - Listeners: []gwapiv1.Listener{ + Spec: gwapiv1b1.GatewaySpec{ + Listeners: []gwapiv1b1.Listener{ { Name: "https", }, @@ -73,8 +74,8 @@ func TestContextsStaleListener(t *testing.T) { }, }, }, - Status: gwapiv1.GatewayStatus{ - Listeners: []gwapiv1.ListenerStatus{ + Status: gwapiv1b1.GatewayStatus{ + Listeners: []gwapiv1b1.ListenerStatus{ { Name: "https", Conditions: []metav1.Condition{ @@ -98,7 +99,7 @@ func TestContextsStaleListener(t *testing.T) { gCtx := &GatewayContext{Gateway: gateway} httpsListenerCtx := &ListenerContext{ - Listener: &gwapiv1.Listener{ + Listener: &gwapiv1b1.Listener{ Name: "https", }, gateway: gateway, @@ -106,7 +107,7 @@ func TestContextsStaleListener(t *testing.T) { } httpListenerCtx := &ListenerContext{ - Listener: &gwapiv1.Listener{ + Listener: &gwapiv1b1.Listener{ Name: "http", }, gateway: gateway, @@ -125,7 +126,7 @@ func TestContextsStaleListener(t *testing.T) { require.Len(t, gCtx.Status.Listeners, 2) - expectedListenerStatuses := []gwapiv1.ListenerStatus{ + expectedListenerStatuses := []gwapiv1b1.ListenerStatus{ { Name: "https", }, @@ -142,7 +143,7 @@ func TestContextsStaleListener(t *testing.T) { // Ensure the listener status has been updated and the stale listener has been // removed. - expectedListenerStatus := []gwapiv1.ListenerStatus{{Name: "https"}} + expectedListenerStatus := []gwapiv1b1.ListenerStatus{{Name: "https"}} require.EqualValues(t, expectedListenerStatus, gCtx.Gateway.Status.Listeners) // Ensure that the listeners within GatewayContext have been properly updated. diff --git a/internal/gatewayapi/filters.go b/internal/gatewayapi/filters.go index b5248cf79511..5a1b91e9db02 100644 --- a/internal/gatewayapi/filters.go +++ b/internal/gatewayapi/filters.go @@ -10,8 +10,9 @@ import ( "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/internal/ir" ) @@ -23,12 +24,12 @@ type FiltersTranslator interface { var _ FiltersTranslator = (*Translator)(nil) type HTTPFiltersTranslator interface { - processURLRewriteFilter(rewrite *gwapiv1.HTTPURLRewriteFilter, filterContext *HTTPFiltersContext) - processRedirectFilter(redirect *gwapiv1.HTTPRequestRedirectFilter, filterContext *HTTPFiltersContext) - processRequestHeaderModifierFilter(headerModifier *gwapiv1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) - processResponseHeaderModifierFilter(headerModifier *gwapiv1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) - processRequestMirrorFilter(filterIdx int, mirror *gwapiv1.HTTPRequestMirrorFilter, filterContext *HTTPFiltersContext, resources *Resources) - processExtensionRefHTTPFilter(extRef *gwapiv1.LocalObjectReference, filterContext *HTTPFiltersContext, resources *Resources) + processURLRewriteFilter(rewrite *gwapiv1beta1.HTTPURLRewriteFilter, filterContext *HTTPFiltersContext) + processRedirectFilter(redirect *gwapiv1beta1.HTTPRequestRedirectFilter, filterContext *HTTPFiltersContext) + processRequestHeaderModifierFilter(headerModifier *gwapiv1beta1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) + processResponseHeaderModifierFilter(headerModifier *gwapiv1beta1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) + processRequestMirrorFilter(filterIdx int, mirror *gwapiv1beta1.HTTPRequestMirrorFilter, filterContext *HTTPFiltersContext, resources *Resources) + processExtensionRefHTTPFilter(extRef *gwapiv1beta1.LocalObjectReference, filterContext *HTTPFiltersContext, resources *Resources) processUnsupportedHTTPFilter(filterType string, filterContext *HTTPFiltersContext) } @@ -62,7 +63,7 @@ type HTTPFilterIR struct { // ProcessHTTPFilters translates gateway api http filters to IRs. func (t *Translator) ProcessHTTPFilters(parentRef *RouteParentContext, route RouteContext, - filters []gwapiv1.HTTPRouteFilter, + filters []gwapiv1beta1.HTTPRouteFilter, ruleIdx int, resources *Resources) *HTTPFiltersContext { httpFiltersContext := &HTTPFiltersContext{ @@ -143,13 +144,13 @@ func (t *Translator) ProcessGRPCFilters(parentRef *RouteParentContext, } func (t *Translator) processURLRewriteFilter( - rewrite *gwapiv1.HTTPURLRewriteFilter, + rewrite *gwapiv1beta1.HTTPURLRewriteFilter, filterContext *HTTPFiltersContext) { if filterContext.URLRewrite != nil { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "Cannot configure multiple urlRewrite filters for a single HTTPRouteRule", ) return @@ -164,9 +165,9 @@ func (t *Translator) processURLRewriteFilter( if rewrite.Hostname != nil { if err := t.validateHostname(string(*rewrite.Hostname)); err != nil { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, err.Error(), ) return @@ -181,9 +182,9 @@ func (t *Translator) processURLRewriteFilter( if rewrite.Path.ReplacePrefixMatch != nil { errMsg := "ReplacePrefixMatch cannot be set when rewrite path type is \"ReplaceFullPath\"" filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) return @@ -191,9 +192,9 @@ func (t *Translator) processURLRewriteFilter( if rewrite.Path.ReplaceFullPath == nil { errMsg := "ReplaceFullPath must be set when rewrite path type is \"ReplaceFullPath\"" filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) return @@ -207,9 +208,9 @@ func (t *Translator) processURLRewriteFilter( if rewrite.Path.ReplaceFullPath != nil { errMsg := "ReplaceFullPath cannot be set when rewrite path type is \"ReplacePrefixMatch\"" filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) return @@ -217,9 +218,9 @@ func (t *Translator) processURLRewriteFilter( if rewrite.Path.ReplacePrefixMatch == nil { errMsg := "ReplacePrefixMatch must be set when rewrite path type is \"ReplacePrefixMatch\"" filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) return @@ -232,9 +233,9 @@ func (t *Translator) processURLRewriteFilter( default: errMsg := fmt.Sprintf("Rewrite path type: %s is invalid, only \"ReplaceFullPath\" and \"ReplacePrefixMatch\" are supported", rewrite.Path.Type) filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) return @@ -245,14 +246,14 @@ func (t *Translator) processURLRewriteFilter( } func (t *Translator) processRedirectFilter( - redirect *gwapiv1.HTTPRequestRedirectFilter, + redirect *gwapiv1beta1.HTTPRequestRedirectFilter, filterContext *HTTPFiltersContext) { // Can't have two redirects for the same route if filterContext.RedirectResponse != nil { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "Cannot configure multiple requestRedirect filters for a single HTTPRouteRule", ) return @@ -271,9 +272,9 @@ func (t *Translator) processRedirectFilter( } else { errMsg := fmt.Sprintf("Scheme: %s is unsupported, only 'https' and 'http' are supported", *redirect.Scheme) filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) return @@ -283,9 +284,9 @@ func (t *Translator) processRedirectFilter( if redirect.Hostname != nil { if err := t.validateHostname(string(*redirect.Hostname)); err != nil { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, err.Error(), ) } else { @@ -311,9 +312,9 @@ func (t *Translator) processRedirectFilter( default: errMsg := fmt.Sprintf("Redirect path type: %s is invalid, only \"ReplaceFullPath\" and \"ReplacePrefixMatch\" are supported", redirect.Path.Type) filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) return @@ -328,9 +329,9 @@ func (t *Translator) processRedirectFilter( } else { errMsg := fmt.Sprintf("Status code %d is invalid, only 302 and 301 are supported", redirectCode) filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) return @@ -346,7 +347,7 @@ func (t *Translator) processRedirectFilter( } func (t *Translator) processRequestHeaderModifierFilter( - headerModifier *gwapiv1.HTTPHeaderFilter, + headerModifier *gwapiv1beta1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) { // Make sure the header modifier config actually exists if headerModifier == nil { @@ -363,9 +364,9 @@ func (t *Translator) processRequestHeaderModifierFilter( emptyFilterConfig = false if addHeader.Name == "" { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "RequestHeaderModifier Filter cannot add a header with an empty name", ) // try to process the rest of the headers and produce a valid config. @@ -374,9 +375,9 @@ func (t *Translator) processRequestHeaderModifierFilter( // Per Gateway API specification on HTTPHeaderName, : and / are invalid characters in header names if strings.Contains(string(addHeader.Name), "/") || strings.Contains(string(addHeader.Name), ":") { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, fmt.Sprintf("RequestHeaderModifier Filter cannot set headers with a '/' or ':' character in them. Header: %q", string(addHeader.Name)), ) continue @@ -414,9 +415,9 @@ func (t *Translator) processRequestHeaderModifierFilter( if setHeader.Name == "" { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "RequestHeaderModifier Filter cannot set a header with an empty name", ) continue @@ -424,9 +425,9 @@ func (t *Translator) processRequestHeaderModifierFilter( // Per Gateway API specification on HTTPHeaderName, : and / are invalid characters in header names if strings.Contains(string(setHeader.Name), "/") || strings.Contains(string(setHeader.Name), ":") { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, fmt.Sprintf("RequestHeaderModifier Filter cannot set headers with a '/' or ':' character in them. Header: '%s'", string(setHeader.Name)), ) continue @@ -464,9 +465,9 @@ func (t *Translator) processRequestHeaderModifierFilter( for _, removedHeader := range headersToRemove { if removedHeader == "" { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "RequestHeaderModifier Filter cannot remove a header with an empty name", ) continue @@ -490,16 +491,16 @@ func (t *Translator) processRequestHeaderModifierFilter( // Update the status if the filter failed to configure any valid headers to add/remove if len(filterContext.AddRequestHeaders) == 0 && len(filterContext.RemoveRequestHeaders) == 0 && !emptyFilterConfig { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "RequestHeaderModifier Filter did not provide valid configuration to add/set/remove any headers", ) } } func (t *Translator) processResponseHeaderModifierFilter( - headerModifier *gwapiv1.HTTPHeaderFilter, + headerModifier *gwapiv1beta1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) { // Make sure the header modifier config actually exists if headerModifier == nil { @@ -516,9 +517,9 @@ func (t *Translator) processResponseHeaderModifierFilter( emptyFilterConfig = false if addHeader.Name == "" { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "ResponseHeaderModifier Filter cannot add a header with an empty name", ) // try to process the rest of the headers and produce a valid config. @@ -527,9 +528,9 @@ func (t *Translator) processResponseHeaderModifierFilter( // Per Gateway API specification on HTTPHeaderName, : and / are invalid characters in header names if strings.Contains(string(addHeader.Name), "/") || strings.Contains(string(addHeader.Name), ":") { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, fmt.Sprintf("ResponseHeaderModifier Filter cannot set headers with a '/' or ':' character in them. Header: %q", string(addHeader.Name)), ) continue @@ -567,9 +568,9 @@ func (t *Translator) processResponseHeaderModifierFilter( if setHeader.Name == "" { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "ResponseHeaderModifier Filter cannot set a header with an empty name", ) continue @@ -577,9 +578,9 @@ func (t *Translator) processResponseHeaderModifierFilter( // Per Gateway API specification on HTTPHeaderName, : and / are invalid characters in header names if strings.Contains(string(setHeader.Name), "/") || strings.Contains(string(setHeader.Name), ":") { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, fmt.Sprintf("ResponseHeaderModifier Filter cannot set headers with a '/' or ':' character in them. Header: '%s'", string(setHeader.Name)), ) continue @@ -617,9 +618,9 @@ func (t *Translator) processResponseHeaderModifierFilter( for _, removedHeader := range headersToRemove { if removedHeader == "" { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "ResponseHeaderModifier Filter cannot remove a header with an empty name", ) continue @@ -644,15 +645,15 @@ func (t *Translator) processResponseHeaderModifierFilter( // Update the status if the filter failed to configure any valid headers to add/remove if len(filterContext.AddResponseHeaders) == 0 && len(filterContext.RemoveResponseHeaders) == 0 && !emptyFilterConfig { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "ResponseHeaderModifier Filter did not provide valid configuration to add/set/remove any headers", ) } } -func (t *Translator) processExtensionRefHTTPFilter(extFilter *gwapiv1.LocalObjectReference, filterContext *HTTPFiltersContext, resources *Resources) { +func (t *Translator) processExtensionRefHTTPFilter(extFilter *gwapiv1beta1.LocalObjectReference, filterContext *HTTPFiltersContext, resources *Resources) { // Make sure the config actually exists. if extFilter == nil { return @@ -691,7 +692,7 @@ func (t *Translator) processExtensionRefHTTPFilter(extFilter *gwapiv1.LocalObjec func (t *Translator) processRequestMirrorFilter( filterIdx int, - mirrorFilter *gwapiv1.HTTPRequestMirrorFilter, + mirrorFilter *gwapiv1beta1.HTTPRequestMirrorFilter, filterContext *HTTPFiltersContext, resources *Resources) { @@ -704,8 +705,8 @@ func (t *Translator) processRequestMirrorFilter( // Wrap the filter's BackendObjectReference into a BackendRef so we can use existing tooling to check it weight := int32(1) - mirrorBackendRef := gwapiv1.HTTPBackendRef{ - BackendRef: gwapiv1.BackendRef{ + mirrorBackendRef := gwapiv1beta1.HTTPBackendRef{ + BackendRef: gwapiv1beta1.BackendRef{ BackendObjectReference: mirrorBackend, Weight: &weight, }, @@ -730,15 +731,15 @@ func (t *Translator) processRequestMirrorFilter( func (t *Translator) processUnresolvedHTTPFilter(errMsg string, filterContext *HTTPFiltersContext) { filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, - gwapiv1.RouteReasonBackendNotFound, + gwapiv1beta1.RouteReasonBackendNotFound, errMsg, ) filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) filterContext.DirectResponse = &ir.DirectResponse{ @@ -750,9 +751,9 @@ func (t *Translator) processUnresolvedHTTPFilter(errMsg string, filterContext *H func (t *Translator) processUnsupportedHTTPFilter(filterType string, filterContext *HTTPFiltersContext) { errMsg := fmt.Sprintf("Unsupported filter type: %s", filterType) filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) filterContext.DirectResponse = &ir.DirectResponse{ @@ -764,9 +765,9 @@ func (t *Translator) processUnsupportedHTTPFilter(filterType string, filterConte func (t *Translator) processInvalidHTTPFilter(filterType string, filterContext *HTTPFiltersContext, err error) { errMsg := fmt.Sprintf("Invalid filter %s: %v", filterType, err) filterContext.ParentRef.SetCondition(filterContext.Route, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, errMsg, ) filterContext.DirectResponse = &ir.DirectResponse{ diff --git a/internal/gatewayapi/helpers.go b/internal/gatewayapi/helpers.go index df342d214f6f..024f8063e9c3 100644 --- a/internal/gatewayapi/helpers.go +++ b/internal/gatewayapi/helpers.go @@ -14,8 +14,9 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/internal/ir" "github.com/envoyproxy/gateway/internal/utils" @@ -32,36 +33,36 @@ const ( ) type protocolPort struct { - protocol gwapiv1.ProtocolType + protocol gwapiv1beta1.ProtocolType port int32 } -func GroupPtr(name string) *gwapiv1.Group { - group := gwapiv1.Group(name) +func GroupPtr(name string) *gwapiv1beta1.Group { + group := gwapiv1beta1.Group(name) return &group } -func KindPtr(name string) *gwapiv1.Kind { - kind := gwapiv1.Kind(name) +func KindPtr(name string) *gwapiv1beta1.Kind { + kind := gwapiv1beta1.Kind(name) return &kind } -func NamespacePtr(name string) *gwapiv1.Namespace { - namespace := gwapiv1.Namespace(name) +func NamespacePtr(name string) *gwapiv1beta1.Namespace { + namespace := gwapiv1beta1.Namespace(name) return &namespace } -func FromNamespacesPtr(fromNamespaces gwapiv1.FromNamespaces) *gwapiv1.FromNamespaces { +func FromNamespacesPtr(fromNamespaces gwapiv1beta1.FromNamespaces) *gwapiv1beta1.FromNamespaces { return &fromNamespaces } -func SectionNamePtr(name string) *gwapiv1.SectionName { - sectionName := gwapiv1.SectionName(name) +func SectionNamePtr(name string) *gwapiv1beta1.SectionName { + sectionName := gwapiv1beta1.SectionName(name) return §ionName } -func PortNumPtr(val int32) *gwapiv1.PortNumber { - portNum := gwapiv1.PortNumber(val) +func PortNumPtr(val int32) *gwapiv1beta1.PortNumber { + portNum := gwapiv1beta1.PortNumber(val) return &portNum } @@ -71,27 +72,27 @@ func ObjectNamePtr(val string) *v1alpha2.ObjectName { } var ( - PathMatchTypeDerefOr = ptr.Deref[gwapiv1.PathMatchType] + PathMatchTypeDerefOr = ptr.Deref[gwapiv1beta1.PathMatchType] GRPCMethodMatchTypeDerefOr = ptr.Deref[v1alpha2.GRPCMethodMatchType] - HeaderMatchTypeDerefOr = ptr.Deref[gwapiv1.HeaderMatchType] - QueryParamMatchTypeDerefOr = ptr.Deref[gwapiv1.QueryParamMatchType] + HeaderMatchTypeDerefOr = ptr.Deref[gwapiv1beta1.HeaderMatchType] + QueryParamMatchTypeDerefOr = ptr.Deref[gwapiv1beta1.QueryParamMatchType] ) -func NamespaceDerefOr(namespace *gwapiv1.Namespace, defaultNamespace string) string { +func NamespaceDerefOr(namespace *gwapiv1beta1.Namespace, defaultNamespace string) string { if namespace != nil && *namespace != "" { return string(*namespace) } return defaultNamespace } -func GroupDerefOr(group *gwapiv1.Group, defaultGroup string) string { +func GroupDerefOr(group *gwapiv1beta1.Group, defaultGroup string) string { if group != nil && *group != "" { return string(*group) } return defaultGroup } -func KindDerefOr(kind *gwapiv1.Kind, defaultKind string) string { +func KindDerefOr(kind *gwapiv1beta1.Kind, defaultKind string) string { if kind != nil && *kind != "" { return string(*kind) } @@ -102,8 +103,8 @@ func KindDerefOr(kind *gwapiv1.Kind, defaultKind string) string { // to a Gateway with the given namespace/name, irrespective of whether a // section/listener name has been specified (i.e. a parent ref to a listener // on the specified gateway will return "true"). -func IsRefToGateway(parentRef gwapiv1.ParentReference, gateway types.NamespacedName) bool { - if parentRef.Group != nil && string(*parentRef.Group) != gwapiv1.GroupName { +func IsRefToGateway(parentRef gwapiv1beta1.ParentReference, gateway types.NamespacedName) bool { + if parentRef.Group != nil && string(*parentRef.Group) != gwapiv1beta1.GroupName { return false } @@ -122,7 +123,7 @@ func IsRefToGateway(parentRef gwapiv1.ParentReference, gateway types.NamespacedN // in the given list, and if so, a list of the Listeners within that Gateway that // are included by the parent ref (either one specific Listener, or all Listeners // in the Gateway, depending on whether section name is specified or not). -func GetReferencedListeners(parentRef gwapiv1.ParentReference, gateways []*GatewayContext) (bool, []*ListenerContext) { +func GetReferencedListeners(parentRef gwapiv1beta1.ParentReference, gateways []*GatewayContext) (bool, []*ListenerContext) { var selectsGateway bool var referencedListeners []*ListenerContext @@ -156,7 +157,7 @@ func HasReadyListener(listeners []*ListenerContext) bool { } // ValidateHTTPRouteFilter validates the provided filter within HTTPRoute. -func ValidateHTTPRouteFilter(filter *gwapiv1.HTTPRouteFilter, extGKs ...schema.GroupKind) error { +func ValidateHTTPRouteFilter(filter *gwapiv1beta1.HTTPRouteFilter, extGKs ...schema.GroupKind) error { switch { case filter == nil: return errors.New("filter is nil") @@ -172,8 +173,8 @@ func ValidateHTTPRouteFilter(filter *gwapiv1.HTTPRouteFilter, extGKs ...schema.G return errors.New("extensionRef field must be specified for an extended filter") default: for _, gk := range extGKs { - if filter.ExtensionRef.Group == gwapiv1.Group(gk.Group) && - filter.ExtensionRef.Kind == gwapiv1.Kind(gk.Kind) { + if filter.ExtensionRef.Group == gwapiv1beta1.Group(gk.Group) && + filter.ExtensionRef.Kind == gwapiv1beta1.Kind(gk.Kind) { return nil } } @@ -199,8 +200,8 @@ func ValidateGRPCRouteFilter(filter *v1alpha2.GRPCRouteFilter, extGKs ...schema. return errors.New("extensionRef field must be specified for an extended filter") default: for _, gk := range extGKs { - if filter.ExtensionRef.Group == gwapiv1.Group(gk.Group) && - filter.ExtensionRef.Kind == gwapiv1.Kind(gk.Kind) { + if filter.ExtensionRef.Group == gwapiv1beta1.Group(gk.Group) && + filter.ExtensionRef.Kind == gwapiv1beta1.Kind(gk.Kind) { return nil } } @@ -241,7 +242,7 @@ func servicePortToContainerPort(servicePort int32) int32 { // computeHosts returns a list of the intersecting hostnames between the route // and the listener. -func computeHosts(routeHostnames []string, listenerHostname *gwapiv1.Hostname) []string { +func computeHosts(routeHostnames []string, listenerHostname *gwapiv1beta1.Hostname) []string { var listenerHostnameVal string if listenerHostname != nil { listenerHostnameVal = string(*listenerHostname) @@ -403,7 +404,7 @@ func IsMergeGatewaysEnabled(resources *Resources) bool { return resources.EnvoyProxy != nil && resources.EnvoyProxy.Spec.MergeGateways != nil && *resources.EnvoyProxy.Spec.MergeGateways } -func protocolSliceToStringSlice(protocols []gwapiv1.ProtocolType) []string { +func protocolSliceToStringSlice(protocols []gwapiv1beta1.ProtocolType) []string { var protocolStrings []string for _, protocol := range protocols { protocolStrings = append(protocolStrings, string(protocol)) @@ -414,10 +415,10 @@ func protocolSliceToStringSlice(protocols []gwapiv1.ProtocolType) []string { // getAncestorRefForPolicy returns Gateway as an ancestor reference for policy. func getAncestorRefForPolicy(gatewayNN types.NamespacedName, sectionName *v1alpha2.SectionName) v1alpha2.ParentReference { return v1alpha2.ParentReference{ - Group: GroupPtr(gwapiv1.GroupName), + Group: GroupPtr(gwapiv1beta1.GroupName), Kind: KindPtr(KindGateway), Namespace: NamespacePtr(gatewayNN.Namespace), - Name: gwapiv1.ObjectName(gatewayNN.Name), + Name: gwapiv1beta1.ObjectName(gatewayNN.Name), SectionName: sectionName, } } diff --git a/internal/gatewayapi/helpers_test.go b/internal/gatewayapi/helpers_test.go index f8654db241b6..24f8868c0bed 100644 --- a/internal/gatewayapi/helpers_test.go +++ b/internal/gatewayapi/helpers_test.go @@ -16,8 +16,9 @@ import ( "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/runtime/schema" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" ) func TestValidateGRPCFilterRef(t *testing.T) { @@ -51,7 +52,7 @@ func TestValidateGRPCFilterRef(t *testing.T) { name: "valid extension resource", filter: &gwapiv1a2.GRPCRouteFilter{ Type: gwapiv1a2.GRPCRouteFilterExtensionRef, - ExtensionRef: &gwapiv1.LocalObjectReference{ + ExtensionRef: &gwapiv1b1.LocalObjectReference{ Group: "example.io", Kind: "Foo", Name: "test", @@ -63,7 +64,7 @@ func TestValidateGRPCFilterRef(t *testing.T) { name: "unsupported extended filter", filter: &gwapiv1a2.GRPCRouteFilter{ Type: gwapiv1a2.GRPCRouteFilterExtensionRef, - ExtensionRef: &gwapiv1.LocalObjectReference{ + ExtensionRef: &gwapiv1b1.LocalObjectReference{ Group: "UnsupportedGroup", Kind: "UnsupportedKind", Name: "test", @@ -82,7 +83,7 @@ func TestValidateGRPCFilterRef(t *testing.T) { name: "invalid filter type", filter: &gwapiv1a2.GRPCRouteFilter{ Type: "Invalid", - ExtensionRef: &gwapiv1.LocalObjectReference{ + ExtensionRef: &gwapiv1b1.LocalObjectReference{ Group: "example.io", Kind: "Foo", Name: "test", @@ -107,42 +108,42 @@ func TestValidateGRPCFilterRef(t *testing.T) { func TestValidateHTTPFilterRef(t *testing.T) { testCases := []struct { name string - filter *gwapiv1.HTTPRouteFilter + filter *gwapiv1b1.HTTPRouteFilter expected bool }{ { name: "request mirror filter", - filter: &gwapiv1.HTTPRouteFilter{ + filter: &gwapiv1b1.HTTPRouteFilter{ Type: gwapiv1.HTTPRouteFilterRequestMirror, }, expected: true, }, { name: "url rewrite filter", - filter: &gwapiv1.HTTPRouteFilter{ + filter: &gwapiv1b1.HTTPRouteFilter{ Type: gwapiv1.HTTPRouteFilterURLRewrite, }, expected: true, }, { name: "request header modifier filter", - filter: &gwapiv1.HTTPRouteFilter{ + filter: &gwapiv1b1.HTTPRouteFilter{ Type: gwapiv1.HTTPRouteFilterRequestHeaderModifier, }, expected: true, }, { name: "request redirect filter", - filter: &gwapiv1.HTTPRouteFilter{ + filter: &gwapiv1b1.HTTPRouteFilter{ Type: gwapiv1.HTTPRouteFilterRequestRedirect, }, expected: true, }, { name: "unsupported extended filter", - filter: &gwapiv1.HTTPRouteFilter{ + filter: &gwapiv1b1.HTTPRouteFilter{ Type: gwapiv1.HTTPRouteFilterExtensionRef, - ExtensionRef: &gwapiv1.LocalObjectReference{ + ExtensionRef: &gwapiv1b1.LocalObjectReference{ Group: "UnsupportedGroup", Kind: "UnsupportedKind", Name: "test", @@ -152,16 +153,16 @@ func TestValidateHTTPFilterRef(t *testing.T) { }, { name: "extended filter with missing reference", - filter: &gwapiv1.HTTPRouteFilter{ + filter: &gwapiv1b1.HTTPRouteFilter{ Type: gwapiv1.HTTPRouteFilterExtensionRef, }, expected: false, }, { name: "valid extension resource", - filter: &gwapiv1.HTTPRouteFilter{ + filter: &gwapiv1b1.HTTPRouteFilter{ Type: gwapiv1.HTTPRouteFilterExtensionRef, - ExtensionRef: &gwapiv1.LocalObjectReference{ + ExtensionRef: &gwapiv1b1.LocalObjectReference{ Group: "example.io", Kind: "Foo", Name: "test", @@ -171,9 +172,9 @@ func TestValidateHTTPFilterRef(t *testing.T) { }, { name: "invalid filter type", - filter: &gwapiv1.HTTPRouteFilter{ + filter: &gwapiv1b1.HTTPRouteFilter{ Type: "Invalid", - ExtensionRef: &gwapiv1.LocalObjectReference{ + ExtensionRef: &gwapiv1b1.LocalObjectReference{ Group: "example.io", Kind: "Foo", Name: "test", diff --git a/internal/gatewayapi/listener.go b/internal/gatewayapi/listener.go index 06a190dc1dfa..9b9f3ee140a5 100644 --- a/internal/gatewayapi/listener.go +++ b/internal/gatewayapi/listener.go @@ -9,7 +9,8 @@ import ( "fmt" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/ir" @@ -234,7 +235,7 @@ func processAccessLog(envoyproxy *egv1a1.EnvoyProxy) *ir.AccessLog { return irAccessLog } -func processTracing(gw *gwapiv1.Gateway, envoyproxy *egv1a1.EnvoyProxy) *ir.Tracing { +func processTracing(gw *gwapiv1beta1.Gateway, envoyproxy *egv1a1.EnvoyProxy) *ir.Tracing { if envoyproxy == nil || envoyproxy.Spec.Telemetry == nil || envoyproxy.Spec.Telemetry.Tracing == nil { diff --git a/internal/gatewayapi/route.go b/internal/gatewayapi/route.go index 6858a4865cd9..34bfb412b5ac 100644 --- a/internal/gatewayapi/route.go +++ b/internal/gatewayapi/route.go @@ -15,8 +15,9 @@ import ( discoveryv1 "k8s.io/api/discovery/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" mcsapi "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" "github.com/envoyproxy/gateway/internal/ir" @@ -38,14 +39,14 @@ var ( ) type RoutesTranslator interface { - ProcessHTTPRoutes(httpRoutes []*gwapiv1.HTTPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*HTTPRouteContext + ProcessHTTPRoutes(httpRoutes []*gwapiv1beta1.HTTPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*HTTPRouteContext ProcessGRPCRoutes(grpcRoutes []*gwapiv1a2.GRPCRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*GRPCRouteContext ProcessTLSRoutes(tlsRoutes []*gwapiv1a2.TLSRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*TLSRouteContext ProcessTCPRoutes(tcpRoutes []*gwapiv1a2.TCPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*TCPRouteContext ProcessUDPRoutes(udpRoutes []*gwapiv1a2.UDPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*UDPRouteContext } -func (t *Translator) ProcessHTTPRoutes(httpRoutes []*gwapiv1.HTTPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*HTTPRouteContext { +func (t *Translator) ProcessHTTPRoutes(httpRoutes []*gwapiv1beta1.HTTPRoute, gateways []*GatewayContext, resources *Resources, xdsIR XdsIRMap) []*HTTPRouteContext { var relevantHTTPRoutes []*HTTPRouteContext for _, h := range httpRoutes { @@ -109,35 +110,35 @@ func (t *Translator) processHTTPRouteParentRefs(httpRoute *HTTPRouteContext, res routeRoutes, err := t.processHTTPRouteRules(httpRoute, parentRef, resources) if err != nil { parentRef.SetCondition(httpRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, // TODO: better reason + gwapiv1beta1.RouteReasonUnsupportedValue, // TODO: better reason status.Error2ConditionMsg(err), ) continue } // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" - if !parentRef.HasCondition(httpRoute, gwapiv1.RouteConditionResolvedRefs, metav1.ConditionFalse) { + if !parentRef.HasCondition(httpRoute, gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse) { parentRef.SetCondition(httpRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionTrue, - gwapiv1.RouteReasonResolvedRefs, + gwapiv1beta1.RouteReasonResolvedRefs, "Resolved all the Object references for the Route", ) } // Skip parent refs that did not accept the route - if parentRef.HasCondition(httpRoute, gwapiv1.RouteConditionAccepted, metav1.ConditionFalse) { + if parentRef.HasCondition(httpRoute, gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse) { continue } var hasHostnameIntersection = t.processHTTPRouteParentRefListener(httpRoute, routeRoutes, parentRef, xdsIR) if !hasHostnameIntersection { parentRef.SetCondition(httpRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonNoMatchingListenerHostname, + gwapiv1beta1.RouteReasonNoMatchingListenerHostname, "There were no hostname intersections between the HTTPRoute and this parent ref's Listener(s).", ) } @@ -146,9 +147,9 @@ func (t *Translator) processHTTPRouteParentRefs(httpRoute *HTTPRouteContext, res if parentRef.HTTPRoute != nil && len(parentRef.HTTPRoute.Status.Parents[parentRef.routeParentStatusIdx].Conditions) == 0 { parentRef.SetCondition(httpRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionTrue, - gwapiv1.RouteReasonAccepted, + gwapiv1beta1.RouteReasonAccepted, "Route is accepted", ) } @@ -202,7 +203,7 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe // TODO: support mixed endpointslice address type between backendRefs if !t.EndpointRoutingDisabled && len(dstAddrTypeMap) > 1 { parentRef.SetCondition(httpRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, gwapiv1a2.RouteReasonResolvedRefs, "Mixed endpointslice address type between backendRefs is not supported") @@ -228,7 +229,7 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe return routeRoutes, nil } -func processTimeout(irRoute *ir.HTTPRoute, rule gwapiv1.HTTPRouteRule) { +func processTimeout(irRoute *ir.HTTPRoute, rule gwapiv1beta1.HTTPRouteRule) { if rule.Timeouts != nil { var rto *ir.Timeout @@ -272,7 +273,7 @@ func setRequestTimeout(irTimeout *ir.Timeout, d metav1.Duration) { } } -func (t *Translator) processHTTPRouteRule(httpRoute *HTTPRouteContext, ruleIdx int, httpFiltersContext *HTTPFiltersContext, rule gwapiv1.HTTPRouteRule) ([]*ir.HTTPRoute, error) { +func (t *Translator) processHTTPRouteRule(httpRoute *HTTPRouteContext, ruleIdx int, httpFiltersContext *HTTPFiltersContext, rule gwapiv1beta1.HTTPRouteRule) ([]*ir.HTTPRoute, error) { var ruleRoutes []*ir.HTTPRoute // If no matches are specified, the implementation MUST match every HTTP request. @@ -403,33 +404,33 @@ func (t *Translator) processGRPCRouteParentRefs(grpcRoute *GRPCRouteContext, res routeRoutes, err := t.processGRPCRouteRules(grpcRoute, parentRef, resources) if err != nil { parentRef.SetCondition(grpcRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, // TODO: better reason + gwapiv1beta1.RouteReasonUnsupportedValue, // TODO: better reason status.Error2ConditionMsg(err), ) continue } // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" - if !parentRef.HasCondition(grpcRoute, gwapiv1.RouteConditionResolvedRefs, metav1.ConditionFalse) { + if !parentRef.HasCondition(grpcRoute, gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse) { parentRef.SetCondition(grpcRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionTrue, - gwapiv1.RouteReasonResolvedRefs, + gwapiv1beta1.RouteReasonResolvedRefs, "Resolved all the Object references for the Route", ) } - if parentRef.HasCondition(grpcRoute, gwapiv1.RouteConditionAccepted, metav1.ConditionFalse) { + if parentRef.HasCondition(grpcRoute, gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse) { continue } var hasHostnameIntersection = t.processHTTPRouteParentRefListener(grpcRoute, routeRoutes, parentRef, xdsIR) if !hasHostnameIntersection { parentRef.SetCondition(grpcRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonNoMatchingListenerHostname, + gwapiv1beta1.RouteReasonNoMatchingListenerHostname, "There were no hostname intersections between the GRPCRoute and this parent ref's Listener(s).", ) } @@ -438,9 +439,9 @@ func (t *Translator) processGRPCRouteParentRefs(grpcRoute *GRPCRouteContext, res if parentRef.GRPCRoute != nil && len(parentRef.GRPCRoute.Status.Parents[parentRef.routeParentStatusIdx].Conditions) == 0 { parentRef.SetCondition(grpcRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionTrue, - gwapiv1.RouteReasonAccepted, + gwapiv1beta1.RouteReasonAccepted, "Route is accepted", ) } @@ -733,17 +734,17 @@ func (t *Translator) processTLSRouteParentRefs(tlsRoute *TLSRouteContext, resour } // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" - if !parentRef.HasCondition(tlsRoute, gwapiv1.RouteConditionResolvedRefs, metav1.ConditionFalse) { + if !parentRef.HasCondition(tlsRoute, gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse) { parentRef.SetCondition(tlsRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionTrue, - gwapiv1.RouteReasonResolvedRefs, + gwapiv1beta1.RouteReasonResolvedRefs, "Resolved all the Object references for the Route", ) } // Skip parent refs that did not accept the route - if parentRef.HasCondition(tlsRoute, gwapiv1.RouteConditionAccepted, metav1.ConditionFalse) { + if parentRef.HasCondition(tlsRoute, gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse) { continue } @@ -780,9 +781,9 @@ func (t *Translator) processTLSRouteParentRefs(tlsRoute *TLSRouteContext, resour if !hasHostnameIntersection { parentRef.SetCondition(tlsRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonNoMatchingListenerHostname, + gwapiv1beta1.RouteReasonNoMatchingListenerHostname, "There were no hostname intersections between the HTTPRoute and this parent ref's Listener(s).", ) } @@ -791,9 +792,9 @@ func (t *Translator) processTLSRouteParentRefs(tlsRoute *TLSRouteContext, resour if parentRef.TLSRoute != nil && len(parentRef.TLSRoute.Status.Parents[parentRef.routeParentStatusIdx].Conditions) == 0 { parentRef.SetCondition(tlsRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionTrue, - gwapiv1.RouteReasonAccepted, + gwapiv1beta1.RouteReasonAccepted, "Route is accepted", ) } @@ -839,7 +840,7 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour // compute backends if len(udpRoute.Spec.Rules) != 1 { parentRef.SetCondition(udpRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, "InvalidRule", "One and only one rule is supported", @@ -848,7 +849,7 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour } if len(udpRoute.Spec.Rules[0].BackendRefs) != 1 { parentRef.SetCondition(udpRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, "InvalidBackend", "One and only one backend is supported", @@ -865,17 +866,17 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour destSettings = append(destSettings, ds) // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" - if !parentRef.HasCondition(udpRoute, gwapiv1.RouteConditionResolvedRefs, metav1.ConditionFalse) { + if !parentRef.HasCondition(udpRoute, gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse) { parentRef.SetCondition(udpRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionTrue, - gwapiv1.RouteReasonResolvedRefs, + gwapiv1beta1.RouteReasonResolvedRefs, "Resolved all the Object references for the Route", ) } // Skip parent refs that did not accept the route - if parentRef.HasCondition(udpRoute, gwapiv1.RouteConditionAccepted, metav1.ConditionFalse) { + if parentRef.HasCondition(udpRoute, gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse) { continue } @@ -913,18 +914,18 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour if accepted && parentRef.UDPRoute != nil && len(parentRef.UDPRoute.Status.Parents[parentRef.routeParentStatusIdx].Conditions) == 0 { parentRef.SetCondition(udpRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionTrue, - gwapiv1.RouteReasonAccepted, + gwapiv1beta1.RouteReasonAccepted, "Route is accepted", ) } if !accepted { parentRef.SetCondition(udpRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "Multiple routes on the same UDP listener", ) } @@ -971,7 +972,7 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour // compute backends if len(tcpRoute.Spec.Rules) != 1 { parentRef.SetCondition(tcpRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, "InvalidRule", "One and only one rule is supported", @@ -980,7 +981,7 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour } if len(tcpRoute.Spec.Rules[0].BackendRefs) != 1 { parentRef.SetCondition(tcpRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, "InvalidBackend", "One and only one backend is supported", @@ -996,17 +997,17 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour } destSettings = append(destSettings, ds) // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" - if !parentRef.HasCondition(tcpRoute, gwapiv1.RouteConditionResolvedRefs, metav1.ConditionFalse) { + if !parentRef.HasCondition(tcpRoute, gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse) { parentRef.SetCondition(tcpRoute, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionTrue, - gwapiv1.RouteReasonResolvedRefs, + gwapiv1beta1.RouteReasonResolvedRefs, "Resolved all the Object references for the Route", ) } // Skip parent refs that did not accept the route - if parentRef.HasCondition(tcpRoute, gwapiv1.RouteConditionAccepted, metav1.ConditionFalse) { + if parentRef.HasCondition(tcpRoute, gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse) { continue } @@ -1044,17 +1045,17 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour if accepted && parentRef.TCPRoute != nil && len(parentRef.TCPRoute.Status.Parents[parentRef.routeParentStatusIdx].Conditions) == 0 { parentRef.SetCondition(tcpRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionTrue, - gwapiv1.RouteReasonAccepted, + gwapiv1beta1.RouteReasonAccepted, "Route is accepted", ) } if !accepted { parentRef.SetCondition(tcpRoute, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonUnsupportedValue, + gwapiv1beta1.RouteReasonUnsupportedValue, "Multiple routes on the same TCP listener", ) } @@ -1160,7 +1161,7 @@ func (t *Translator) processDestination(backendRefContext BackendRefContext, // TODO: support mixed endpointslice address type for the same backendRef if !t.EndpointRoutingDisabled && addrType != nil && *addrType == ir.MIXED { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, gwapiv1a2.RouteReasonResolvedRefs, "Mixed endpointslice address type for the same backendRef is not supported") @@ -1176,7 +1177,7 @@ func (t *Translator) processDestination(backendRefContext BackendRefContext, return ds, weight } -func inspectAppProtocolByRouteKind(kind gwapiv1.Kind) ir.AppProtocol { +func inspectAppProtocolByRouteKind(kind gwapiv1beta1.Kind) ir.AppProtocol { switch kind { case KindUDPRoute: return ir.UDP @@ -1213,7 +1214,7 @@ func (t *Translator) processAllowedListenersForParentRefs(routeContext RouteCont if len(selectedListeners) == 0 { parentRefCtx.SetCondition(routeContext, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, gwapiv1.RouteReasonNoMatchingParent, "No listeners match this parent ref", @@ -1224,7 +1225,7 @@ func (t *Translator) processAllowedListenersForParentRefs(routeContext RouteCont var allowedListeners []*ListenerContext for _, listener := range selectedListeners { acceptedKind := GetRouteType(routeContext) - if listener.AllowsKind(gwapiv1.RouteGroupKind{Group: GroupPtr(gwapiv1.GroupName), Kind: acceptedKind}) && + if listener.AllowsKind(gwapiv1beta1.RouteGroupKind{Group: GroupPtr(gwapiv1beta1.GroupName), Kind: acceptedKind}) && listener.AllowsNamespace(resources.GetNamespace(routeContext.GetNamespace())) { allowedListeners = append(allowedListeners, listener) } @@ -1232,9 +1233,9 @@ func (t *Translator) processAllowedListenersForParentRefs(routeContext RouteCont if len(allowedListeners) == 0 { parentRefCtx.SetCondition(routeContext, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, - gwapiv1.RouteReasonNotAllowedByListeners, + gwapiv1beta1.RouteReasonNotAllowedByListeners, "No listeners included by this parent ref allowed this attachment.", ) continue @@ -1252,7 +1253,7 @@ func (t *Translator) processAllowedListenersForParentRefs(routeContext RouteCont if !HasReadyListener(selectedListeners) { parentRefCtx.SetCondition(routeContext, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionFalse, "NoReadyListeners", "There are no ready listeners for this parent ref", @@ -1263,9 +1264,9 @@ func (t *Translator) processAllowedListenersForParentRefs(routeContext RouteCont parentRefCtx.SetListeners(allowedListeners...) parentRefCtx.SetCondition(routeContext, - gwapiv1.RouteConditionAccepted, + gwapiv1beta1.RouteConditionAccepted, metav1.ConditionTrue, - gwapiv1.RouteReasonAccepted, + gwapiv1beta1.RouteReasonAccepted, "Route is accepted", ) } @@ -1335,7 +1336,7 @@ func GetTargetBackendReference(backendRef gwapiv1a2.BackendObjectReference, name } return *backendRef.Group }(), - Kind: func() gwapiv1.Kind { + Kind: func() gwapiv1beta1.Kind { if backendRef.Kind == nil { return "Service" } @@ -1344,7 +1345,7 @@ func GetTargetBackendReference(backendRef gwapiv1a2.BackendObjectReference, name Name: backendRef.Name, Namespace: NamespacePtr(NamespaceDerefOr(backendRef.Namespace, namespace)), }, - SectionName: func() *gwapiv1.SectionName { + SectionName: func() *gwapiv1beta1.SectionName { if backendRef.Port != nil { return SectionNamePtr(strconv.Itoa(int(*backendRef.Port))) } diff --git a/internal/gatewayapi/validate.go b/internal/gatewayapi/validate.go index 1609844c567e..28ffc23377e5 100644 --- a/internal/gatewayapi/validate.go +++ b/internal/gatewayapi/validate.go @@ -15,15 +15,15 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" - gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" ) func (t *Translator) validateBackendRef(backendRefContext BackendRefContext, parentRef *RouteParentContext, route RouteContext, - resources *Resources, backendNamespace string, routeKind gwapiv1.Kind) bool { + resources *Resources, backendNamespace string, routeKind gwapiv1beta1.Kind) bool { if !t.validateBackendRefFilters(backendRefContext, parentRef, route, routeKind) { return false } @@ -62,9 +62,9 @@ func (t *Translator) validateBackendRef(backendRefContext BackendRefContext, par func (t *Translator) validateBackendRefGroup(backendRef *gwapiv1a2.BackendRef, parentRef *RouteParentContext, route RouteContext) bool { if backendRef.Group != nil && *backendRef.Group != "" && *backendRef.Group != GroupMultiClusterService { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, - gwapiv1.RouteReasonInvalidKind, + gwapiv1beta1.RouteReasonInvalidKind, fmt.Sprintf("Group is invalid, only the core API group (specified by omitting the group field or setting it to an empty string) and %s are supported", GroupMultiClusterService), ) return false @@ -75,9 +75,9 @@ func (t *Translator) validateBackendRefGroup(backendRef *gwapiv1a2.BackendRef, p func (t *Translator) validateBackendRefKind(backendRef *gwapiv1a2.BackendRef, parentRef *RouteParentContext, route RouteContext) bool { if backendRef.Kind != nil && *backendRef.Kind != KindService && *backendRef.Kind != KindServiceImport { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, - gwapiv1.RouteReasonInvalidKind, + gwapiv1beta1.RouteReasonInvalidKind, "Kind is invalid, only Service and MCS ServiceImport are supported", ) return false @@ -85,11 +85,11 @@ func (t *Translator) validateBackendRefKind(backendRef *gwapiv1a2.BackendRef, pa return true } -func (t *Translator) validateBackendRefFilters(backendRef BackendRefContext, parentRef *RouteParentContext, route RouteContext, routeKind gwapiv1.Kind) bool { +func (t *Translator) validateBackendRefFilters(backendRef BackendRefContext, parentRef *RouteParentContext, route RouteContext, routeKind gwapiv1beta1.Kind) bool { var filtersLen int switch routeKind { case KindHTTPRoute: - filters := GetFilters(backendRef).([]gwapiv1.HTTPRouteFilter) + filters := GetFilters(backendRef).([]gwapiv1beta1.HTTPRouteFilter) filtersLen = len(filters) case KindGRPCRoute: filters := GetFilters(backendRef).([]gwapiv1a2.GRPCRouteFilter) @@ -100,7 +100,7 @@ func (t *Translator) validateBackendRefFilters(backendRef BackendRefContext, par if filtersLen > 0 { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, "UnsupportedRefValue", "The filters field within BackendRef is not supported", @@ -112,11 +112,11 @@ func (t *Translator) validateBackendRefFilters(backendRef BackendRefContext, par } func (t *Translator) validateBackendNamespace(backendRef *gwapiv1a2.BackendRef, parentRef *RouteParentContext, route RouteContext, - resources *Resources, routeKind gwapiv1.Kind) bool { + resources *Resources, routeKind gwapiv1beta1.Kind) bool { if backendRef.Namespace != nil && string(*backendRef.Namespace) != "" && string(*backendRef.Namespace) != route.GetNamespace() { if !t.validateCrossNamespaceRef( crossNamespaceFrom{ - group: gwapiv1.GroupName, + group: gwapiv1beta1.GroupName, kind: string(routeKind), namespace: route.GetNamespace(), }, @@ -129,9 +129,9 @@ func (t *Translator) validateBackendNamespace(backendRef *gwapiv1a2.BackendRef, resources.ReferenceGrants, ) { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, - gwapiv1.RouteReasonRefNotPermitted, + gwapiv1beta1.RouteReasonRefNotPermitted, fmt.Sprintf("Backend ref to %s %s/%s not permitted by any ReferenceGrant.", KindDerefOr(backendRef.Kind, KindService), *backendRef.Namespace, backendRef.Name), ) return false @@ -143,7 +143,7 @@ func (t *Translator) validateBackendNamespace(backendRef *gwapiv1a2.BackendRef, func (t *Translator) validateBackendPort(backendRef *gwapiv1a2.BackendRef, parentRef *RouteParentContext, route RouteContext) bool { if backendRef.Port == nil { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, "PortNotSpecified", "A valid port number corresponding to a port on the Service must be specified", @@ -157,9 +157,9 @@ func (t *Translator) validateBackendService(backendRef *gwapiv1a2.BackendRef, pa service := resources.GetService(serviceNamespace, string(backendRef.Name)) if service == nil { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, - gwapiv1.RouteReasonBackendNotFound, + gwapiv1beta1.RouteReasonBackendNotFound, fmt.Sprintf("Service %s/%s not found", NamespaceDerefOr(backendRef.Namespace, route.GetNamespace()), string(backendRef.Name)), ) @@ -179,7 +179,7 @@ func (t *Translator) validateBackendService(backendRef *gwapiv1a2.BackendRef, pa if !portFound { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, "PortNotFound", fmt.Sprintf(string(protocol)+" Port %d not found on service %s/%s", *backendRef.Port, serviceNamespace, @@ -195,9 +195,9 @@ func (t *Translator) validateBackendServiceImport(backendRef *gwapiv1a2.BackendR serviceImport := resources.GetServiceImport(serviceImportNamespace, string(backendRef.Name)) if serviceImport == nil { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, - gwapiv1.RouteReasonBackendNotFound, + gwapiv1beta1.RouteReasonBackendNotFound, fmt.Sprintf("ServiceImport %s/%s not found", NamespaceDerefOr(backendRef.Namespace, route.GetNamespace()), string(backendRef.Name)), ) @@ -217,7 +217,7 @@ func (t *Translator) validateBackendServiceImport(backendRef *gwapiv1a2.BackendR if !portFound { parentRef.SetCondition(route, - gwapiv1.RouteConditionResolvedRefs, + gwapiv1beta1.RouteConditionResolvedRefs, metav1.ConditionFalse, "PortNotFound", fmt.Sprintf(string(protocol)+" Port %d not found on ServiceImport %s/%s", *backendRef.Port, serviceImportNamespace, @@ -343,7 +343,7 @@ func (t *Translator) validateTerminateModeAndGetTLSSecrets(listener *ListenerCon if certificateRef.Namespace != nil && string(*certificateRef.Namespace) != "" && string(*certificateRef.Namespace) != listener.gateway.Namespace { if !t.validateCrossNamespaceRef( crossNamespaceFrom{ - group: gwapiv1.GroupName, + group: gwapiv1beta1.GroupName, kind: KindGateway, namespace: listener.gateway.Namespace, }, @@ -502,29 +502,29 @@ func (t *Translator) validateHostName(listener *ListenerContext) { } } -func (t *Translator) validateAllowedRoutes(listener *ListenerContext, routeKinds ...gwapiv1.Kind) { - canSupportKinds := make([]gwapiv1.RouteGroupKind, len(routeKinds)) +func (t *Translator) validateAllowedRoutes(listener *ListenerContext, routeKinds ...gwapiv1beta1.Kind) { + canSupportKinds := make([]gwapiv1beta1.RouteGroupKind, len(routeKinds)) for i, routeKind := range routeKinds { - canSupportKinds[i] = gwapiv1.RouteGroupKind{Group: GroupPtr(gwapiv1.GroupName), Kind: routeKind} + canSupportKinds[i] = gwapiv1beta1.RouteGroupKind{Group: GroupPtr(gwapiv1beta1.GroupName), Kind: routeKind} } if listener.AllowedRoutes == nil || len(listener.AllowedRoutes.Kinds) == 0 { listener.SetSupportedKinds(canSupportKinds...) return } - supportedRouteKinds := make([]gwapiv1.Kind, 0) - supportedKinds := make([]gwapiv1.RouteGroupKind, 0) - unSupportedKinds := make([]gwapiv1.RouteGroupKind, 0) + supportedRouteKinds := make([]gwapiv1beta1.Kind, 0) + supportedKinds := make([]gwapiv1beta1.RouteGroupKind, 0) + unSupportedKinds := make([]gwapiv1beta1.RouteGroupKind, 0) for _, kind := range listener.AllowedRoutes.Kinds { // if there is a group it must match `gateway.networking.k8s.io` - if kind.Group != nil && string(*kind.Group) != gwapiv1.GroupName { + if kind.Group != nil && string(*kind.Group) != gwapiv1beta1.GroupName { listener.SetCondition( gwapiv1.ListenerConditionResolvedRefs, metav1.ConditionFalse, gwapiv1.ListenerReasonInvalidRouteKinds, - fmt.Sprintf("Group is not supported, group must be %s", gwapiv1.GroupName), + fmt.Sprintf("Group is not supported, group must be %s", gwapiv1beta1.GroupName), ) continue } @@ -545,7 +545,7 @@ func (t *Translator) validateAllowedRoutes(listener *ListenerContext, routeKinds } for _, kind := range unSupportedKinds { - var printRouteKinds []gwapiv1.Kind + var printRouteKinds []gwapiv1beta1.Kind if len(supportedKinds) == 0 { printRouteKinds = routeKinds } else { @@ -573,7 +573,7 @@ func (t *Translator) validateConflictedMergedListeners(gateways []*GatewayContex listenerSets := sets.Set[string]{} for _, gateway := range gateways { for _, listener := range gateway.listeners { - hostname := new(gwapiv1.Hostname) + hostname := new(gwapiv1beta1.Hostname) if listener.Hostname != nil { hostname = listener.Hostname } @@ -595,7 +595,7 @@ func (t *Translator) validateConflictedLayer7Listeners(gateways []*GatewayContex // Iterate through all layer-7 (HTTP, HTTPS, TLS) listeners and collect info about protocols // and hostnames per port. for _, gateway := range gateways { - portListenerInfo := map[gwapiv1.PortNumber]*portListeners{} + portListenerInfo := map[gwapiv1beta1.PortNumber]*portListeners{} for _, listener := range gateway.listeners { if listener.Protocol == gwapiv1.UDPProtocolType || listener.Protocol == gwapiv1.TCPProtocolType { continue @@ -657,10 +657,10 @@ func (t *Translator) validateConflictedLayer7Listeners(gateways []*GatewayContex } } -func (t *Translator) validateConflictedLayer4Listeners(gateways []*GatewayContext, protocols ...gwapiv1.ProtocolType) { +func (t *Translator) validateConflictedLayer4Listeners(gateways []*GatewayContext, protocols ...gwapiv1beta1.ProtocolType) { // Iterate through all layer-4(TCP UDP) listeners and check if there are more than one listener on the same port for _, gateway := range gateways { - portListenerInfo := map[gwapiv1.PortNumber]*portListeners{} + portListenerInfo := map[gwapiv1beta1.PortNumber]*portListeners{} for _, listener := range gateway.listeners { for _, protocol := range protocols { if listener.Protocol == protocol { @@ -688,7 +688,7 @@ func (t *Translator) validateConflictedLayer4Listeners(gateways []*GatewayContex } } -func (t *Translator) validateCrossNamespaceRef(from crossNamespaceFrom, to crossNamespaceTo, referenceGrants []*gwapiv1b1.ReferenceGrant) bool { +func (t *Translator) validateCrossNamespaceRef(from crossNamespaceFrom, to crossNamespaceTo, referenceGrants []*gwapiv1beta1.ReferenceGrant) bool { for _, referenceGrant := range referenceGrants { // The ReferenceGrant must be defined in the namespace of // the "to" (the referent). @@ -766,7 +766,7 @@ func (t *Translator) validateHostname(hostname string) error { func (t *Translator) validateSecretRef( allowCrossNamespace bool, from crossNamespaceFrom, - secretObjRef gwapiv1b1.SecretObjectReference, + secretObjRef gwapiv1beta1.SecretObjectReference, resources *Resources) (*v1.Secret, error) { if err := t.validateSecretObjectRef(allowCrossNamespace, from, secretObjRef, resources); err != nil { @@ -790,7 +790,7 @@ func (t *Translator) validateSecretRef( func (t *Translator) validateConfigMapRef( allowCrossNamespace bool, from crossNamespaceFrom, - secretObjRef gwapiv1b1.SecretObjectReference, + secretObjRef gwapiv1beta1.SecretObjectReference, resources *Resources) (*v1.ConfigMap, error) { if err := t.validateSecretObjectRef(allowCrossNamespace, from, secretObjRef, resources); err != nil { @@ -814,7 +814,7 @@ func (t *Translator) validateConfigMapRef( func (t *Translator) validateSecretObjectRef( allowCrossNamespace bool, from crossNamespaceFrom, - secretRef gwapiv1b1.SecretObjectReference, + secretRef gwapiv1beta1.SecretObjectReference, resources *Resources) error { var kind string if secretRef.Group != nil && string(*secretRef.Group) != "" { @@ -873,7 +873,7 @@ func (t *Translator) validateSecretObjectRef( // 5. The cross-namespace reference is permitted by the ReferenceGrants if the // namespace is different from the policy's namespace. func (t *Translator) validateExtServiceBackendReference( - backendRef *gwapiv1.BackendObjectReference, + backendRef *gwapiv1beta1.BackendObjectReference, ownerNamespace string, resources *Resources) error { diff --git a/internal/gatewayapi/zz_generated.deepcopy.go b/internal/gatewayapi/zz_generated.deepcopy.go index f08a7044fdba..f1f9e22956e4 100644 --- a/internal/gatewayapi/zz_generated.deepcopy.go +++ b/internal/gatewayapi/zz_generated.deepcopy.go @@ -16,7 +16,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/gateway-api/apis/v1beta1" "sigs.k8s.io/gateway-api/apis/v1alpha2" - "sigs.k8s.io/gateway-api/apis/v1beta1" "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" ) @@ -25,27 +24,27 @@ func (in *Resources) DeepCopyInto(out *Resources) { *out = *in if in.GatewayClass != nil { in, out := &in.GatewayClass, &out.GatewayClass - *out = new(v1.GatewayClass) + *out = new(v1beta1.GatewayClass) (*in).DeepCopyInto(*out) } if in.Gateways != nil { in, out := &in.Gateways, &out.Gateways - *out = make([]*v1.Gateway, len(*in)) + *out = make([]*v1beta1.Gateway, len(*in)) for i := range *in { if (*in)[i] != nil { in, out := &(*in)[i], &(*out)[i] - *out = new(v1.Gateway) + *out = new(v1beta1.Gateway) (*in).DeepCopyInto(*out) } } } if in.HTTPRoutes != nil { in, out := &in.HTTPRoutes, &out.HTTPRoutes - *out = make([]*v1.HTTPRoute, len(*in)) + *out = make([]*v1beta1.HTTPRoute, len(*in)) for i := range *in { if (*in)[i] != nil { in, out := &(*in)[i], &(*out)[i] - *out = new(v1.HTTPRoute) + *out = new(v1beta1.HTTPRoute) (*in).DeepCopyInto(*out) } } diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index eb96161b3c77..3ffdd30f90fa 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -27,8 +27,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" mcsapi "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" @@ -47,7 +47,7 @@ type gatewayAPIReconciler struct { client client.Client log logging.Logger statusUpdater status.Updater - classController gwapiv1.GatewayController + classController gwapiv1b1.GatewayController store *kubernetesProviderStore namespace string namespaceLabel *metav1.LabelSelector @@ -81,7 +81,7 @@ func newGatewayAPIController(mgr manager.Manager, cfg *config.Server, su status. r := &gatewayAPIReconciler{ client: mgr.GetClient(), log: cfg.Logger, - classController: gwapiv1.GatewayController(cfg.EnvoyGateway.Gateway.ControllerName), + classController: gwapiv1b1.GatewayController(cfg.EnvoyGateway.Gateway.ControllerName), namespace: cfg.Namespace, statusUpdater: su, resources: resources, @@ -115,7 +115,7 @@ type resourceMappings struct { // Map for storing namespaces for Route, Service and Gateway objects. allAssociatedNamespaces map[string]struct{} // Map for storing backendRefs' NamespaceNames referred by various Route objects. - allAssociatedBackendRefs map[gwapiv1.BackendObjectReference]struct{} + allAssociatedBackendRefs map[gwapiv1b1.BackendObjectReference]struct{} // extensionRefFilters is a map of filters managed by an extension. // The key is the namespaced name of the filter and the value is the // unstructured form of the resource. @@ -125,7 +125,7 @@ type resourceMappings struct { func newResourceMapping() *resourceMappings { return &resourceMappings{ allAssociatedNamespaces: map[string]struct{}{}, - allAssociatedBackendRefs: map[gwapiv1.BackendObjectReference]struct{}{}, + allAssociatedBackendRefs: map[gwapiv1b1.BackendObjectReference]struct{}{}, extensionRefFilters: map[types.NamespacedName]unstructured.Unstructured{}, } } @@ -135,7 +135,7 @@ func newResourceMapping() *resourceMappings { // be handled by a single call to Reconcile. The reconcile.Request DOES NOT map to a specific resource. func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Request) (reconcile.Result, error) { var ( - managedGCs []*gwapiv1.GatewayClass + managedGCs []*gwapiv1b1.GatewayClass err error ) r.log.Info("reconciling gateways") @@ -274,8 +274,8 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques } // managedGatewayClasses returns a list of GatewayClass objects that are managed by the Envoy Gateway Controller. -func (r *gatewayAPIReconciler) managedGatewayClasses(ctx context.Context) ([]*gwapiv1.GatewayClass, error) { - var gatewayClasses gwapiv1.GatewayClassList +func (r *gatewayAPIReconciler) managedGatewayClasses(ctx context.Context) ([]*gwapiv1b1.GatewayClass, error) { + var gatewayClasses gwapiv1b1.GatewayClassList if err := r.client.List(ctx, &gatewayClasses); err != nil { return nil, fmt.Errorf("error listing gatewayclasses: %w", err) } @@ -416,7 +416,7 @@ func (r *gatewayAPIReconciler) processSecurityPolicyObjectRefs( // Add the referenced BackendRefs and ReferenceGrants in ExtAuth to Maps for later processing extAuth := policy.Spec.ExtAuth if extAuth != nil { - var backendRef gwapiv1.BackendObjectReference + var backendRef gwapiv1b1.BackendObjectReference if extAuth.GRPC != nil { backendRef = extAuth.GRPC.BackendRef } else { @@ -424,7 +424,7 @@ func (r *gatewayAPIReconciler) processSecurityPolicyObjectRefs( } backendNamespace := gatewayapi.NamespaceDerefOr(backendRef.Namespace, policy.Namespace) - resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ + resourceMap.allAssociatedBackendRefs[gwapiv1b1.BackendObjectReference{ Group: backendRef.Group, Kind: backendRef.Kind, Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), @@ -690,10 +690,10 @@ func (r *gatewayAPIReconciler) findReferenceGrant(ctx context.Context, from, to return nil, nil } -func (r *gatewayAPIReconciler) processGateways(ctx context.Context, managedGC *gwapiv1.GatewayClass, resourceMap *resourceMappings, resourceTree *gatewayapi.Resources) error { +func (r *gatewayAPIReconciler) processGateways(ctx context.Context, managedGC *gwapiv1b1.GatewayClass, resourceMap *resourceMappings, resourceTree *gatewayapi.Resources) error { // Find gateways for the managedGC // Find the Gateways that reference this Class. - gatewayList := &gwapiv1.GatewayList{} + gatewayList := &gwapiv1b1.GatewayList{} if err := r.client.List(ctx, gatewayList, &client.ListOptions{ FieldSelector: fields.OneTermEqualSelector(classGatewayIndex, managedGC.Name), }); err != nil { @@ -767,7 +767,7 @@ func (r *gatewayAPIReconciler) processGateways(ctx context.Context, managedGC *g // Discard Status to reduce memory consumption in watchable // It will be recomputed by the gateway-api layer - gtw.Status = gwapiv1.GatewayStatus{} + gtw.Status = gwapiv1b1.GatewayStatus{} resourceTree.Gateways = append(resourceTree.Gateways, >w) } @@ -876,7 +876,7 @@ func (r *gatewayAPIReconciler) processBackendTLSPolicies( } // removeFinalizer removes the gatewayclass finalizer from the provided gc, if it exists. -func (r *gatewayAPIReconciler) removeFinalizer(ctx context.Context, gc *gwapiv1.GatewayClass) error { +func (r *gatewayAPIReconciler) removeFinalizer(ctx context.Context, gc *gwapiv1b1.GatewayClass) error { if slice.ContainsString(gc.Finalizers, gatewayClassFinalizer) { base := client.MergeFrom(gc.DeepCopy()) gc.Finalizers = slice.RemoveString(gc.Finalizers, gatewayClassFinalizer) @@ -888,7 +888,7 @@ func (r *gatewayAPIReconciler) removeFinalizer(ctx context.Context, gc *gwapiv1. } // addFinalizer adds the gatewayclass finalizer to the provided gc, if it doesn't exist. -func (r *gatewayAPIReconciler) addFinalizer(ctx context.Context, gc *gwapiv1.GatewayClass) error { +func (r *gatewayAPIReconciler) addFinalizer(ctx context.Context, gc *gwapiv1b1.GatewayClass) error { if !slice.ContainsString(gc.Finalizers, gatewayClassFinalizer) { base := client.MergeFrom(gc.DeepCopy()) gc.Finalizers = append(gc.Finalizers, gatewayClassFinalizer) @@ -902,7 +902,7 @@ func (r *gatewayAPIReconciler) addFinalizer(ctx context.Context, gc *gwapiv1.Gat // watchResources watches gateway api resources. func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.Manager, c controller.Controller) error { if err := c.Watch( - source.Kind(mgr.GetCache(), &gwapiv1.GatewayClass{}), + source.Kind(mgr.GetCache(), &gwapiv1b1.GatewayClass{}), handler.EnqueueRequestsFromMapFunc(r.enqueueClass), predicate.GenerationChangedPredicate{}, predicate.NewPredicateFuncs(r.hasMatchingController), @@ -936,7 +936,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M gPredicates = append(gPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels)) } if err := c.Watch( - source.Kind(mgr.GetCache(), &gwapiv1.Gateway{}), + source.Kind(mgr.GetCache(), &gwapiv1b1.Gateway{}), handler.EnqueueRequestsFromMapFunc(r.enqueueClass), gPredicates..., ); err != nil { @@ -952,7 +952,7 @@ func (r *gatewayAPIReconciler) watchResources(ctx context.Context, mgr manager.M httprPredicates = append(httprPredicates, predicate.NewPredicateFuncs(r.hasMatchingNamespaceLabels)) } if err := c.Watch( - source.Kind(mgr.GetCache(), &gwapiv1.HTTPRoute{}), + source.Kind(mgr.GetCache(), &gwapiv1b1.HTTPRoute{}), handler.EnqueueRequestsFromMapFunc(r.enqueueClass), httprPredicates..., ); err != nil { @@ -1274,7 +1274,7 @@ func (r *gatewayAPIReconciler) hasManagedClass(obj client.Object) bool { return false } - gcList := new(gwapiv1.GatewayClassList) + gcList := new(gwapiv1b1.GatewayClassList) err := r.client.List(context.TODO(), gcList) if err != nil { r.log.Error(err, "failed to list gatewayclasses") @@ -1295,7 +1295,7 @@ func (r *gatewayAPIReconciler) hasManagedClass(obj client.Object) bool { } // processParamsRef processes the parametersRef of the provided GatewayClass. -func (r *gatewayAPIReconciler) processParamsRef(ctx context.Context, gc *gwapiv1.GatewayClass, resourceTree *gatewayapi.Resources) error { +func (r *gatewayAPIReconciler) processParamsRef(ctx context.Context, gc *gwapiv1b1.GatewayClass, resourceTree *gatewayapi.Resources) error { if !refsEnvoyProxy(gc) { return fmt.Errorf("unsupported parametersRef for gatewayclass %s", gc.Name) } diff --git a/internal/provider/kubernetes/controller_test.go b/internal/provider/kubernetes/controller_test.go index 691a70812491..1b6c4757bae2 100644 --- a/internal/provider/kubernetes/controller_test.go +++ b/internal/provider/kubernetes/controller_test.go @@ -14,7 +14,8 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/envoygateway" @@ -26,16 +27,16 @@ import ( func TestAddGatewayClassFinalizer(t *testing.T) { testCases := []struct { name string - gc *gwapiv1.GatewayClass + gc *gwapiv1b1.GatewayClass expect []string }{ { name: "gatewayclass with no finalizers", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: egv1a1.GatewayControllerName, }, }, @@ -43,12 +44,12 @@ func TestAddGatewayClassFinalizer(t *testing.T) { }, { name: "gatewayclass with a different finalizer", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", Finalizers: []string{"fooFinalizer"}, }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: egv1a1.GatewayControllerName, }, }, @@ -56,12 +57,12 @@ func TestAddGatewayClassFinalizer(t *testing.T) { }, { name: "gatewayclass with existing gatewayclass finalizer", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", Finalizers: []string{gatewayClassFinalizer}, }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: egv1a1.GatewayControllerName, }, }, @@ -90,16 +91,16 @@ func TestAddGatewayClassFinalizer(t *testing.T) { func TestRemoveGatewayClassFinalizer(t *testing.T) { testCases := []struct { name string - gc *gwapiv1.GatewayClass + gc *gwapiv1b1.GatewayClass expect []string }{ { name: "gatewayclass with no finalizers", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: egv1a1.GatewayControllerName, }, }, @@ -107,12 +108,12 @@ func TestRemoveGatewayClassFinalizer(t *testing.T) { }, { name: "gatewayclass with a different finalizer", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", Finalizers: []string{"fooFinalizer"}, }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: egv1a1.GatewayControllerName, }, }, @@ -120,12 +121,12 @@ func TestRemoveGatewayClassFinalizer(t *testing.T) { }, { name: "gatewayclass with existing gatewayclass finalizer", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", Finalizers: []string{gatewayClassFinalizer}, }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: egv1a1.GatewayControllerName, }, }, @@ -152,12 +153,12 @@ func TestRemoveGatewayClassFinalizer(t *testing.T) { } func TestHasManagedClass(t *testing.T) { - gcCtrlName := gwapiv1.GatewayController(egv1a1.GatewayControllerName) + gcCtrlName := gwapiv1b1.GatewayController(egv1a1.GatewayControllerName) testCases := []struct { name string ep client.Object - classes []*gwapiv1.GatewayClass + classes []*gwapiv1b1.GatewayClass expected bool }{ { @@ -168,21 +169,21 @@ func TestHasManagedClass(t *testing.T) { Name: "test-envoyproxy", }, }, - classes: []*gwapiv1.GatewayClass{ + classes: []*gwapiv1b1.GatewayClass{ { ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: "SomeOtherController", - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test-envoyproxy", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: string(gwapiv1.GatewayClassConditionStatusAccepted), @@ -202,21 +203,21 @@ func TestHasManagedClass(t *testing.T) { Name: "test-envoyproxy", }, }, - classes: []*gwapiv1.GatewayClass{ + classes: []*gwapiv1b1.GatewayClass{ { ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test-envoyproxy", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: string(gwapiv1.GatewayClassConditionStatusAccepted), @@ -236,12 +237,12 @@ func TestHasManagedClass(t *testing.T) { Name: "test-envoyproxy", }, }, - classes: []*gwapiv1.GatewayClass{ + classes: []*gwapiv1b1.GatewayClass{ { ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ControllerName: gcCtrlName}, + Spec: gwapiv1b1.GatewayClassSpec{ControllerName: gcCtrlName}, }, }, expected: false, @@ -254,21 +255,21 @@ func TestHasManagedClass(t *testing.T) { Name: "test-envoyproxy", }, }, - classes: []*gwapiv1.GatewayClass{ + classes: []*gwapiv1b1.GatewayClass{ { ObjectMeta: metav1.ObjectMeta{ Name: "test-gc1", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test-envoyproxy", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: string(gwapiv1.GatewayClassConditionStatusAccepted), @@ -281,16 +282,16 @@ func TestHasManagedClass(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "test-gc2", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test-envoyproxy", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: string(gwapiv1.GatewayClassConditionStatusAccepted), @@ -337,25 +338,25 @@ func TestHasManagedClass(t *testing.T) { } func TestProcessParamsRef(t *testing.T) { - gcCtrlName := gwapiv1.GatewayController(egv1a1.GatewayControllerName) + gcCtrlName := gwapiv1b1.GatewayController(egv1a1.GatewayControllerName) testCases := []struct { name string - gc *gwapiv1.GatewayClass + gc *gwapiv1b1.GatewayClass ep *egv1a1.EnvoyProxy expected bool }{ { name: "valid envoyproxy reference", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -371,15 +372,15 @@ func TestProcessParamsRef(t *testing.T) { }, { name: "envoyproxy kind does not exist", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -389,15 +390,15 @@ func TestProcessParamsRef(t *testing.T) { }, { name: "referenced envoyproxy does not exist", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "non-exist", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -413,15 +414,15 @@ func TestProcessParamsRef(t *testing.T) { }, { name: "invalid gatewayclass parameters ref", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group("UnSupportedGroup"), - Kind: gwapiv1.Kind("UnSupportedKind"), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group("UnSupportedGroup"), + Kind: gwapiv1b1.Kind("UnSupportedKind"), Name: "test", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, diff --git a/internal/provider/kubernetes/helpers.go b/internal/provider/kubernetes/helpers.go index 6200c3ca647c..4481ca3911bf 100644 --- a/internal/provider/kubernetes/helpers.go +++ b/internal/provider/kubernetes/helpers.go @@ -13,7 +13,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" mcsapi "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" @@ -35,16 +36,16 @@ type ObjectKindNamespacedName struct { // referenced Gateways managed by Envoy Gateway. The only supported parentRef // is a Gateway. func validateParentRefs(ctx context.Context, client client.Client, namespace string, - gatewayClassController gwapiv1.GatewayController, - routeParentReferences []gwapiv1.ParentReference) ([]gwapiv1.Gateway, error) { + gatewayClassController gwapiv1beta1.GatewayController, + routeParentReferences []gwapiv1beta1.ParentReference) ([]gwapiv1beta1.Gateway, error) { - var gateways []gwapiv1.Gateway + var gateways []gwapiv1beta1.Gateway for i := range routeParentReferences { ref := routeParentReferences[i] if ref.Kind != nil && *ref.Kind != "Gateway" { return nil, fmt.Errorf("invalid Kind %q", *ref.Kind) } - if ref.Group != nil && *ref.Group != gwapiv1.GroupName { + if ref.Group != nil && *ref.Group != gwapiv1beta1.GroupName { return nil, fmt.Errorf("invalid Group %q", *ref.Group) } @@ -59,13 +60,13 @@ func validateParentRefs(ctx context.Context, client client.Client, namespace str Name: string(ref.Name), } - gw := new(gwapiv1.Gateway) + gw := new(gwapiv1beta1.Gateway) if err := client.Get(ctx, gwKey, gw); err != nil { return nil, fmt.Errorf("failed to get gateway %s/%s: %w", gwKey.Namespace, gwKey.Name, err) } gcKey := types.NamespacedName{Name: string(gw.Spec.GatewayClassName)} - gc := new(gwapiv1.GatewayClass) + gc := new(gwapiv1beta1.GatewayClass) if err := client.Get(ctx, gcKey, gc); err != nil { return nil, fmt.Errorf("failed to get gatewayclass %s: %w", gcKey.Name, err) } @@ -79,14 +80,14 @@ func validateParentRefs(ctx context.Context, client client.Client, namespace str type controlledClasses struct { // matchedClasses holds all GatewayClass objects with matching controllerName. - matchedClasses []*gwapiv1.GatewayClass + matchedClasses []*gwapiv1beta1.GatewayClass } -func (cc *controlledClasses) addMatch(gc *gwapiv1.GatewayClass) { +func (cc *controlledClasses) addMatch(gc *gwapiv1beta1.GatewayClass) { cc.matchedClasses = append(cc.matchedClasses, gc) } -func (cc *controlledClasses) removeMatch(gc *gwapiv1.GatewayClass) { +func (cc *controlledClasses) removeMatch(gc *gwapiv1beta1.GatewayClass) { // First remove gc from matchedClasses. for i, matchedGC := range cc.matchedClasses { if matchedGC.Name == gc.Name { @@ -99,7 +100,7 @@ func (cc *controlledClasses) removeMatch(gc *gwapiv1.GatewayClass) { // isAccepted returns true if the provided gatewayclass contains the Accepted=true // status condition. -func isAccepted(gc *gwapiv1.GatewayClass) bool { +func isAccepted(gc *gwapiv1beta1.GatewayClass) bool { if gc == nil { return false } @@ -112,8 +113,8 @@ func isAccepted(gc *gwapiv1.GatewayClass) bool { } // gatewaysOfClass returns a list of gateways that reference gc from the provided gwList. -func gatewaysOfClass(gc *gwapiv1.GatewayClass, gwList *gwapiv1.GatewayList) []gwapiv1.Gateway { - var gateways []gwapiv1.Gateway +func gatewaysOfClass(gc *gwapiv1beta1.GatewayClass, gwList *gwapiv1beta1.GatewayList) []gwapiv1beta1.Gateway { + var gateways []gwapiv1beta1.Gateway if gwList == nil || gc == nil { return gateways } @@ -128,7 +129,7 @@ func gatewaysOfClass(gc *gwapiv1.GatewayClass, gwList *gwapiv1.GatewayList) []gw // terminatesTLS returns true if the provided gateway contains a listener configured // for TLS termination. -func terminatesTLS(listener *gwapiv1.Listener) bool { +func terminatesTLS(listener *gwapiv1beta1.Listener) bool { if listener.TLS != nil && (listener.Protocol == gwapiv1.HTTPSProtocolType || listener.Protocol == gwapiv1.TLSProtocolType) && @@ -140,7 +141,7 @@ func terminatesTLS(listener *gwapiv1.Listener) bool { } // refsSecret returns true if ref refers to a Secret. -func refsSecret(ref *gwapiv1.SecretObjectReference) bool { +func refsSecret(ref *gwapiv1beta1.SecretObjectReference) bool { return (ref.Group == nil || *ref.Group == corev1.GroupName) && (ref.Kind == nil || *ref.Kind == gatewayapi.KindSecret) } @@ -148,7 +149,7 @@ func refsSecret(ref *gwapiv1.SecretObjectReference) bool { // infraName returns expected name for the EnvoyProxy infra resources. // By default it returns hashed string from {GatewayNamespace}/{GatewayName}, // but if mergeGateways is set, it will return hashed string of {GatewayClassName}. -func infraName(gateway *gwapiv1.Gateway, merged bool) string { +func infraName(gateway *gwapiv1beta1.Gateway, merged bool) string { if merged { return proxy.ExpectedResourceHashedName(string(gateway.Spec.GatewayClassName)) } @@ -161,7 +162,7 @@ func infraName(gateway *gwapiv1.Gateway, merged bool) string { // - Validating weights. // - Validating ports. // - Referencing HTTPRoutes. -func validateBackendRef(ref *gwapiv1.BackendRef) error { +func validateBackendRef(ref *gwapiv1beta1.BackendRef) error { switch { case ref == nil: return nil @@ -176,7 +177,7 @@ func validateBackendRef(ref *gwapiv1.BackendRef) error { } // classRefsEnvoyProxy returns true if the provided GatewayClass references the provided EnvoyProxy. -func classRefsEnvoyProxy(gc *gwapiv1.GatewayClass, ep *egv1a1.EnvoyProxy) bool { +func classRefsEnvoyProxy(gc *gwapiv1beta1.GatewayClass, ep *egv1a1.EnvoyProxy) bool { if gc == nil || ep == nil { return false } @@ -187,7 +188,7 @@ func classRefsEnvoyProxy(gc *gwapiv1.GatewayClass, ep *egv1a1.EnvoyProxy) bool { } // refsEnvoyProxy returns true if the provided GatewayClass references an EnvoyProxy. -func refsEnvoyProxy(gc *gwapiv1.GatewayClass) bool { +func refsEnvoyProxy(gc *gwapiv1beta1.GatewayClass) bool { if gc == nil { return false } @@ -200,7 +201,7 @@ func refsEnvoyProxy(gc *gwapiv1.GatewayClass) bool { } // classAccepted returns true if the provided GatewayClass is accepted. -func classAccepted(gc *gwapiv1.GatewayClass) bool { +func classAccepted(gc *gwapiv1beta1.GatewayClass) bool { if gc == nil { return false } diff --git a/internal/provider/kubernetes/helpers_test.go b/internal/provider/kubernetes/helpers_test.go index ef6736bca037..57a7df1603f0 100644 --- a/internal/provider/kubernetes/helpers_test.go +++ b/internal/provider/kubernetes/helpers_test.go @@ -10,7 +10,8 @@ import ( "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/envoygateway/config" @@ -18,26 +19,26 @@ import ( ) func TestGatewaysOfClass(t *testing.T) { - gc := &gwapiv1.GatewayClass{ + gc := &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, } testCases := []struct { name string - gws []gwapiv1.Gateway + gws []gwapiv1b1.Gateway expect int }{ { name: "no matching gateways", - gws: []gwapiv1.Gateway{ + gws: []gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewaySpec{ - GatewayClassName: gwapiv1.ObjectName("no-match"), + Spec: gwapiv1b1.GatewaySpec{ + GatewayClassName: gwapiv1b1.ObjectName("no-match"), }, }, { @@ -45,8 +46,8 @@ func TestGatewaysOfClass(t *testing.T) { Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewaySpec{ - GatewayClassName: gwapiv1.ObjectName("no-match2"), + Spec: gwapiv1b1.GatewaySpec{ + GatewayClassName: gwapiv1b1.ObjectName("no-match2"), }, }, }, @@ -54,14 +55,14 @@ func TestGatewaysOfClass(t *testing.T) { }, { name: "one of two matching gateways", - gws: []gwapiv1.Gateway{ + gws: []gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewaySpec{ - GatewayClassName: gwapiv1.ObjectName(gc.Name), + Spec: gwapiv1b1.GatewaySpec{ + GatewayClassName: gwapiv1b1.ObjectName(gc.Name), }, }, { @@ -69,8 +70,8 @@ func TestGatewaysOfClass(t *testing.T) { Name: "test2", Namespace: "test", }, - Spec: gwapiv1.GatewaySpec{ - GatewayClassName: gwapiv1.ObjectName("no-match"), + Spec: gwapiv1b1.GatewaySpec{ + GatewayClassName: gwapiv1b1.ObjectName("no-match"), }, }, }, @@ -78,14 +79,14 @@ func TestGatewaysOfClass(t *testing.T) { }, { name: "two of two matching gateways", - gws: []gwapiv1.Gateway{ + gws: []gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewaySpec{ - GatewayClassName: gwapiv1.ObjectName(gc.Name), + Spec: gwapiv1b1.GatewaySpec{ + GatewayClassName: gwapiv1b1.ObjectName(gc.Name), }, }, { @@ -93,8 +94,8 @@ func TestGatewaysOfClass(t *testing.T) { Name: "test2", Namespace: "test", }, - Spec: gwapiv1.GatewaySpec{ - GatewayClassName: gwapiv1.ObjectName(gc.Name), + Spec: gwapiv1b1.GatewaySpec{ + GatewayClassName: gwapiv1b1.ObjectName(gc.Name), }, }, }, @@ -105,7 +106,7 @@ func TestGatewaysOfClass(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.name, func(t *testing.T) { - gwList := &gwapiv1.GatewayList{Items: tc.gws} + gwList := &gwapiv1b1.GatewayList{Items: tc.gws} actual := gatewaysOfClass(gc, gwList) require.Len(t, actual, tc.expect) }) @@ -115,19 +116,19 @@ func TestGatewaysOfClass(t *testing.T) { func TestIsGatewayClassAccepted(t *testing.T) { testCases := []struct { name string - gc *gwapiv1.GatewayClass + gc *gwapiv1b1.GatewayClass expect bool }{ { name: "gatewayclass accepted condition", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ - ControllerName: gwapiv1.GatewayController(egv1a1.GatewayControllerName), + Spec: gwapiv1b1.GatewayClassSpec{ + ControllerName: gwapiv1b1.GatewayController(egv1a1.GatewayControllerName), }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: string(gwapiv1.GatewayClassConditionStatusAccepted), @@ -140,14 +141,14 @@ func TestIsGatewayClassAccepted(t *testing.T) { }, { name: "gatewayclass not accepted condition", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ - ControllerName: gwapiv1.GatewayController(egv1a1.GatewayControllerName), + Spec: gwapiv1b1.GatewayClassSpec{ + ControllerName: gwapiv1b1.GatewayController(egv1a1.GatewayControllerName), }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: string(gwapiv1.GatewayClassConditionStatusAccepted), @@ -160,14 +161,14 @@ func TestIsGatewayClassAccepted(t *testing.T) { }, { name: "no gatewayclass accepted condition type", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ - ControllerName: gwapiv1.GatewayController(egv1a1.GatewayControllerName), + Spec: gwapiv1b1.GatewayClassSpec{ + ControllerName: gwapiv1b1.GatewayController(egv1a1.GatewayControllerName), }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: "SomeOtherType", @@ -196,7 +197,7 @@ func TestIsGatewayClassAccepted(t *testing.T) { func TestRefsEnvoyProxy(t *testing.T) { testCases := []struct { name string - gc *gwapiv1.GatewayClass + gc *gwapiv1b1.GatewayClass expect bool }{ { @@ -206,16 +207,16 @@ func TestRefsEnvoyProxy(t *testing.T) { }, { name: "valid envoyproxy parameters ref", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: "test", - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -225,12 +226,12 @@ func TestRefsEnvoyProxy(t *testing.T) { }, { name: "unspecified parameters ref", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: "test", }, }, @@ -238,16 +239,16 @@ func TestRefsEnvoyProxy(t *testing.T) { }, { name: "unsupported group parameters ref", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: "test", - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group("Unsupported"), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group("Unsupported"), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -257,16 +258,16 @@ func TestRefsEnvoyProxy(t *testing.T) { }, { name: "unsupported group parameters ref", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: "test", - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind("Unsupported"), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind("Unsupported"), Name: "test", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -276,16 +277,16 @@ func TestRefsEnvoyProxy(t *testing.T) { }, { name: "unsupported group parameters ref", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: "test", - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind("Unsupported"), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind("Unsupported"), Name: "test", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -295,16 +296,16 @@ func TestRefsEnvoyProxy(t *testing.T) { }, { name: "empty parameters ref name", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: "test", - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -314,16 +315,16 @@ func TestRefsEnvoyProxy(t *testing.T) { }, { name: "unspecified parameters ref namespace", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", Namespace: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: "test", - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test", }, }, @@ -342,11 +343,11 @@ func TestRefsEnvoyProxy(t *testing.T) { } func TestClassRefsEnvoyProxy(t *testing.T) { - gcCtrlName := gwapiv1.GatewayController(egv1a1.GatewayControllerName) + gcCtrlName := gwapiv1b1.GatewayController(egv1a1.GatewayControllerName) testCases := []struct { name string - gc *gwapiv1.GatewayClass + gc *gwapiv1b1.GatewayClass ep *egv1a1.EnvoyProxy expected bool }{ @@ -358,15 +359,15 @@ func TestClassRefsEnvoyProxy(t *testing.T) { }, { name: "gatewayclass references envoyproxy", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test-ep", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -382,15 +383,15 @@ func TestClassRefsEnvoyProxy(t *testing.T) { }, { name: "gatewayclass does not reference envoyproxy", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "not-test-ep", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -406,15 +407,15 @@ func TestClassRefsEnvoyProxy(t *testing.T) { }, { name: "gatewayclass references invalid kind", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind("UnsupportedKind"), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind("UnsupportedKind"), Name: "test-ep", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -430,15 +431,15 @@ func TestClassRefsEnvoyProxy(t *testing.T) { }, { name: "gatewayclass references invalid group", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group("UnsupportedGroup"), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group("UnsupportedGroup"), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test-ep", Namespace: gatewayapi.NamespacePtr(config.DefaultNamespace), }, @@ -454,15 +455,15 @@ func TestClassRefsEnvoyProxy(t *testing.T) { }, { name: "gatewayclass references envoyproxy without namespace", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, - ParametersRef: &gwapiv1.ParametersReference{ - Group: gwapiv1.Group(egv1a1.GroupVersion.Group), - Kind: gwapiv1.Kind(egv1a1.KindEnvoyProxy), + ParametersRef: &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), + Kind: gwapiv1b1.Kind(egv1a1.KindEnvoyProxy), Name: "test-ep", }, }, @@ -490,11 +491,11 @@ func TestClassRefsEnvoyProxy(t *testing.T) { } func TestClassAccepted(t *testing.T) { - gcCtrlName := gwapiv1.GatewayController(egv1a1.GatewayControllerName) + gcCtrlName := gwapiv1b1.GatewayController(egv1a1.GatewayControllerName) testCases := []struct { name string - gc *gwapiv1.GatewayClass + gc *gwapiv1b1.GatewayClass expected bool }{ { @@ -504,14 +505,14 @@ func TestClassAccepted(t *testing.T) { }, { name: "gatewayclass accepted", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: string(gwapiv1.GatewayClassConditionStatusAccepted), @@ -524,14 +525,14 @@ func TestClassAccepted(t *testing.T) { }, { name: "gatewayclass not accepted", - gc: &gwapiv1.GatewayClass{ + gc: &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test-gc", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, }, - Status: gwapiv1.GatewayClassStatus{ + Status: gwapiv1b1.GatewayClassStatus{ Conditions: []metav1.Condition{ { Type: string(gwapiv1.GatewayClassConditionStatusAccepted), diff --git a/internal/provider/kubernetes/indexers.go b/internal/provider/kubernetes/indexers.go index faa8f2f93c7a..8df741430e13 100644 --- a/internal/provider/kubernetes/indexers.go +++ b/internal/provider/kubernetes/indexers.go @@ -11,8 +11,8 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/api/v1alpha1" @@ -58,11 +58,11 @@ func addReferenceGrantIndexers(ctx context.Context, mgr manager.Manager) error { // - For Service, ServiceImports objects that are referenced in HTTPRoute objects via `.spec.rules.backendRefs`. // This helps in querying for HTTPRoutes that are affected by a particular Service CRUD. func addHTTPRouteIndexers(ctx context.Context, mgr manager.Manager) error { - if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1.HTTPRoute{}, gatewayHTTPRouteIndex, gatewayHTTPRouteIndexFunc); err != nil { + if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1b1.HTTPRoute{}, gatewayHTTPRouteIndex, gatewayHTTPRouteIndexFunc); err != nil { return err } - if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1.HTTPRoute{}, backendHTTPRouteIndex, backendHTTPRouteIndexFunc); err != nil { + if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1b1.HTTPRoute{}, backendHTTPRouteIndex, backendHTTPRouteIndexFunc); err != nil { return err } @@ -70,7 +70,7 @@ func addHTTPRouteIndexers(ctx context.Context, mgr manager.Manager) error { } func gatewayHTTPRouteIndexFunc(rawObj client.Object) []string { - httproute := rawObj.(*gwapiv1.HTTPRoute) + httproute := rawObj.(*gwapiv1b1.HTTPRoute) var gateways []string for _, parent := range httproute.Spec.ParentRefs { if parent.Kind == nil || string(*parent.Kind) == gatewayapi.KindGateway { @@ -88,7 +88,7 @@ func gatewayHTTPRouteIndexFunc(rawObj client.Object) []string { } func backendHTTPRouteIndexFunc(rawObj client.Object) []string { - httproute := rawObj.(*gwapiv1.HTTPRoute) + httproute := rawObj.(*gwapiv1b1.HTTPRoute) var backendRefs []string for _, rule := range httproute.Spec.Rules { for _, backend := range rule.BackendRefs { @@ -316,12 +316,12 @@ func backendUDPRouteIndexFunc(rawObj client.Object) []string { // referenced in Gateway objects. This helps in querying for Gateways that are // affected by a particular Secret CRUD. func addGatewayIndexers(ctx context.Context, mgr manager.Manager) error { - if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1.Gateway{}, secretGatewayIndex, secretGatewayIndexFunc); err != nil { + if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1b1.Gateway{}, secretGatewayIndex, secretGatewayIndexFunc); err != nil { return err } - if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1.Gateway{}, classGatewayIndex, func(rawObj client.Object) []string { - gateway := rawObj.(*gwapiv1.Gateway) + if err := mgr.GetFieldIndexer().IndexField(ctx, &gwapiv1b1.Gateway{}, classGatewayIndex, func(rawObj client.Object) []string { + gateway := rawObj.(*gwapiv1b1.Gateway) return []string{string(gateway.Spec.GatewayClassName)} }); err != nil { return err @@ -330,7 +330,7 @@ func addGatewayIndexers(ctx context.Context, mgr manager.Manager) error { } func secretGatewayIndexFunc(rawObj client.Object) []string { - gateway := rawObj.(*gwapiv1.Gateway) + gateway := rawObj.(*gwapiv1b1.Gateway) var secretReferences []string for _, listener := range gateway.Spec.Listeners { if listener.TLS == nil || *listener.TLS.Mode != gwapiv1.TLSModeTerminate { @@ -406,7 +406,7 @@ func secretSecurityPolicyIndexFunc(rawObj client.Object) []string { func backendSecurityPolicyIndexFunc(rawObj client.Object) []string { securityPolicy := rawObj.(*v1alpha1.SecurityPolicy) - var backendRef *gwapiv1.BackendObjectReference + var backendRef *gwapiv1b1.BackendObjectReference if securityPolicy.Spec.ExtAuth != nil { if securityPolicy.Spec.ExtAuth.HTTP != nil { diff --git a/internal/provider/kubernetes/routes.go b/internal/provider/kubernetes/routes.go index a4ae951d546c..2c9e4924f829 100644 --- a/internal/provider/kubernetes/routes.go +++ b/internal/provider/kubernetes/routes.go @@ -13,8 +13,9 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/internal/gatewayapi" "github.com/envoyproxy/gateway/internal/utils" @@ -54,7 +55,7 @@ func (r *gatewayAPIReconciler) processTLSRoutes(ctx context.Context, gatewayName } backendNamespace := gatewayapi.NamespaceDerefOrAlpha(backendRef.Namespace, tlsRoute.Namespace) - resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ + resourceMap.allAssociatedBackendRefs[gwapiv1b1.BackendObjectReference{ Group: backendRef.BackendObjectReference.Group, Kind: backendRef.BackendObjectReference.Kind, Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), @@ -124,7 +125,7 @@ func (r *gatewayAPIReconciler) processGRPCRoutes(ctx context.Context, gatewayNam } backendNamespace := gatewayapi.NamespaceDerefOr(backendRef.Namespace, grpcRoute.Namespace) - resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ + resourceMap.allAssociatedBackendRefs[gwapiv1b1.BackendObjectReference{ Group: backendRef.BackendObjectReference.Group, Kind: backendRef.BackendObjectReference.Kind, Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), @@ -204,7 +205,7 @@ func (r *gatewayAPIReconciler) processGRPCRoutes(ctx context.Context, gatewayNam // the backend references and pushes the HTTPRoutes to the resourceTree. func (r *gatewayAPIReconciler) processHTTPRoutes(ctx context.Context, gatewayNamespaceName string, resourceMap *resourceMappings, resourceTree *gatewayapi.Resources) error { - httpRouteList := &gwapiv1.HTTPRouteList{} + httpRouteList := &gwapiv1b1.HTTPRouteList{} extensionRefFilters, err := r.getExtensionRefFilters(ctx) if err != nil { @@ -243,7 +244,7 @@ func (r *gatewayAPIReconciler) processHTTPRoutes(ctx context.Context, gatewayNam } backendNamespace := gatewayapi.NamespaceDerefOr(backendRef.Namespace, httpRoute.Namespace) - resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ + resourceMap.allAssociatedBackendRefs[gwapiv1b1.BackendObjectReference{ Group: backendRef.BackendObjectReference.Group, Kind: backendRef.BackendObjectReference.Kind, Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), @@ -299,7 +300,7 @@ func (r *gatewayAPIReconciler) processHTTPRoutes(ctx context.Context, gatewayNam mirrorBackendObj := mirrorFilter.BackendRef // Wrap the filter's BackendObjectReference into a BackendRef so we can use existing tooling to check it weight := int32(1) - mirrorBackendRef := gwapiv1.BackendRef{ + mirrorBackendRef := gwapiv1b1.BackendRef{ BackendObjectReference: mirrorBackendObj, Weight: &weight, } @@ -310,7 +311,7 @@ func (r *gatewayAPIReconciler) processHTTPRoutes(ctx context.Context, gatewayNam } backendNamespace := gatewayapi.NamespaceDerefOr(mirrorBackendRef.Namespace, httpRoute.Namespace) - resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ + resourceMap.allAssociatedBackendRefs[gwapiv1b1.BackendObjectReference{ Group: mirrorBackendRef.BackendObjectReference.Group, Kind: mirrorBackendRef.BackendObjectReference.Kind, Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), @@ -366,7 +367,7 @@ func (r *gatewayAPIReconciler) processHTTPRoutes(ctx context.Context, gatewayNam resourceMap.allAssociatedNamespaces[httpRoute.Namespace] = struct{}{} // Discard Status to reduce memory consumption in watchable // It will be recomputed by the gateway-api layer - httpRoute.Status = gwapiv1.HTTPRouteStatus{} + httpRoute.Status = gwapiv1b1.HTTPRouteStatus{} resourceTree.HTTPRoutes = append(resourceTree.HTTPRoutes, &httpRoute) } @@ -407,7 +408,7 @@ func (r *gatewayAPIReconciler) processTCPRoutes(ctx context.Context, gatewayName } backendNamespace := gatewayapi.NamespaceDerefOrAlpha(backendRef.Namespace, tcpRoute.Namespace) - resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ + resourceMap.allAssociatedBackendRefs[gwapiv1b1.BackendObjectReference{ Group: backendRef.BackendObjectReference.Group, Kind: backendRef.BackendObjectReference.Kind, Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), @@ -477,7 +478,7 @@ func (r *gatewayAPIReconciler) processUDPRoutes(ctx context.Context, gatewayName } backendNamespace := gatewayapi.NamespaceDerefOrAlpha(backendRef.Namespace, udpRoute.Namespace) - resourceMap.allAssociatedBackendRefs[gwapiv1.BackendObjectReference{ + resourceMap.allAssociatedBackendRefs[gwapiv1b1.BackendObjectReference{ Group: backendRef.BackendObjectReference.Group, Kind: backendRef.BackendObjectReference.Kind, Namespace: gatewayapi.NamespacePtrV1Alpha2(backendNamespace), diff --git a/internal/provider/kubernetes/routes_test.go b/internal/provider/kubernetes/routes_test.go index b4b79803bd8c..19f1cb543541 100644 --- a/internal/provider/kubernetes/routes_test.go +++ b/internal/provider/kubernetes/routes_test.go @@ -20,8 +20,9 @@ import ( "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/envoygateway" @@ -37,76 +38,76 @@ func TestProcessHTTPRoutes(t *testing.T) { ) // The gatewayclass configured for the reconciler and referenced by test cases. - gcCtrlName := gwapiv1.GatewayController(egv1a1.GatewayControllerName) - gc := &gwapiv1.GatewayClass{ + gcCtrlName := gwapiv1b1.GatewayController(egv1a1.GatewayControllerName) + gc := &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, }, } // The gateway referenced by test cases. - gw := &gwapiv1.Gateway{ + gw := &gwapiv1b1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.GatewaySpec{ - GatewayClassName: gwapiv1.ObjectName(gc.Name), - Listeners: []gwapiv1.Listener{ + Spec: gwapiv1b1.GatewaySpec{ + GatewayClassName: gwapiv1b1.ObjectName(gc.Name), + Listeners: []gwapiv1b1.Listener{ { Name: "http", Protocol: gwapiv1.HTTPProtocolType, - Port: gwapiv1.PortNumber(int32(8080)), + Port: gwapiv1b1.PortNumber(int32(8080)), }, }, }, } gwNsName := utils.NamespacedName(gw).String() - invalidDuration := gwapiv1.Duration("invalid duration") + invalidDuration := gwapiv1b1.Duration("invalid duration") httpRouteNS := "test" testCases := []struct { name string - routes []*gwapiv1.HTTPRoute + routes []*gwapiv1b1.HTTPRoute extensionFilters []*unstructured.Unstructured extensionAPIGroups []schema.GroupVersionKind expected bool }{ { name: "valid httproute", - routes: []*gwapiv1.HTTPRoute{ + routes: []*gwapiv1b1.HTTPRoute{ { ObjectMeta: metav1.ObjectMeta{ Namespace: httpRouteNS, Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { Name: "test", }, }, }, - Rules: []gwapiv1.HTTPRouteRule{ + Rules: []gwapiv1b1.HTTPRouteRule{ { - Matches: []gwapiv1.HTTPRouteMatch{ + Matches: []gwapiv1b1.HTTPRouteMatch{ { - Path: &gwapiv1.HTTPPathMatch{ + Path: &gwapiv1b1.HTTPPathMatch{ Type: ptr.To(gwapiv1.PathMatchPathPrefix), Value: ptr.To("/"), }, }, }, - BackendRefs: []gwapiv1.HTTPBackendRef{ + BackendRefs: []gwapiv1b1.HTTPBackendRef{ { - BackendRef: gwapiv1.BackendRef{ - BackendObjectReference: gwapiv1.BackendObjectReference{ + BackendRef: gwapiv1b1.BackendRef{ + BackendObjectReference: gwapiv1b1.BackendObjectReference{ Group: gatewayapi.GroupPtr(corev1.GroupName), Kind: gatewayapi.KindPtr(gatewayapi.KindService), Name: "test", @@ -123,44 +124,44 @@ func TestProcessHTTPRoutes(t *testing.T) { }, { name: "httproute with one filter_from_extension", - routes: []*gwapiv1.HTTPRoute{ + routes: []*gwapiv1b1.HTTPRoute{ { ObjectMeta: metav1.ObjectMeta{ Namespace: httpRouteNS, Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { Name: "test", }, }, }, - Rules: []gwapiv1.HTTPRouteRule{ + Rules: []gwapiv1b1.HTTPRouteRule{ { - Matches: []gwapiv1.HTTPRouteMatch{ + Matches: []gwapiv1b1.HTTPRouteMatch{ { - Path: &gwapiv1.HTTPPathMatch{ + Path: &gwapiv1b1.HTTPPathMatch{ Type: ptr.To(gwapiv1.PathMatchPathPrefix), Value: ptr.To("/"), }, }, }, - Filters: []gwapiv1.HTTPRouteFilter{ + Filters: []gwapiv1b1.HTTPRouteFilter{ { Type: gwapiv1.HTTPRouteFilterExtensionRef, - ExtensionRef: &gwapiv1.LocalObjectReference{ - Group: gwapiv1.Group("gateway.example.io"), - Kind: gwapiv1.Kind("Foo"), - Name: gwapiv1.ObjectName("test"), + ExtensionRef: &gwapiv1b1.LocalObjectReference{ + Group: gwapiv1b1.Group("gateway.example.io"), + Kind: gwapiv1b1.Kind("Foo"), + Name: gwapiv1b1.ObjectName("test"), }, }, }, - BackendRefs: []gwapiv1.HTTPBackendRef{ + BackendRefs: []gwapiv1b1.HTTPBackendRef{ { - BackendRef: gwapiv1.BackendRef{ - BackendObjectReference: gwapiv1.BackendObjectReference{ + BackendRef: gwapiv1b1.BackendRef{ + BackendObjectReference: gwapiv1b1.BackendObjectReference{ Group: gatewayapi.GroupPtr(corev1.GroupName), Kind: gatewayapi.KindPtr(gatewayapi.KindService), Name: "test", @@ -196,34 +197,34 @@ func TestProcessHTTPRoutes(t *testing.T) { }, { name: "httproute with invalid timeout setting for HTTPRouteRule", - routes: []*gwapiv1.HTTPRoute{ + routes: []*gwapiv1b1.HTTPRoute{ { ObjectMeta: metav1.ObjectMeta{ Namespace: httpRouteNS, Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { Name: "test", }, }, }, - Rules: []gwapiv1.HTTPRouteRule{ + Rules: []gwapiv1b1.HTTPRouteRule{ { - Matches: []gwapiv1.HTTPRouteMatch{ + Matches: []gwapiv1b1.HTTPRouteMatch{ { - Path: &gwapiv1.HTTPPathMatch{ + Path: &gwapiv1b1.HTTPPathMatch{ Type: ptr.To(gwapiv1.PathMatchPathPrefix), Value: ptr.To("/"), }, }, }, - BackendRefs: []gwapiv1.HTTPBackendRef{ + BackendRefs: []gwapiv1b1.HTTPBackendRef{ { - BackendRef: gwapiv1.BackendRef{ - BackendObjectReference: gwapiv1.BackendObjectReference{ + BackendRef: gwapiv1b1.BackendRef{ + BackendObjectReference: gwapiv1b1.BackendObjectReference{ Group: gatewayapi.GroupPtr(corev1.GroupName), Kind: gatewayapi.KindPtr(gatewayapi.KindService), Name: "test", @@ -231,7 +232,7 @@ func TestProcessHTTPRoutes(t *testing.T) { }, }, }, - Timeouts: &gwapiv1.HTTPRouteTimeouts{ + Timeouts: &gwapiv1b1.HTTPRouteTimeouts{ Request: &invalidDuration, BackendRequest: &invalidDuration, }, @@ -274,12 +275,12 @@ func TestProcessHTTPRoutes(t *testing.T) { r.client = fakeclient.NewClientBuilder(). WithScheme(envoygateway.GetScheme()). WithObjects(objs...). - WithIndex(&gwapiv1.HTTPRoute{}, gatewayHTTPRouteIndex, gatewayHTTPRouteIndexFunc). + WithIndex(&gwapiv1b1.HTTPRoute{}, gatewayHTTPRouteIndex, gatewayHTTPRouteIndexFunc). Build() // Wait until all the httproutes have been initialized. require.Eventually(t, func() bool { - httpRoutes := gwapiv1.HTTPRouteList{} + httpRoutes := gwapiv1b1.HTTPRouteList{} if err := r.client.List(ctx, &httpRoutes, client.InNamespace(httpRouteNS)); err != nil { return false } @@ -312,29 +313,29 @@ func TestProcessHTTPRoutes(t *testing.T) { func TestProcessGRPCRoutes(t *testing.T) { // The gatewayclass configured for the reconciler and referenced by test cases. - gcCtrlName := gwapiv1.GatewayController(egv1a1.GatewayControllerName) - gc := &gwapiv1.GatewayClass{ + gcCtrlName := gwapiv1b1.GatewayController(egv1a1.GatewayControllerName) + gc := &gwapiv1b1.GatewayClass{ ObjectMeta: metav1.ObjectMeta{ Name: "test", }, - Spec: gwapiv1.GatewayClassSpec{ + Spec: gwapiv1b1.GatewayClassSpec{ ControllerName: gcCtrlName, }, } // The gateway referenced by test cases. - gw := &gwapiv1.Gateway{ + gw := &gwapiv1b1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.GatewaySpec{ - GatewayClassName: gwapiv1.ObjectName(gc.Name), - Listeners: []gwapiv1.Listener{ + Spec: gwapiv1b1.GatewaySpec{ + GatewayClassName: gwapiv1b1.ObjectName(gc.Name), + Listeners: []gwapiv1b1.Listener{ { Name: "http", Protocol: gwapiv1.HTTPProtocolType, - Port: gwapiv1.PortNumber(int32(8080)), + Port: gwapiv1b1.PortNumber(int32(8080)), }, }, }, @@ -356,8 +357,8 @@ func TestProcessGRPCRoutes(t *testing.T) { Name: "test", }, Spec: gwapiv1a2.GRPCRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { Name: "test", }, @@ -374,8 +375,8 @@ func TestProcessGRPCRoutes(t *testing.T) { }, BackendRefs: []gwapiv1a2.GRPCBackendRef{ { - BackendRef: gwapiv1.BackendRef{ - BackendObjectReference: gwapiv1.BackendObjectReference{ + BackendRef: gwapiv1b1.BackendRef{ + BackendObjectReference: gwapiv1b1.BackendObjectReference{ Group: gatewayapi.GroupPtr(corev1.GroupName), Kind: gatewayapi.KindPtr(gatewayapi.KindService), Name: "test", @@ -440,24 +441,24 @@ func TestProcessGRPCRoutes(t *testing.T) { func TestValidateHTTPRouteParentRefs(t *testing.T) { testCases := []struct { name string - route *gwapiv1.HTTPRoute - gateways []*gwapiv1.Gateway - classes []*gwapiv1.GatewayClass - expect []gwapiv1.Gateway + route *gwapiv1b1.HTTPRoute + gateways []*gwapiv1b1.Gateway + classes []*gwapiv1b1.GatewayClass + expect []gwapiv1b1.Gateway expected bool }{ { name: "valid parentRef", - route: &gwapiv1.HTTPRoute{ + route: &gwapiv1b1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("Gateway"), Name: "test", }, @@ -465,35 +466,35 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, }, }, - gateways: []*gwapiv1.Gateway{ + gateways: []*gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc1", }, }, }, - classes: []*gwapiv1.GatewayClass{ + classes: []*gwapiv1b1.GatewayClass{ { ObjectMeta: metav1.ObjectMeta{ Name: "gc1", }, - Spec: gwapiv1.GatewayClassSpec{ - ControllerName: gwapiv1.GatewayController(egv1a1.GatewayControllerName), + Spec: gwapiv1b1.GatewayClassSpec{ + ControllerName: gwapiv1b1.GatewayController(egv1a1.GatewayControllerName), }, }, }, - expect: []gwapiv1.Gateway{ + expect: []gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", ResourceVersion: "999", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc1", }, }, @@ -502,14 +503,14 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, { name: "invalid parentRef group", - route: &gwapiv1.HTTPRoute{ + route: &gwapiv1b1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { Group: gatewayapi.GroupPtr("unsupported.group"), Kind: gatewayapi.KindPtr("Gateway"), @@ -523,16 +524,16 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, { name: "invalid parentRef kind", - route: &gwapiv1.HTTPRoute{ + route: &gwapiv1b1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("UnsupportedKind"), Name: "test", }, @@ -544,16 +545,16 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, { name: "non-existent parentRef name", - route: &gwapiv1.HTTPRoute{ + route: &gwapiv1b1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("Gateway"), Name: "no-existent", }, @@ -565,21 +566,21 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, { name: "valid parentRefs", - route: &gwapiv1.HTTPRoute{ + route: &gwapiv1b1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("Gateway"), Name: "test", }, { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("Gateway"), Name: "test2", }, @@ -587,13 +588,13 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, }, }, - gateways: []*gwapiv1.Gateway{ + gateways: []*gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc1", }, }, @@ -602,29 +603,29 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { Namespace: "test", Name: "test2", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc1", }, }, }, - classes: []*gwapiv1.GatewayClass{ + classes: []*gwapiv1b1.GatewayClass{ { ObjectMeta: metav1.ObjectMeta{ Name: "gc1", }, - Spec: gwapiv1.GatewayClassSpec{ - ControllerName: gwapiv1.GatewayController(egv1a1.GatewayControllerName), + Spec: gwapiv1b1.GatewayClassSpec{ + ControllerName: gwapiv1b1.GatewayController(egv1a1.GatewayControllerName), }, }, }, - expect: []gwapiv1.Gateway{ + expect: []gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", ResourceVersion: "999", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc1", }, }, @@ -634,7 +635,7 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { Name: "test2", ResourceVersion: "999", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc1", }, }, @@ -643,21 +644,21 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, { name: "one of two parentRefs are managed", - route: &gwapiv1.HTTPRoute{ + route: &gwapiv1b1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("Gateway"), Name: "test", }, { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("Gateway"), Name: "test2", }, @@ -665,13 +666,13 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, }, }, - gateways: []*gwapiv1.Gateway{ + gateways: []*gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc1", }, }, @@ -680,37 +681,37 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { Namespace: "test", Name: "test2", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc2", }, }, }, - classes: []*gwapiv1.GatewayClass{ + classes: []*gwapiv1b1.GatewayClass{ { ObjectMeta: metav1.ObjectMeta{ Name: "gc1", }, - Spec: gwapiv1.GatewayClassSpec{ - ControllerName: gwapiv1.GatewayController(egv1a1.GatewayControllerName), + Spec: gwapiv1b1.GatewayClassSpec{ + ControllerName: gwapiv1b1.GatewayController(egv1a1.GatewayControllerName), }, }, { ObjectMeta: metav1.ObjectMeta{ Name: "gc2", }, - Spec: gwapiv1.GatewayClassSpec{ - ControllerName: gwapiv1.GatewayController("unmanaged.controller"), + Spec: gwapiv1b1.GatewayClassSpec{ + ControllerName: gwapiv1b1.GatewayController("unmanaged.controller"), }, }, }, - expect: []gwapiv1.Gateway{ + expect: []gwapiv1b1.Gateway{ { ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", ResourceVersion: "999", }, - Spec: gwapiv1.GatewaySpec{ + Spec: gwapiv1b1.GatewaySpec{ GatewayClassName: "gc1", }, }, @@ -719,21 +720,21 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { }, { name: "one of two valid parentRefs kind", - route: &gwapiv1.HTTPRoute{ + route: &gwapiv1b1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", Name: "test", }, - Spec: gwapiv1.HTTPRouteSpec{ - CommonRouteSpec: gwapiv1.CommonRouteSpec{ - ParentRefs: []gwapiv1.ParentReference{ + Spec: gwapiv1b1.HTTPRouteSpec{ + CommonRouteSpec: gwapiv1b1.CommonRouteSpec{ + ParentRefs: []gwapiv1b1.ParentReference{ { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("Gateway"), Name: "test", }, { - Group: gatewayapi.GroupPtr(gwapiv1.GroupName), + Group: gatewayapi.GroupPtr(gwapiv1b1.GroupName), Kind: gatewayapi.KindPtr("Unsupported"), Name: "test2", }, @@ -746,7 +747,7 @@ func TestValidateHTTPRouteParentRefs(t *testing.T) { } // Create the reconciler. - r := &gatewayAPIReconciler{classController: gwapiv1.GatewayController(egv1a1.GatewayControllerName)} + r := &gatewayAPIReconciler{classController: gwapiv1b1.GatewayController(egv1a1.GatewayControllerName)} ctx := context.Background() for _, tc := range testCases { diff --git a/internal/status/conditions.go b/internal/status/conditions.go index cb588131ef93..a39295159a9d 100644 --- a/internal/status/conditions.go +++ b/internal/status/conditions.go @@ -20,7 +20,8 @@ import ( appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" ) const ( @@ -32,7 +33,7 @@ const ( ) // computeGatewayClassAcceptedCondition computes the GatewayClass Accepted status condition. -func computeGatewayClassAcceptedCondition(gatewayClass *gwapiv1.GatewayClass, +func computeGatewayClassAcceptedCondition(gatewayClass *gwapiv1beta1.GatewayClass, accepted bool, reason, msg string) metav1.Condition { switch accepted { @@ -58,7 +59,7 @@ func computeGatewayClassAcceptedCondition(gatewayClass *gwapiv1.GatewayClass, } // computeGatewayAcceptedCondition computes the Gateway Accepted status condition. -func computeGatewayAcceptedCondition(gw *gwapiv1.Gateway, accepted bool) metav1.Condition { +func computeGatewayAcceptedCondition(gw *gwapiv1beta1.Gateway, accepted bool) metav1.Condition { switch accepted { case true: return newCondition(string(gwapiv1.GatewayReasonAccepted), metav1.ConditionTrue, @@ -73,7 +74,7 @@ func computeGatewayAcceptedCondition(gw *gwapiv1.Gateway, accepted bool) metav1. // computeGatewayProgrammedCondition computes the Gateway Programmed status condition. // Programmed condition surfaces true when the Envoy Deployment status is ready. -func computeGatewayProgrammedCondition(gw *gwapiv1.Gateway, deployment *appsv1.Deployment) metav1.Condition { +func computeGatewayProgrammedCondition(gw *gwapiv1beta1.Gateway, deployment *appsv1.Deployment) metav1.Condition { if len(gw.Status.Addresses) == 0 { return newCondition(string(gwapiv1.GatewayConditionProgrammed), metav1.ConditionFalse, string(gwapiv1.GatewayReasonAddressNotAssigned), diff --git a/internal/status/gateway.go b/internal/status/gateway.go index 29d47078bedf..00d8ce18c122 100644 --- a/internal/status/gateway.go +++ b/internal/status/gateway.go @@ -9,11 +9,12 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/ptr" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1beta1" + gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" ) // UpdateGatewayStatusAcceptedCondition updates the status condition for the provided Gateway based on the accepted state. -func UpdateGatewayStatusAcceptedCondition(gw *gwapiv1.Gateway, accepted bool) *gwapiv1.Gateway { +func UpdateGatewayStatusAcceptedCondition(gw *gwapiv1beta1.Gateway, accepted bool) *gwapiv1beta1.Gateway { gw.Status.Conditions = MergeConditions(gw.Status.Conditions, computeGatewayAcceptedCondition(gw, accepted)) return gw } @@ -21,7 +22,7 @@ func UpdateGatewayStatusAcceptedCondition(gw *gwapiv1.Gateway, accepted bool) *g // UpdateGatewayStatusProgrammedCondition updates the status addresses for the provided gateway // based on the status IP/Hostname of svc and updates the Programmed condition based on the // service and deployment state. -func UpdateGatewayStatusProgrammedCondition(gw *gwapiv1.Gateway, svc *corev1.Service, deployment *appsv1.Deployment, nodeAddresses ...string) { +func UpdateGatewayStatusProgrammedCondition(gw *gwapiv1beta1.Gateway, svc *corev1.Service, deployment *appsv1.Deployment, nodeAddresses ...string) { var addresses, hostnames []string // Update the status addresses field. if svc != nil {