From d0ca00df78ca06129b5d2267fbbb1271adb5fd19 Mon Sep 17 00:00:00 2001 From: Tommy Chen Date: Tue, 2 Apr 2024 15:24:12 +0800 Subject: [PATCH] chore: Use v1beta1 gateway API on more files --- internal/cmd/egctl/status.go | 5 +- internal/cmd/egctl/translate.go | 18 +++--- internal/envoygateway/config/config_test.go | 6 +- internal/envoygateway/config/decoder_test.go | 4 +- .../extension/registry/extension_manager.go | 21 +++---- internal/extension/testutils/manager.go | 6 +- internal/extension/types/manager.go | 4 +- internal/gatewayapi/backendtlspolicy.go | 3 +- internal/gatewayapi/clienttrafficpolicy.go | 2 +- internal/gatewayapi/contexts.go | 4 +- internal/gatewayapi/contexts_test.go | 22 +++---- internal/gatewayapi/envoypatchpolicy.go | 2 +- internal/gatewayapi/filters.go | 31 +++++----- internal/gatewayapi/helpers.go | 61 ++++++++++--------- internal/gatewayapi/helpers_v1alpha2.go | 34 +++++------ internal/gatewayapi/route.go | 10 +-- internal/gatewayapi/runner/runner.go | 4 +- internal/gatewayapi/runner/runner_test.go | 10 +-- internal/gatewayapi/securitypolicy.go | 13 ++-- internal/gatewayapi/tls.go | 3 +- internal/gatewayapi/translator.go | 3 +- internal/gatewayapi/validate.go | 6 +- .../kubernetes/proxy_infra_test.go | 4 +- .../ratelimit/resource_provider_test.go | 8 +-- internal/kubernetes/secret.go | 8 +-- internal/message/types.go | 6 +- internal/provider/kubernetes/controller.go | 14 ++--- internal/provider/kubernetes/helpers.go | 12 ++-- internal/provider/kubernetes/routes.go | 16 ++--- internal/provider/kubernetes/status.go | 5 +- 30 files changed, 172 insertions(+), 173 deletions(-) diff --git a/internal/cmd/egctl/status.go b/internal/cmd/egctl/status.go index 3a3f65a7fa48..918f50e53990 100644 --- a/internal/cmd/egctl/status.go +++ b/internal/cmd/egctl/status.go @@ -18,7 +18,6 @@ import ( "github.com/spf13/cobra" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" - gwv1 "sigs.k8s.io/gateway-api/apis/v1" gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -120,14 +119,14 @@ func runStatus(ctx context.Context, cli client.Client, resourceType, namespace s switch strings.ToLower(resourceType) { case "gc", "gatewayclass": - gc := gwv1.GatewayClassList{} + gc := gwv1b1.GatewayClassList{} if err := cli.List(ctx, &gc, client.InNamespace(namespace)); err != nil { return err } resourcesList = &gc case "gtw", "gateway": - gtw := gwv1.GatewayList{} + gtw := gwv1b1.GatewayList{} if err := cli.List(ctx, >w, client.InNamespace(namespace)); err != nil { return err } diff --git a/internal/cmd/egctl/translate.go b/internal/cmd/egctl/translate.go index 36112d2de915..14dd83b33d73 100644 --- a/internal/cmd/egctl/translate.go +++ b/internal/cmd/egctl/translate.go @@ -278,7 +278,7 @@ func translateGatewayAPIToIR(resources *gatewayapi.Resources) (*gatewayapi.Trans t := &gatewayapi.Translator{ GatewayControllerName: egv1a1.GatewayControllerName, - GatewayClassName: gwapiv1.ObjectName(resources.GatewayClass.Name), + GatewayClassName: gwapiv1b1.ObjectName(resources.GatewayClass.Name), GlobalRateLimitEnabled: true, EndpointRoutingDisabled: true, EnvoyPatchPolicyEnabled: true, @@ -305,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: gwapiv1b1.ObjectName(resources.GatewayClass.Name), GlobalRateLimitEnabled: true, EndpointRoutingDisabled: true, EnvoyPatchPolicyEnabled: true, @@ -337,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: gwapiv1b1.ObjectName(resources.GatewayClass.Name), GlobalRateLimitEnabled: true, EndpointRoutingDisabled: true, EnvoyPatchPolicyEnabled: true, @@ -543,7 +543,7 @@ func addMissingServices(requiredServices map[string]*v1.Service, obj interface{} var objNamespace string protocol := v1.Protocol(gatewayapi.TCPProtocol) - refs := []gwapiv1.BackendRef{} + refs := []gwapiv1b1.BackendRef{} switch route := obj.(type) { case *gwapiv1b1.HTTPRoute: objNamespace = route.Namespace @@ -687,7 +687,7 @@ func kubernetesYAMLToResources(str string, addMissingResources bool) (*gatewayap Name: name, Namespace: namespace, }, - Spec: typedSpec.(gwapiv1.GatewayClassSpec), + Spec: typedSpec.(gwapiv1b1.GatewayClassSpec), } resources.GatewayClass = gatewayClass case gatewayapi.KindGateway: @@ -697,7 +697,7 @@ func kubernetesYAMLToResources(str string, addMissingResources bool) (*gatewayap Name: name, Namespace: namespace, }, - Spec: typedSpec.(gwapiv1.GatewaySpec), + Spec: typedSpec.(gwapiv1b1.GatewaySpec), } resources.Gateways = append(resources.Gateways, gateway) case gatewayapi.KindTCPRoute: @@ -946,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 := gwapiv1b1.Namespace(namespace) + resources.GatewayClass.Spec.ParametersRef = &gwapiv1b1.ParametersReference{ + Group: gwapiv1b1.Group(egv1a1.GroupVersion.Group), Kind: gatewayapi.KindEnvoyProxy, Name: defaultEnvoyProxyName, Namespace: &ns, diff --git a/internal/envoygateway/config/config_test.go b/internal/envoygateway/config/config_test.go index 09f3ddfdcb24..1902b6ebf647 100644 --- a/internal/envoygateway/config/config_test.go +++ b/internal/envoygateway/config/config_test.go @@ -9,15 +9,15 @@ import ( "testing" "github.com/stretchr/testify/require" - v1 "sigs.k8s.io/gateway-api/apis/v1" + gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/logging" ) var ( - TLSSecretKind = v1.Kind("Secret") - TLSUnrecognizedKind = v1.Kind("Unrecognized") + TLSSecretKind = gwv1b1.Kind("Secret") + TLSUnrecognizedKind = gwv1b1.Kind("Unrecognized") ) func TestValidate(t *testing.T) { diff --git a/internal/envoygateway/config/decoder_test.go b/internal/envoygateway/config/decoder_test.go index eb2f24855db2..d91d6ac6360b 100644 --- a/internal/envoygateway/config/decoder_test.go +++ b/internal/envoygateway/config/decoder_test.go @@ -13,7 +13,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/api/v1alpha1" ) @@ -175,7 +175,7 @@ func TestDecode(t *testing.T) { Redis: &v1alpha1.RateLimitRedisSettings{ URL: "localhost:6379", TLS: &v1alpha1.RedisTLSSettings{ - CertificateRef: &gwapiv1.SecretObjectReference{ + CertificateRef: &gwapiv1b1.SecretObjectReference{ Name: "ratelimit-cert", }, }, diff --git a/internal/extension/registry/extension_manager.go b/internal/extension/registry/extension_manager.go index dd2170c5be6c..42250a6958e3 100644 --- a/internal/extension/registry/extension_manager.go +++ b/internal/extension/registry/extension_manager.go @@ -11,21 +11,20 @@ import ( "errors" "fmt" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - "google.golang.org/grpc/credentials/insecure" - - corev1 "k8s.io/api/core/v1" - k8scli "sigs.k8s.io/controller-runtime/pkg/client" - k8sclicfg "sigs.k8s.io/controller-runtime/pkg/client/config" - v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/envoygateway" "github.com/envoyproxy/gateway/internal/envoygateway/config" extTypes "github.com/envoyproxy/gateway/internal/extension/types" "github.com/envoyproxy/gateway/internal/kubernetes" "github.com/envoyproxy/gateway/proto/extension" + + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" + corev1 "k8s.io/api/core/v1" + k8scli "sigs.k8s.io/controller-runtime/pkg/client" + k8sclicfg "sigs.k8s.io/controller-runtime/pkg/client/config" + "sigs.k8s.io/gateway-api/apis/v1beta1" ) const grpcServiceConfig = `{ @@ -76,11 +75,11 @@ func NewManager(cfg *config.Server) (extTypes.Manager, error) { // HasExtension checks to see whether a given Group and Kind has an // associated extension registered for it. -func (m *Manager) HasExtension(g v1.Group, k v1.Kind) bool { +func (m *Manager) HasExtension(g v1beta1.Group, k v1beta1.Kind) bool { extension := m.extension // TODO: not currently checking the version since extensionRef only supports group and kind. for _, gvk := range extension.Resources { - if g == v1.Group(gvk.Group) && k == v1.Kind(gvk.Kind) { + if g == v1beta1.Group(gvk.Group) && k == v1beta1.Kind(gvk.Kind) { return true } } diff --git a/internal/extension/testutils/manager.go b/internal/extension/testutils/manager.go index 7185d58739f3..dd5375a1c06a 100644 --- a/internal/extension/testutils/manager.go +++ b/internal/extension/testutils/manager.go @@ -6,7 +6,7 @@ package testutils import ( - v1 "sigs.k8s.io/gateway-api/apis/v1" + "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/api/v1alpha1" extType "github.com/envoyproxy/gateway/internal/extension/types" @@ -24,11 +24,11 @@ func NewManager(ext v1alpha1.ExtensionManager) extType.Manager { } } -func (m *Manager) HasExtension(g v1.Group, k v1.Kind) bool { +func (m *Manager) HasExtension(g v1beta1.Group, k v1beta1.Kind) bool { extension := m.extension // TODO: not currently checking the version since extensionRef only supports group and kind. for _, gvk := range extension.Resources { - if g == v1.Group(gvk.Group) && k == v1.Kind(gvk.Kind) { + if g == v1beta1.Group(gvk.Group) && k == v1beta1.Kind(gvk.Kind) { return true } } diff --git a/internal/extension/types/manager.go b/internal/extension/types/manager.go index 766bd4fda3c4..062c8bb89ef9 100644 --- a/internal/extension/types/manager.go +++ b/internal/extension/types/manager.go @@ -6,7 +6,7 @@ package types import ( - v1 "sigs.k8s.io/gateway-api/apis/v1" + "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/api/v1alpha1" ) @@ -19,7 +19,7 @@ type Manager interface { // // If a Group and Kind is registered with an extension, then it should // return true, otherwise return false. - HasExtension(g v1.Group, k v1.Kind) bool + HasExtension(g v1beta1.Group, k v1beta1.Kind) bool // GetPreXDSHookClient checks if the registered extension makes use of a particular hook type that modifies inputs // that are used to generate an xDS resource. diff --git a/internal/gatewayapi/backendtlspolicy.go b/internal/gatewayapi/backendtlspolicy.go index e147589577af..f4f520e0a36e 100644 --- a/internal/gatewayapi/backendtlspolicy.go +++ b/internal/gatewayapi/backendtlspolicy.go @@ -13,13 +13,14 @@ import ( "k8s.io/utils/ptr" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/internal/ir" "github.com/envoyproxy/gateway/internal/status" ) func (t *Translator) processBackendTLSPolicy( - backendRef gwapiv1.BackendObjectReference, + backendRef gwapiv1b1.BackendObjectReference, backendNamespace string, parent gwapiv1a2.ParentReference, resources *Resources) *ir.TLSUpstreamConfig { diff --git a/internal/gatewayapi/clienttrafficpolicy.go b/internal/gatewayapi/clienttrafficpolicy.go index ef8869f5bc83..2ec36930e104 100644 --- a/internal/gatewayapi/clienttrafficpolicy.go +++ b/internal/gatewayapi/clienttrafficpolicy.go @@ -16,8 +16,8 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/utils/ptr" - gwv1b1 "sigs.k8s.io/gateway-api/apis/v1" gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/ir" diff --git a/internal/gatewayapi/contexts.go b/internal/gatewayapi/contexts.go index 67e545e1edf8..e2e47625ce08 100644 --- a/internal/gatewayapi/contexts.go +++ b/internal/gatewayapi/contexts.go @@ -30,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([]gwapiv1b1.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] = gwapiv1b1.ListenerStatus{Name: listener.Name} g.listeners[i] = &ListenerContext{ Listener: listener, gateway: g.Gateway, diff --git a/internal/gatewayapi/contexts_test.go b/internal/gatewayapi/contexts_test.go index 0ff9ec5a3e4d..42ab4dfde9a0 100644 --- a/internal/gatewayapi/contexts_test.go +++ b/internal/gatewayapi/contexts_test.go @@ -20,8 +20,8 @@ func TestContexts(t *testing.T) { Namespace: "envoy-gateway", Name: "gateway-1", }, - Spec: gwapiv1.GatewaySpec{ - Listeners: []gwapiv1.Listener{ + Spec: gwapiv1b1.GatewaySpec{ + Listeners: []gwapiv1b1.Listener{ { Name: "http", }, @@ -48,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) @@ -64,8 +64,8 @@ func TestContextsStaleListener(t *testing.T) { Namespace: "envoy-gateway", Name: "gateway-1", }, - Spec: gwapiv1.GatewaySpec{ - Listeners: []gwapiv1.Listener{ + Spec: gwapiv1b1.GatewaySpec{ + Listeners: []gwapiv1b1.Listener{ { Name: "https", }, @@ -74,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{ @@ -99,7 +99,7 @@ func TestContextsStaleListener(t *testing.T) { gCtx := &GatewayContext{Gateway: gateway} httpsListenerCtx := &ListenerContext{ - Listener: &gwapiv1.Listener{ + Listener: &gwapiv1b1.Listener{ Name: "https", }, gateway: gateway, @@ -107,7 +107,7 @@ func TestContextsStaleListener(t *testing.T) { } httpListenerCtx := &ListenerContext{ - Listener: &gwapiv1.Listener{ + Listener: &gwapiv1b1.Listener{ Name: "http", }, gateway: gateway, @@ -126,7 +126,7 @@ func TestContextsStaleListener(t *testing.T) { require.Len(t, gCtx.Status.Listeners, 2) - expectedListenerStatuses := []gwapiv1.ListenerStatus{ + expectedListenerStatuses := []gwapiv1b1.ListenerStatus{ { Name: "https", }, @@ -143,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/envoypatchpolicy.go b/internal/gatewayapi/envoypatchpolicy.go index 1ec835e51a4b..11bbbb5f9965 100644 --- a/internal/gatewayapi/envoypatchpolicy.go +++ b/internal/gatewayapi/envoypatchpolicy.go @@ -11,8 +11,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" - gwv1b1 "sigs.k8s.io/gateway-api/apis/v1" gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/ir" diff --git a/internal/gatewayapi/filters.go b/internal/gatewayapi/filters.go index c728e1e863b9..9212e9af6543 100644 --- a/internal/gatewayapi/filters.go +++ b/internal/gatewayapi/filters.go @@ -12,6 +12,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1b1 "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 *gwapiv1b1.HTTPURLRewriteFilter, filterContext *HTTPFiltersContext) + processRedirectFilter(redirect *gwapiv1b1.HTTPRequestRedirectFilter, filterContext *HTTPFiltersContext) + processRequestHeaderModifierFilter(headerModifier *gwapiv1b1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) + processResponseHeaderModifierFilter(headerModifier *gwapiv1b1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) + processRequestMirrorFilter(filterIdx int, mirror *gwapiv1b1.HTTPRequestMirrorFilter, filterContext *HTTPFiltersContext, resources *Resources) + processExtensionRefHTTPFilter(extRef *gwapiv1b1.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 []gwapiv1b1.HTTPRouteFilter, ruleIdx int, resources *Resources) *HTTPFiltersContext { httpFiltersContext := &HTTPFiltersContext{ @@ -143,7 +144,7 @@ func (t *Translator) ProcessGRPCFilters(parentRef *RouteParentContext, } func (t *Translator) processURLRewriteFilter( - rewrite *gwapiv1.HTTPURLRewriteFilter, + rewrite *gwapiv1b1.HTTPURLRewriteFilter, filterContext *HTTPFiltersContext) { if filterContext.URLRewrite != nil { filterContext.ParentRef.SetCondition(filterContext.Route, @@ -245,7 +246,7 @@ func (t *Translator) processURLRewriteFilter( } func (t *Translator) processRedirectFilter( - redirect *gwapiv1.HTTPRequestRedirectFilter, + redirect *gwapiv1b1.HTTPRequestRedirectFilter, filterContext *HTTPFiltersContext) { // Can't have two redirects for the same route if filterContext.RedirectResponse != nil { @@ -346,7 +347,7 @@ func (t *Translator) processRedirectFilter( } func (t *Translator) processRequestHeaderModifierFilter( - headerModifier *gwapiv1.HTTPHeaderFilter, + headerModifier *gwapiv1b1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) { // Make sure the header modifier config actually exists if headerModifier == nil { @@ -499,7 +500,7 @@ func (t *Translator) processRequestHeaderModifierFilter( } func (t *Translator) processResponseHeaderModifierFilter( - headerModifier *gwapiv1.HTTPHeaderFilter, + headerModifier *gwapiv1b1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) { // Make sure the header modifier config actually exists if headerModifier == nil { @@ -652,7 +653,7 @@ func (t *Translator) processResponseHeaderModifierFilter( } } -func (t *Translator) processExtensionRefHTTPFilter(extFilter *gwapiv1.LocalObjectReference, filterContext *HTTPFiltersContext, resources *Resources) { +func (t *Translator) processExtensionRefHTTPFilter(extFilter *gwapiv1b1.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 *gwapiv1b1.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 := gwapiv1b1.HTTPBackendRef{ + BackendRef: gwapiv1b1.BackendRef{ BackendObjectReference: mirrorBackend, Weight: &weight, }, diff --git a/internal/gatewayapi/helpers.go b/internal/gatewayapi/helpers.go index 9fb98f591c74..89c493cd53d8 100644 --- a/internal/gatewayapi/helpers.go +++ b/internal/gatewayapi/helpers.go @@ -16,6 +16,7 @@ import ( "k8s.io/utils/ptr" gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1b1 "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 gwapiv1b1.ProtocolType port int32 } -func GroupPtr(name string) *gwapiv1.Group { - group := gwapiv1.Group(name) +func GroupPtr(name string) *gwapiv1b1.Group { + group := gwapiv1b1.Group(name) return &group } -func KindPtr(name string) *gwapiv1.Kind { - kind := gwapiv1.Kind(name) +func KindPtr(name string) *gwapiv1b1.Kind { + kind := gwapiv1b1.Kind(name) return &kind } -func NamespacePtr(name string) *gwapiv1.Namespace { - namespace := gwapiv1.Namespace(name) +func NamespacePtr(name string) *gwapiv1b1.Namespace { + namespace := gwapiv1b1.Namespace(name) return &namespace } -func FromNamespacesPtr(fromNamespaces gwapiv1.FromNamespaces) *gwapiv1.FromNamespaces { +func FromNamespacesPtr(fromNamespaces gwapiv1b1.FromNamespaces) *gwapiv1b1.FromNamespaces { return &fromNamespaces } -func SectionNamePtr(name string) *gwapiv1.SectionName { - sectionName := gwapiv1.SectionName(name) +func SectionNamePtr(name string) *gwapiv1b1.SectionName { + sectionName := gwapiv1b1.SectionName(name) return §ionName } -func PortNumPtr(val int32) *gwapiv1.PortNumber { - portNum := gwapiv1.PortNumber(val) +func PortNumPtr(val int32) *gwapiv1b1.PortNumber { + portNum := gwapiv1b1.PortNumber(val) return &portNum } @@ -71,27 +72,27 @@ func ObjectNamePtr(val string) *v1alpha2.ObjectName { } var ( - PathMatchTypeDerefOr = ptr.Deref[gwapiv1.PathMatchType] + PathMatchTypeDerefOr = ptr.Deref[gwapiv1b1.PathMatchType] GRPCMethodMatchTypeDerefOr = ptr.Deref[v1alpha2.GRPCMethodMatchType] - HeaderMatchTypeDerefOr = ptr.Deref[gwapiv1.HeaderMatchType] - QueryParamMatchTypeDerefOr = ptr.Deref[gwapiv1.QueryParamMatchType] + HeaderMatchTypeDerefOr = ptr.Deref[gwapiv1b1.HeaderMatchType] + QueryParamMatchTypeDerefOr = ptr.Deref[gwapiv1b1.QueryParamMatchType] ) -func NamespaceDerefOr(namespace *gwapiv1.Namespace, defaultNamespace string) string { +func NamespaceDerefOr(namespace *gwapiv1b1.Namespace, defaultNamespace string) string { if namespace != nil && *namespace != "" { return string(*namespace) } return defaultNamespace } -func GroupDerefOr(group *gwapiv1.Group, defaultGroup string) string { +func GroupDerefOr(group *gwapiv1b1.Group, defaultGroup string) string { if group != nil && *group != "" { return string(*group) } return defaultGroup } -func KindDerefOr(kind *gwapiv1.Kind, defaultKind string) string { +func KindDerefOr(kind *gwapiv1b1.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 gwapiv1b1.ParentReference, gateway types.NamespacedName) bool { + if parentRef.Group != nil && string(*parentRef.Group) != gwapiv1b1.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 gwapiv1b1.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 *gwapiv1b1.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 == gwapiv1b1.Group(gk.Group) && + filter.ExtensionRef.Kind == gwapiv1b1.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 == gwapiv1b1.Group(gk.Group) && + filter.ExtensionRef.Kind == gwapiv1b1.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 *gwapiv1b1.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 []gwapiv1b1.ProtocolType) []string { var protocolStrings []string for _, protocol := range protocols { protocolStrings = append(protocolStrings, string(protocol)) @@ -413,10 +414,10 @@ func protocolSliceToStringSlice(protocols []gwapiv1.ProtocolType) []string { func getAncestorRefForPolicy(gatewayNN types.NamespacedName, sectionName *v1alpha2.SectionName) v1alpha2.ParentReference { return v1alpha2.ParentReference{ - Group: GroupPtr(gwapiv1.GroupName), + Group: GroupPtr(gwapiv1b1.GroupName), Kind: KindPtr(KindGateway), Namespace: NamespacePtr(gatewayNN.Namespace), - Name: gwapiv1.ObjectName(gatewayNN.Name), + Name: gwapiv1b1.ObjectName(gatewayNN.Name), SectionName: sectionName, } } diff --git a/internal/gatewayapi/helpers_v1alpha2.go b/internal/gatewayapi/helpers_v1alpha2.go index afa804131757..4ae0cb1d9d3a 100644 --- a/internal/gatewayapi/helpers_v1alpha2.go +++ b/internal/gatewayapi/helpers_v1alpha2.go @@ -12,12 +12,12 @@ package gatewayapi import ( - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" ) -// TODO: [gwapiv1a2-gwapiv1] -// This file can be removed once TLSRoute graduates to gwapiv1. +// TODO: [gwapiv1a2-gwapiv1b1] +// This file can be removed once TLSRoute graduates to gwapiv1b1. func GroupPtrV1Alpha2(group string) *gwapiv1a2.Group { gwGroup := gwapiv1a2.Group(group) @@ -44,17 +44,17 @@ func PortNumPtrV1Alpha2(port int) *gwapiv1a2.PortNumber { return &pn } -func UpgradeParentReferences(old []gwapiv1a2.ParentReference) []gwapiv1.ParentReference { - newParentReferences := make([]gwapiv1.ParentReference, len(old)) +func UpgradeParentReferences(old []gwapiv1a2.ParentReference) []gwapiv1b1.ParentReference { + newParentReferences := make([]gwapiv1b1.ParentReference, len(old)) for i, o := range old { newParentReferences[i] = UpgradeParentReference(o) } return newParentReferences } -// UpgradeParentReference converts gwapiv1a2.ParentReference to gwapiv1.ParentReference -func UpgradeParentReference(old gwapiv1a2.ParentReference) gwapiv1.ParentReference { - upgraded := gwapiv1.ParentReference{} +// UpgradeParentReference converts gwapiv1a2.ParentReference to gwapiv1b1.ParentReference +func UpgradeParentReference(old gwapiv1a2.ParentReference) gwapiv1b1.ParentReference { + upgraded := gwapiv1b1.ParentReference{} if old.Group != nil { upgraded.Group = GroupPtr(string(*old.Group)) @@ -81,7 +81,7 @@ func UpgradeParentReference(old gwapiv1a2.ParentReference) gwapiv1.ParentReferen return upgraded } -func DowngradeParentReference(old gwapiv1.ParentReference) gwapiv1a2.ParentReference { +func DowngradeParentReference(old gwapiv1b1.ParentReference) gwapiv1a2.ParentReference { downgraded := gwapiv1a2.ParentReference{} if old.Group != nil { @@ -109,11 +109,11 @@ func DowngradeParentReference(old gwapiv1.ParentReference) gwapiv1a2.ParentRefer return downgraded } -func UpgradeRouteParentStatuses(routeParentStatuses []gwapiv1a2.RouteParentStatus) []gwapiv1.RouteParentStatus { - var res []gwapiv1.RouteParentStatus +func UpgradeRouteParentStatuses(routeParentStatuses []gwapiv1a2.RouteParentStatus) []gwapiv1b1.RouteParentStatus { + var res []gwapiv1b1.RouteParentStatus for _, rps := range routeParentStatuses { - res = append(res, gwapiv1.RouteParentStatus{ + res = append(res, gwapiv1b1.RouteParentStatus{ ParentRef: UpgradeParentReference(rps.ParentRef), ControllerName: rps.ControllerName, Conditions: rps.Conditions, @@ -123,7 +123,7 @@ func UpgradeRouteParentStatuses(routeParentStatuses []gwapiv1a2.RouteParentStatu return res } -func DowngradeRouteParentStatuses(routeParentStatuses []gwapiv1.RouteParentStatus) []gwapiv1a2.RouteParentStatus { +func DowngradeRouteParentStatuses(routeParentStatuses []gwapiv1b1.RouteParentStatus) []gwapiv1a2.RouteParentStatus { var res []gwapiv1a2.RouteParentStatus for _, rps := range routeParentStatuses { @@ -137,9 +137,9 @@ func DowngradeRouteParentStatuses(routeParentStatuses []gwapiv1.RouteParentStatu return res } -// UpgradeBackendRef converts gwapiv1a2.BackendRef to gwapiv1.BackendRef -func UpgradeBackendRef(old gwapiv1a2.BackendRef) gwapiv1.BackendRef { - upgraded := gwapiv1.BackendRef{} +// UpgradeBackendRef converts gwapiv1a2.BackendRef to gwapiv1b1.BackendRef +func UpgradeBackendRef(old gwapiv1a2.BackendRef) gwapiv1b1.BackendRef { + upgraded := gwapiv1b1.BackendRef{} if old.Group != nil { upgraded.Group = GroupPtr(string(*old.Group)) @@ -162,7 +162,7 @@ func UpgradeBackendRef(old gwapiv1a2.BackendRef) gwapiv1.BackendRef { return upgraded } -func DowngradeBackendRef(old gwapiv1.BackendRef) gwapiv1a2.BackendRef { +func DowngradeBackendRef(old gwapiv1b1.BackendRef) gwapiv1a2.BackendRef { downgraded := gwapiv1a2.BackendRef{} if old.Group != nil { diff --git a/internal/gatewayapi/route.go b/internal/gatewayapi/route.go index d4f045a1cc9f..4a0faa1e75fb 100644 --- a/internal/gatewayapi/route.go +++ b/internal/gatewayapi/route.go @@ -229,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 gwapiv1b1.HTTPRouteRule) { if rule.Timeouts != nil { var rto *ir.Timeout @@ -279,7 +279,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 gwapiv1b1.HTTPRouteRule) ([]*ir.HTTPRoute, error) { var ruleRoutes []*ir.HTTPRoute // If no matches are specified, the implementation MUST match every HTTP request. @@ -1231,7 +1231,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(gwapiv1b1.RouteGroupKind{Group: GroupPtr(gwapiv1b1.GroupName), Kind: acceptedKind}) && listener.AllowsNamespace(resources.GetNamespace(routeContext.GetNamespace())) { allowedListeners = append(allowedListeners, listener) } @@ -1342,7 +1342,7 @@ func GetTargetBackendReference(backendRef gwapiv1a2.BackendObjectReference, name } return *backendRef.Group }(), - Kind: func() gwapiv1.Kind { + Kind: func() gwapiv1b1.Kind { if backendRef.Kind == nil { return "Service" } @@ -1351,7 +1351,7 @@ func GetTargetBackendReference(backendRef gwapiv1a2.BackendObjectReference, name Name: backendRef.Name, Namespace: NamespacePtr(NamespaceDerefOr(backendRef.Namespace, namespace)), }, - SectionName: func() *gwapiv1.SectionName { + SectionName: func() *gwapiv1b1.SectionName { if backendRef.Port != nil { return SectionNamePtr(strconv.Itoa(int(*backendRef.Port))) } diff --git a/internal/gatewayapi/runner/runner.go b/internal/gatewayapi/runner/runner.go index 4cb3d69d15ff..807e0258461f 100644 --- a/internal/gatewayapi/runner/runner.go +++ b/internal/gatewayapi/runner/runner.go @@ -12,7 +12,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" - v1 "sigs.k8s.io/gateway-api/apis/v1" + "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/envoygateway/config" @@ -80,7 +80,7 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) { // Translate and publish IRs. t := &gatewayapi.Translator{ GatewayControllerName: r.Server.EnvoyGateway.Gateway.ControllerName, - GatewayClassName: v1.ObjectName(resources.GatewayClass.Name), + GatewayClassName: v1beta1.ObjectName(resources.GatewayClass.Name), GlobalRateLimitEnabled: r.EnvoyGateway.RateLimit != nil, EnvoyPatchPolicyEnabled: r.EnvoyGateway.ExtensionAPIs != nil && r.EnvoyGateway.ExtensionAPIs.EnableEnvoyPatchPolicy, Namespace: r.Namespace, diff --git a/internal/gatewayapi/runner/runner_test.go b/internal/gatewayapi/runner/runner_test.go index 772f0372a3ca..6dfc928a339c 100644 --- a/internal/gatewayapi/runner/runner_test.go +++ b/internal/gatewayapi/runner/runner_test.go @@ -14,8 +14,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "k8s.io/apimachinery/pkg/types" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/envoygateway/config" @@ -160,8 +160,8 @@ func TestDeleteStatusKeys(t *testing.T) { }, } - r.ProviderResources.GatewayStatuses.Store(keys[0], &gwapiv1.GatewayStatus{}) - r.ProviderResources.HTTPRouteStatuses.Store(keys[1], &gwapiv1.HTTPRouteStatus{}) + r.ProviderResources.GatewayStatuses.Store(keys[0], &gwapiv1b1.GatewayStatus{}) + r.ProviderResources.HTTPRouteStatuses.Store(keys[1], &gwapiv1b1.HTTPRouteStatus{}) r.ProviderResources.GRPCRouteStatuses.Store(keys[2], &gwapiv1a2.GRPCRouteStatus{}) r.ProviderResources.TLSRouteStatuses.Store(keys[3], &gwapiv1a2.TLSRouteStatus{}) r.ProviderResources.TCPRouteStatuses.Store(keys[4], &gwapiv1a2.TCPRouteStatus{}) @@ -246,8 +246,8 @@ func TestDeleteAllStatusKeys(t *testing.T) { }, } - r.ProviderResources.GatewayStatuses.Store(keys[0], &gwapiv1.GatewayStatus{}) - r.ProviderResources.HTTPRouteStatuses.Store(keys[1], &gwapiv1.HTTPRouteStatus{}) + r.ProviderResources.GatewayStatuses.Store(keys[0], &gwapiv1b1.GatewayStatus{}) + r.ProviderResources.HTTPRouteStatuses.Store(keys[1], &gwapiv1b1.HTTPRouteStatus{}) r.ProviderResources.GRPCRouteStatuses.Store(keys[2], &gwapiv1a2.GRPCRouteStatus{}) r.ProviderResources.TLSRouteStatuses.Store(keys[3], &gwapiv1a2.TLSRouteStatus{}) r.ProviderResources.TCPRouteStatuses.Store(keys[4], &gwapiv1a2.TCPRouteStatus{}) diff --git a/internal/gatewayapi/securitypolicy.go b/internal/gatewayapi/securitypolicy.go index 962ff54b46de..bb4c641f7d02 100644 --- a/internal/gatewayapi/securitypolicy.go +++ b/internal/gatewayapi/securitypolicy.go @@ -21,7 +21,6 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/utils/ptr" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -754,7 +753,7 @@ func (t *Translator) buildExtAuth( var ( http = policy.Spec.ExtAuth.HTTP grpc = policy.Spec.ExtAuth.GRPC - backendRef *gwapiv1.BackendObjectReference + backendRef *gwv1b1.BackendObjectReference protocol ir.AppProtocol ds *ir.DestinationSetting authority string @@ -822,7 +821,7 @@ func (t *Translator) buildExtAuth( // TODO: zhaohuabing combine this function with the one in the route translator func (t *Translator) processExtServiceDestination( - backendRef *gwapiv1.BackendObjectReference, + backendRef *gwv1b1.BackendObjectReference, policy *egv1a1.SecurityPolicy, protocol ir.AppProtocol, resources *Resources) (*ir.DestinationSetting, error) { @@ -875,10 +874,10 @@ func (t *Translator) processExtServiceDestination( // relationship between the security policy and a gateway. // The owner security policy of the BackendRef is used as the parent reference here. gwv1a2.ParentReference{ - Group: ptr.To(gwapiv1.Group(egv1a1.GroupName)), - Kind: ptr.To(gwapiv1.Kind(egv1a1.KindSecurityPolicy)), - Namespace: ptr.To(gwapiv1.Namespace(policy.Namespace)), - Name: gwapiv1.ObjectName(policy.Name), + Group: ptr.To(gwv1b1.Group(egv1a1.GroupName)), + Kind: ptr.To(gwv1b1.Kind(egv1a1.KindSecurityPolicy)), + Namespace: ptr.To(gwv1b1.Namespace(policy.Namespace)), + Name: gwv1b1.ObjectName(policy.Name), }, resources) diff --git a/internal/gatewayapi/tls.go b/internal/gatewayapi/tls.go index f37c53b95262..fae657daa8c6 100644 --- a/internal/gatewayapi/tls.go +++ b/internal/gatewayapi/tls.go @@ -13,11 +13,12 @@ import ( corev1 "k8s.io/api/core/v1" v1 "sigs.k8s.io/gateway-api/apis/v1" + "sigs.k8s.io/gateway-api/apis/v1beta1" ) // validateTLSSecretData ensures the cert and key provided in a secret // is not malformed and can be properly parsed -func validateTLSSecretsData(secrets []*corev1.Secret, host *v1.Hostname) error { +func validateTLSSecretsData(secrets []*corev1.Secret, host *v1beta1.Hostname) error { var publicKeyAlgorithm string var parseErr error diff --git a/internal/gatewayapi/translator.go b/internal/gatewayapi/translator.go index 4a0455c13a96..f9a0d26d1c57 100644 --- a/internal/gatewayapi/translator.go +++ b/internal/gatewayapi/translator.go @@ -8,7 +8,6 @@ package gatewayapi import ( "golang.org/x/exp/maps" "k8s.io/apimachinery/pkg/runtime/schema" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" egv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -71,7 +70,7 @@ type Translator struct { // GatewayClassName is the name of the GatewayClass // to process Gateways for. - GatewayClassName gwapiv1.ObjectName + GatewayClassName gwapiv1b1.ObjectName // GlobalRateLimitEnabled is true when global // ratelimiting has been configured by the admin. diff --git a/internal/gatewayapi/validate.go b/internal/gatewayapi/validate.go index e7ddb427a157..bab9fb0f8732 100644 --- a/internal/gatewayapi/validate.go +++ b/internal/gatewayapi/validate.go @@ -23,7 +23,7 @@ import ( ) func (t *Translator) validateBackendRef(backendRefContext BackendRefContext, parentRef *RouteParentContext, route RouteContext, - resources *Resources, backendNamespace string, routeKind gwapiv1.Kind) bool { + resources *Resources, backendNamespace string, routeKind gwapiv1b1.Kind) bool { if !t.validateBackendRefFilters(backendRefContext, parentRef, route, routeKind) { 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 gwapiv1b1.Kind) bool { var filtersLen int switch routeKind { case KindHTTPRoute: - filters := GetFilters(backendRef).([]gwapiv1.HTTPRouteFilter) + filters := GetFilters(backendRef).([]gwapiv1b1.HTTPRouteFilter) filtersLen = len(filters) case KindGRPCRoute: filters := GetFilters(backendRef).([]gwapiv1a2.GRPCRouteFilter) diff --git a/internal/infrastructure/kubernetes/proxy_infra_test.go b/internal/infrastructure/kubernetes/proxy_infra_test.go index 9d3d2fe98ea4..d73d313a46fd 100644 --- a/internal/infrastructure/kubernetes/proxy_infra_test.go +++ b/internal/infrastructure/kubernetes/proxy_infra_test.go @@ -17,7 +17,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake" - 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" @@ -56,7 +56,7 @@ func newTestInfraWithClient(t *testing.T, cli client.Client) *Infra { Redis: &egv1a1.RateLimitRedisSettings{ URL: "", TLS: &egv1a1.RedisTLSSettings{ - CertificateRef: &gwapiv1.SecretObjectReference{ + CertificateRef: &gwapiv1b1.SecretObjectReference{ Name: "ratelimit-cert", }, }, diff --git a/internal/infrastructure/kubernetes/ratelimit/resource_provider_test.go b/internal/infrastructure/kubernetes/ratelimit/resource_provider_test.go index d322e8c925e5..446830677ea0 100644 --- a/internal/infrastructure/kubernetes/ratelimit/resource_provider_test.go +++ b/internal/infrastructure/kubernetes/ratelimit/resource_provider_test.go @@ -20,7 +20,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" "sigs.k8s.io/yaml" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" @@ -403,7 +403,7 @@ func TestDeployment(t *testing.T) { Redis: &egv1a1.RateLimitRedisSettings{ URL: "redis.redis.svc:6379", TLS: &egv1a1.RedisTLSSettings{ - CertificateRef: &gwapiv1.SecretObjectReference{ + CertificateRef: &gwapiv1b1.SecretObjectReference{ Name: "ratelimit-cert", }, }, @@ -457,7 +457,7 @@ func TestDeployment(t *testing.T) { Redis: &egv1a1.RateLimitRedisSettings{ URL: "redis.redis.svc:6379", TLS: &egv1a1.RedisTLSSettings{ - CertificateRef: &gwapiv1.SecretObjectReference{ + CertificateRef: &gwapiv1b1.SecretObjectReference{ Name: "ratelimit-cert", }, }, @@ -519,7 +519,7 @@ func TestDeployment(t *testing.T) { Redis: &egv1a1.RateLimitRedisSettings{ URL: "redis.redis.svc:6379", TLS: &egv1a1.RedisTLSSettings{ - CertificateRef: &gwapiv1.SecretObjectReference{ + CertificateRef: &gwapiv1b1.SecretObjectReference{ Name: "ratelimit-cert-origin", }, }, diff --git a/internal/kubernetes/secret.go b/internal/kubernetes/secret.go index ff98d61874bd..370868dde00f 100644 --- a/internal/kubernetes/secret.go +++ b/internal/kubernetes/secret.go @@ -10,16 +10,16 @@ import ( "errors" "fmt" + "github.com/envoyproxy/gateway/internal/gatewayapi" + corev1 "k8s.io/api/core/v1" k8smachinery "k8s.io/apimachinery/pkg/types" k8sclient "sigs.k8s.io/controller-runtime/pkg/client" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" - - "github.com/envoyproxy/gateway/internal/gatewayapi" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" ) // ValidateSecretObjectReference validate secret object reference for extension tls and ratelimit tls settings. -func ValidateSecretObjectReference(ctx context.Context, client k8sclient.Client, secretObjRef *gwapiv1.SecretObjectReference, namespace string) (*corev1.Secret, string, error) { +func ValidateSecretObjectReference(ctx context.Context, client k8sclient.Client, secretObjRef *gwapiv1b1.SecretObjectReference, namespace string) (*corev1.Secret, string, error) { if (secretObjRef.Group == nil || *secretObjRef.Group == corev1.GroupName) && (secretObjRef.Kind == nil || *secretObjRef.Kind == gatewayapi.KindSecret) { secret := &corev1.Secret{} diff --git a/internal/message/types.go b/internal/message/types.go index 7fc44da6678b..29953c0da871 100644 --- a/internal/message/types.go +++ b/internal/message/types.go @@ -8,8 +8,8 @@ package message import ( "github.com/telepresenceio/watchable" "k8s.io/apimachinery/pkg/types" - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" "github.com/envoyproxy/gateway/internal/gatewayapi" @@ -71,8 +71,8 @@ func (p *ProviderResources) Close() { // GatewayAPIStatuses contains gateway API resources statuses type GatewayAPIStatuses struct { - GatewayStatuses watchable.Map[types.NamespacedName, *gwapiv1.GatewayStatus] - HTTPRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1.HTTPRouteStatus] + GatewayStatuses watchable.Map[types.NamespacedName, *gwapiv1b1.GatewayStatus] + HTTPRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1b1.HTTPRouteStatus] GRPCRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.GRPCRouteStatus] TLSRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.TLSRouteStatus] TCPRouteStatuses watchable.Map[types.NamespacedName, *gwapiv1a2.TCPRouteStatus] diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index ed8d8c212435..d8e2f1e82af3 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -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{}, } } @@ -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), @@ -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) } diff --git a/internal/provider/kubernetes/helpers.go b/internal/provider/kubernetes/helpers.go index 1568d48fbb09..0ed8c8b94e2d 100644 --- a/internal/provider/kubernetes/helpers.go +++ b/internal/provider/kubernetes/helpers.go @@ -36,8 +36,8 @@ 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) ([]gwapiv1b1.Gateway, error) { + gatewayClassController gwapiv1b1.GatewayController, + routeParentReferences []gwapiv1b1.ParentReference) ([]gwapiv1b1.Gateway, error) { var gateways []gwapiv1b1.Gateway for i := range routeParentReferences { @@ -45,7 +45,7 @@ func validateParentRefs(ctx context.Context, client client.Client, namespace str 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 != gwapiv1b1.GroupName { return nil, fmt.Errorf("invalid Group %q", *ref.Group) } @@ -129,7 +129,7 @@ func gatewaysOfClass(gc *gwapiv1b1.GatewayClass, gwList *gwapiv1b1.GatewayList) // terminatesTLS returns true if the provided gateway contains a listener configured // for TLS termination. -func terminatesTLS(listener *gwapiv1.Listener) bool { +func terminatesTLS(listener *gwapiv1b1.Listener) bool { if listener.TLS != nil && (listener.Protocol == gwapiv1.HTTPSProtocolType || listener.Protocol == gwapiv1.TLSProtocolType) && @@ -141,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 *gwapiv1b1.SecretObjectReference) bool { return (ref.Group == nil || *ref.Group == corev1.GroupName) && (ref.Kind == nil || *ref.Kind == gatewayapi.KindSecret) } @@ -162,7 +162,7 @@ func infraName(gateway *gwapiv1b1.Gateway, merged bool) string { // - Validating weights. // - Validating ports. // - Referencing HTTPRoutes. -func validateBackendRef(ref *gwapiv1.BackendRef) error { +func validateBackendRef(ref *gwapiv1b1.BackendRef) error { switch { case ref == nil: return nil diff --git a/internal/provider/kubernetes/routes.go b/internal/provider/kubernetes/routes.go index bc909546a8da..2c9e4924f829 100644 --- a/internal/provider/kubernetes/routes.go +++ b/internal/provider/kubernetes/routes.go @@ -55,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), @@ -125,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), @@ -244,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), @@ -300,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, } @@ -311,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), @@ -367,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) } @@ -408,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), @@ -478,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/status.go b/internal/provider/kubernetes/status.go index 0f884ec329a0..911aee0392fb 100644 --- a/internal/provider/kubernetes/status.go +++ b/internal/provider/kubernetes/status.go @@ -12,7 +12,6 @@ import ( kerrors "k8s.io/apimachinery/pkg/api/errors" "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" gwapiv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -396,9 +395,9 @@ func (r *gatewayAPIReconciler) updateStatusForGateway(ctx context.Context, gtw * // publish status r.statusUpdater.Send(status.Update{ NamespacedName: key, - Resource: new(gwapiv1.Gateway), + Resource: new(gwapiv1b1.Gateway), Mutator: status.MutatorFunc(func(obj client.Object) client.Object { - g, ok := obj.(*gwapiv1.Gateway) + g, ok := obj.(*gwapiv1b1.Gateway) if !ok { panic(fmt.Sprintf("unsupported object type %T", obj)) }