From 928db9bc4210e82c229fb57375d0b745f83473b9 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 17 Apr 2023 10:56:36 +0200 Subject: [PATCH] chore: update linter --- .golangci.yml | 145 ++++-- pkg/provider/kubernetes/crd/client.go | 106 ++--- .../kubernetes/crd/client_mock_test.go | 70 +-- pkg/provider/kubernetes/crd/client_test.go | 4 +- .../versioned/fake/clientset_generated.go | 6 +- pkg/provider/kubernetes/crd/kubernetes.go | 20 +- .../kubernetes/crd/kubernetes_http.go | 26 +- pkg/provider/kubernetes/crd/kubernetes_tcp.go | 10 +- .../kubernetes/crd/kubernetes_test.go | 66 +-- pkg/provider/kubernetes/crd/kubernetes_udp.go | 6 +- .../crd/traefikio/v1alpha1/register.go | 8 +- pkg/provider/kubernetes/gateway/client.go | 90 ++-- .../kubernetes/gateway/client_mock_test.go | 48 +- .../kubernetes/gateway/client_test.go | 70 +-- pkg/provider/kubernetes/gateway/kubernetes.go | 224 ++++----- .../kubernetes/gateway/kubernetes_test.go | 442 +++++++++--------- .../ingress/builder_ingress_test.go | 36 +- pkg/provider/kubernetes/ingress/client.go | 86 ++-- .../kubernetes/ingress/client_mock_test.go | 22 +- .../kubernetes/ingress/client_test.go | 36 +- pkg/provider/kubernetes/ingress/kubernetes.go | 18 +- .../kubernetes/ingress/kubernetes_test.go | 4 +- .../kubernetes/k8s/event_handler_test.go | 10 +- pkg/provider/kubernetes/k8s/parser.go | 4 +- pkg/server/service/roundtripper_test.go | 3 - 25 files changed, 817 insertions(+), 743 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c8baa7f6b..3af93d19e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,9 +6,10 @@ run: linters-settings: govet: - check-shadowing: false - golint: - min-confidence: 0 + enable-all: true + disable: + - shadow + - fieldalignment gocyclo: min-complexity: 14 goconst: @@ -33,40 +34,112 @@ linters-settings: keywords: - FIXME importas: - corev1: k8s.io/api/core/v1 - networkingv1beta1: k8s.io/api/networking/v1beta1 - extensionsv1beta1: k8s.io/api/extensions/v1beta1 - metav1: k8s.io/apimachinery/pkg/apis/meta/v1 - kubeerror: k8s.io/apimachinery/pkg/api/errors - composeapi: github.com/docker/compose/v2/pkg/api + no-unaliased: true + alias: + - alias: composeapi + pkg: github.com/docker/compose/v2/pkg/api + + # Standard Kubernetes rewrites: + - alias: corev1 + pkg: "k8s.io/api/core/v1" + - alias: netv1 + pkg: "k8s.io/api/networking/v1" + - alias: netv1beta1 + pkg: "k8s.io/api/networking/v1beta1" + - alias: admv1 + pkg: "k8s.io/api/admission/v1" + - alias: admv1beta1 + pkg: "k8s.io/api/admission/v1beta1" + - alias: extv1beta1 + pkg: "k8s.io/api/extensions/v1beta1" + - alias: metav1 + pkg: "k8s.io/apimachinery/pkg/apis/meta/v1" + - alias: ktypes + pkg: "k8s.io/apimachinery/pkg/types" + - alias: kerror + pkg: "k8s.io/apimachinery/pkg/api/errors" + - alias: kclientset + pkg: "k8s.io/client-go/kubernetes" + - alias: kinformers + pkg: "k8s.io/client-go/informers" + - alias: ktesting + pkg: "k8s.io/client-go/testing" + - alias: kschema + pkg: "k8s.io/apimachinery/pkg/runtime/schema" + - alias: kscheme + pkg: "k8s.io/client-go/kubernetes/scheme" + - alias: kversion + pkg: "k8s.io/apimachinery/pkg/version" + - alias: kubefake + pkg: "k8s.io/client-go/kubernetes/fake" + - alias: discoveryfake + pkg: "k8s.io/client-go/discovery/fake" + + # Kubernetes Gateway rewrites: + - alias: gateclientset + pkg: "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned" + - alias: gateinformers + pkg: "sigs.k8s.io/gateway-api/pkg/client/informers/gateway/externalversions" + - alias: gatev1alpha2 + pkg: "sigs.k8s.io/gateway-api/apis/v1alpha2" + + # Traefik Kubernetes rewrites: + - alias: containousv1alpha1 + pkg: "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikcontainous/v1alpha1" + - alias: traefikv1alpha1 + pkg: "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" + - alias: traefikclientset + pkg: "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned" + - alias: traefikinformers + pkg: "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/informers/externalversions" + - alias: traefikscheme + pkg: "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned/scheme" + - alias: traefikcrdfake + pkg: "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake" + tagalign: + align: false + sort: true + order: + - description + - json + - toml + - yaml + - yml + - label + - label-slice-as-struct + - file + - kv + - export revive: rules: - name: struct-tag - rules: - - name: blank-imports - - name: context-as-argument - - name: context-keys-type - - name: dot-imports - - name: error-return - - name: error-strings - - name: error-naming - - name: exported - - name: if-return - - name: increment-decrement - - name: var-naming - - name: var-declaration - - name: package-comments - - name: range - - name: receiver-naming - - name: time-naming - - name: unexported-return - - name: indent-error-flow - - name: errorf - - name: empty-block - - name: superfluous-else - - name: unused-parameter - - name: unreachable-code - - name: redefines-builtin-id + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + disabled: true + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + disabled: true + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: unused-parameter + disabled: true + - name: unreachable-code + - name: redefines-builtin-id gomoddirectives: replace-allow-list: - github.com/abbot/go-http-auth @@ -183,3 +256,7 @@ issues: text: "Function 'loadConfigurationFromCRD' has too many statements" linters: - funlen + - path: pkg/provider/kubernetes/gateway/client_mock_test.go + text: 'unusedwrite: unused write to field' + linters: + - govet diff --git a/pkg/provider/kubernetes/crd/client.go b/pkg/provider/kubernetes/crd/client.go index 44e0cb29c..c56ea9013 100644 --- a/pkg/provider/kubernetes/crd/client.go +++ b/pkg/provider/kubernetes/crd/client.go @@ -9,17 +9,17 @@ import ( "time" "github.com/rs/zerolog/log" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/informers/externalversions" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" + traefikclientset "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned" + traefikinformers "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/informers/externalversions" + traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/version" corev1 "k8s.io/api/core/v1" - kubeerror "k8s.io/apimachinery/pkg/api/errors" + kerror "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/informers" - "k8s.io/client-go/kubernetes" + kinformers "k8s.io/client-go/informers" + kclientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" ) @@ -31,17 +31,17 @@ const resyncPeriod = 10 * time.Minute // The stores can then be accessed via the Get* functions. type Client interface { WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) - GetIngressRoutes() []*v1alpha1.IngressRoute - GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP - GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP - GetMiddlewares() []*v1alpha1.Middleware - GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP - GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) - GetTraefikServices() []*v1alpha1.TraefikService - GetTLSOptions() []*v1alpha1.TLSOption - GetServersTransports() []*v1alpha1.ServersTransport - GetServersTransportTCPs() []*v1alpha1.ServersTransportTCP - GetTLSStores() []*v1alpha1.TLSStore + GetIngressRoutes() []*traefikv1alpha1.IngressRoute + GetIngressRouteTCPs() []*traefikv1alpha1.IngressRouteTCP + GetIngressRouteUDPs() []*traefikv1alpha1.IngressRouteUDP + GetMiddlewares() []*traefikv1alpha1.Middleware + GetMiddlewareTCPs() []*traefikv1alpha1.MiddlewareTCP + GetTraefikService(namespace, name string) (*traefikv1alpha1.TraefikService, bool, error) + GetTraefikServices() []*traefikv1alpha1.TraefikService + GetTLSOptions() []*traefikv1alpha1.TLSOption + GetServersTransports() []*traefikv1alpha1.ServersTransport + GetServersTransportTCPs() []*traefikv1alpha1.ServersTransportTCP + GetTLSStores() []*traefikv1alpha1.TLSStore GetService(namespace, name string) (*corev1.Service, bool, error) GetSecret(namespace, name string) (*corev1.Secret, bool, error) GetEndpoints(namespace, name string) (*corev1.Endpoints, bool, error) @@ -49,12 +49,12 @@ type Client interface { // TODO: add tests for the clientWrapper (and its methods) itself. type clientWrapper struct { - csCrd versioned.Interface - csKube kubernetes.Interface + csCrd traefikclientset.Interface + csKube kclientset.Interface - factoriesCrd map[string]externalversions.SharedInformerFactory - factoriesKube map[string]informers.SharedInformerFactory - factoriesSecret map[string]informers.SharedInformerFactory + factoriesCrd map[string]traefikinformers.SharedInformerFactory + factoriesKube map[string]kinformers.SharedInformerFactory + factoriesSecret map[string]kinformers.SharedInformerFactory labelSelector string @@ -71,12 +71,12 @@ func createClientFromConfig(c *rest.Config) (*clientWrapper, error) { runtime.GOARCH, ) - csCrd, err := versioned.NewForConfig(c) + csCrd, err := traefikclientset.NewForConfig(c) if err != nil { return nil, err } - csKube, err := kubernetes.NewForConfig(c) + csKube, err := kclientset.NewForConfig(c) if err != nil { return nil, err } @@ -84,13 +84,13 @@ func createClientFromConfig(c *rest.Config) (*clientWrapper, error) { return newClientImpl(csKube, csCrd), nil } -func newClientImpl(csKube kubernetes.Interface, csCrd versioned.Interface) *clientWrapper { +func newClientImpl(csKube kclientset.Interface, csCrd traefikclientset.Interface) *clientWrapper { return &clientWrapper{ csCrd: csCrd, csKube: csKube, - factoriesCrd: make(map[string]externalversions.SharedInformerFactory), - factoriesKube: make(map[string]informers.SharedInformerFactory), - factoriesSecret: make(map[string]informers.SharedInformerFactory), + factoriesCrd: make(map[string]traefikinformers.SharedInformerFactory), + factoriesKube: make(map[string]kinformers.SharedInformerFactory), + factoriesSecret: make(map[string]kinformers.SharedInformerFactory), } } @@ -163,7 +163,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< } for _, ns := range namespaces { - factoryCrd := externalversions.NewSharedInformerFactoryWithOptions(c.csCrd, resyncPeriod, externalversions.WithNamespace(ns), externalversions.WithTweakListOptions(matchesLabelSelector)) + factoryCrd := traefikinformers.NewSharedInformerFactoryWithOptions(c.csCrd, resyncPeriod, traefikinformers.WithNamespace(ns), traefikinformers.WithTweakListOptions(matchesLabelSelector)) factoryCrd.Traefik().V1alpha1().IngressRoutes().Informer().AddEventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().Middlewares().Informer().AddEventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().MiddlewareTCPs().Informer().AddEventHandler(eventHandler) @@ -175,11 +175,11 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< factoryCrd.Traefik().V1alpha1().TLSStores().Informer().AddEventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().TraefikServices().Informer().AddEventHandler(eventHandler) - factoryKube := informers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, informers.WithNamespace(ns)) + factoryKube := kinformers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, kinformers.WithNamespace(ns)) factoryKube.Core().V1().Services().Informer().AddEventHandler(eventHandler) factoryKube.Core().V1().Endpoints().Informer().AddEventHandler(eventHandler) - factorySecret := informers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, informers.WithNamespace(ns), informers.WithTweakListOptions(notOwnedByHelm)) + factorySecret := kinformers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, kinformers.WithNamespace(ns), kinformers.WithTweakListOptions(notOwnedByHelm)) factorySecret.Core().V1().Secrets().Informer().AddEventHandler(eventHandler) c.factoriesCrd[ns] = factoryCrd @@ -216,8 +216,8 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< return eventCh, nil } -func (c *clientWrapper) GetIngressRoutes() []*v1alpha1.IngressRoute { - var result []*v1alpha1.IngressRoute +func (c *clientWrapper) GetIngressRoutes() []*traefikv1alpha1.IngressRoute { + var result []*traefikv1alpha1.IngressRoute for ns, factory := range c.factoriesCrd { ings, err := factory.Traefik().V1alpha1().IngressRoutes().Lister().List(labels.Everything()) @@ -230,8 +230,8 @@ func (c *clientWrapper) GetIngressRoutes() []*v1alpha1.IngressRoute { return result } -func (c *clientWrapper) GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP { - var result []*v1alpha1.IngressRouteTCP +func (c *clientWrapper) GetIngressRouteTCPs() []*traefikv1alpha1.IngressRouteTCP { + var result []*traefikv1alpha1.IngressRouteTCP for ns, factory := range c.factoriesCrd { ings, err := factory.Traefik().V1alpha1().IngressRouteTCPs().Lister().List(labels.Everything()) @@ -244,8 +244,8 @@ func (c *clientWrapper) GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP { return result } -func (c *clientWrapper) GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP { - var result []*v1alpha1.IngressRouteUDP +func (c *clientWrapper) GetIngressRouteUDPs() []*traefikv1alpha1.IngressRouteUDP { + var result []*traefikv1alpha1.IngressRouteUDP for ns, factory := range c.factoriesCrd { ings, err := factory.Traefik().V1alpha1().IngressRouteUDPs().Lister().List(labels.Everything()) @@ -258,8 +258,8 @@ func (c *clientWrapper) GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP { return result } -func (c *clientWrapper) GetMiddlewares() []*v1alpha1.Middleware { - var result []*v1alpha1.Middleware +func (c *clientWrapper) GetMiddlewares() []*traefikv1alpha1.Middleware { + var result []*traefikv1alpha1.Middleware for ns, factory := range c.factoriesCrd { middlewares, err := factory.Traefik().V1alpha1().Middlewares().Lister().List(labels.Everything()) @@ -272,8 +272,8 @@ func (c *clientWrapper) GetMiddlewares() []*v1alpha1.Middleware { return result } -func (c *clientWrapper) GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP { - var result []*v1alpha1.MiddlewareTCP +func (c *clientWrapper) GetMiddlewareTCPs() []*traefikv1alpha1.MiddlewareTCP { + var result []*traefikv1alpha1.MiddlewareTCP for ns, factory := range c.factoriesCrd { middlewares, err := factory.Traefik().V1alpha1().MiddlewareTCPs().Lister().List(labels.Everything()) @@ -287,7 +287,7 @@ func (c *clientWrapper) GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP { } // GetTraefikService returns the named service from the given namespace. -func (c *clientWrapper) GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) { +func (c *clientWrapper) GetTraefikService(namespace, name string) (*traefikv1alpha1.TraefikService, bool, error) { if !c.isWatchedNamespace(namespace) { return nil, false, fmt.Errorf("failed to get service %s/%s: namespace is not within watched namespaces", namespace, name) } @@ -298,8 +298,8 @@ func (c *clientWrapper) GetTraefikService(namespace, name string) (*v1alpha1.Tra return service, exist, err } -func (c *clientWrapper) GetTraefikServices() []*v1alpha1.TraefikService { - var result []*v1alpha1.TraefikService +func (c *clientWrapper) GetTraefikServices() []*traefikv1alpha1.TraefikService { + var result []*traefikv1alpha1.TraefikService for ns, factory := range c.factoriesCrd { traefikServices, err := factory.Traefik().V1alpha1().TraefikServices().Lister().List(labels.Everything()) @@ -313,8 +313,8 @@ func (c *clientWrapper) GetTraefikServices() []*v1alpha1.TraefikService { } // GetServersTransports returns all ServersTransport. -func (c *clientWrapper) GetServersTransports() []*v1alpha1.ServersTransport { - var result []*v1alpha1.ServersTransport +func (c *clientWrapper) GetServersTransports() []*traefikv1alpha1.ServersTransport { + var result []*traefikv1alpha1.ServersTransport for ns, factory := range c.factoriesCrd { serversTransports, err := factory.Traefik().V1alpha1().ServersTransports().Lister().List(labels.Everything()) @@ -328,8 +328,8 @@ func (c *clientWrapper) GetServersTransports() []*v1alpha1.ServersTransport { } // GetServersTransportTCPs returns all ServersTransportTCP. -func (c *clientWrapper) GetServersTransportTCPs() []*v1alpha1.ServersTransportTCP { - var result []*v1alpha1.ServersTransportTCP +func (c *clientWrapper) GetServersTransportTCPs() []*traefikv1alpha1.ServersTransportTCP { + var result []*traefikv1alpha1.ServersTransportTCP for ns, factory := range c.factoriesCrd { serversTransports, err := factory.Traefik().V1alpha1().ServersTransportTCPs().Lister().List(labels.Everything()) @@ -343,8 +343,8 @@ func (c *clientWrapper) GetServersTransportTCPs() []*v1alpha1.ServersTransportTC } // GetTLSOptions returns all TLS options. -func (c *clientWrapper) GetTLSOptions() []*v1alpha1.TLSOption { - var result []*v1alpha1.TLSOption +func (c *clientWrapper) GetTLSOptions() []*traefikv1alpha1.TLSOption { + var result []*traefikv1alpha1.TLSOption for ns, factory := range c.factoriesCrd { options, err := factory.Traefik().V1alpha1().TLSOptions().Lister().List(labels.Everything()) @@ -358,8 +358,8 @@ func (c *clientWrapper) GetTLSOptions() []*v1alpha1.TLSOption { } // GetTLSStores returns all TLS stores. -func (c *clientWrapper) GetTLSStores() []*v1alpha1.TLSStore { - var result []*v1alpha1.TLSStore +func (c *clientWrapper) GetTLSStores() []*traefikv1alpha1.TLSStore { + var result []*traefikv1alpha1.TLSStore for ns, factory := range c.factoriesCrd { stores, err := factory.Traefik().V1alpha1().TLSStores().Lister().List(labels.Everything()) @@ -435,7 +435,7 @@ func (c *clientWrapper) isWatchedNamespace(ns string) bool { // translateNotFoundError will translate a "not found" error to a boolean return // value which indicates if the resource exists and a nil error. func translateNotFoundError(err error) (bool, error) { - if kubeerror.IsNotFound(err) { + if kerror.IsNotFound(err) { return false, nil } return err == nil, err diff --git a/pkg/provider/kubernetes/crd/client_mock_test.go b/pkg/provider/kubernetes/crd/client_mock_test.go index 7509fc2ef..548966123 100644 --- a/pkg/provider/kubernetes/crd/client_mock_test.go +++ b/pkg/provider/kubernetes/crd/client_mock_test.go @@ -5,17 +5,17 @@ import ( "os" "path/filepath" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" + traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" corev1 "k8s.io/api/core/v1" - "k8s.io/client-go/kubernetes/scheme" + kscheme "k8s.io/client-go/kubernetes/scheme" ) var _ Client = (*clientMock)(nil) func init() { // required by k8s.MustParseYaml - err := v1alpha1.AddToScheme(scheme.Scheme) + err := traefikv1alpha1.AddToScheme(kscheme.Scheme) if err != nil { panic(err) } @@ -30,16 +30,16 @@ type clientMock struct { apiSecretError error apiEndpointsError error - ingressRoutes []*v1alpha1.IngressRoute - ingressRouteTCPs []*v1alpha1.IngressRouteTCP - ingressRouteUDPs []*v1alpha1.IngressRouteUDP - middlewares []*v1alpha1.Middleware - middlewareTCPs []*v1alpha1.MiddlewareTCP - tlsOptions []*v1alpha1.TLSOption - tlsStores []*v1alpha1.TLSStore - traefikServices []*v1alpha1.TraefikService - serversTransports []*v1alpha1.ServersTransport - serversTransportTCPs []*v1alpha1.ServersTransportTCP + ingressRoutes []*traefikv1alpha1.IngressRoute + ingressRouteTCPs []*traefikv1alpha1.IngressRouteTCP + ingressRouteUDPs []*traefikv1alpha1.IngressRouteUDP + middlewares []*traefikv1alpha1.Middleware + middlewareTCPs []*traefikv1alpha1.MiddlewareTCP + tlsOptions []*traefikv1alpha1.TLSOption + tlsStores []*traefikv1alpha1.TLSStore + traefikServices []*traefikv1alpha1.TraefikService + serversTransports []*traefikv1alpha1.ServersTransport + serversTransportTCPs []*traefikv1alpha1.ServersTransportTCP watchChan chan interface{} } @@ -60,25 +60,25 @@ func newClientMock(paths ...string) clientMock { c.services = append(c.services, o) case *corev1.Endpoints: c.endpoints = append(c.endpoints, o) - case *v1alpha1.IngressRoute: + case *traefikv1alpha1.IngressRoute: c.ingressRoutes = append(c.ingressRoutes, o) - case *v1alpha1.IngressRouteTCP: + case *traefikv1alpha1.IngressRouteTCP: c.ingressRouteTCPs = append(c.ingressRouteTCPs, o) - case *v1alpha1.IngressRouteUDP: + case *traefikv1alpha1.IngressRouteUDP: c.ingressRouteUDPs = append(c.ingressRouteUDPs, o) - case *v1alpha1.Middleware: + case *traefikv1alpha1.Middleware: c.middlewares = append(c.middlewares, o) - case *v1alpha1.MiddlewareTCP: + case *traefikv1alpha1.MiddlewareTCP: c.middlewareTCPs = append(c.middlewareTCPs, o) - case *v1alpha1.TraefikService: + case *traefikv1alpha1.TraefikService: c.traefikServices = append(c.traefikServices, o) - case *v1alpha1.TLSOption: + case *traefikv1alpha1.TLSOption: c.tlsOptions = append(c.tlsOptions, o) - case *v1alpha1.ServersTransport: + case *traefikv1alpha1.ServersTransport: c.serversTransports = append(c.serversTransports, o) - case *v1alpha1.ServersTransportTCP: + case *traefikv1alpha1.ServersTransportTCP: c.serversTransportTCPs = append(c.serversTransportTCPs, o) - case *v1alpha1.TLSStore: + case *traefikv1alpha1.TLSStore: c.tlsStores = append(c.tlsStores, o) case *corev1.Secret: c.secrets = append(c.secrets, o) @@ -91,27 +91,27 @@ func newClientMock(paths ...string) clientMock { return c } -func (c clientMock) GetIngressRoutes() []*v1alpha1.IngressRoute { +func (c clientMock) GetIngressRoutes() []*traefikv1alpha1.IngressRoute { return c.ingressRoutes } -func (c clientMock) GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP { +func (c clientMock) GetIngressRouteTCPs() []*traefikv1alpha1.IngressRouteTCP { return c.ingressRouteTCPs } -func (c clientMock) GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP { +func (c clientMock) GetIngressRouteUDPs() []*traefikv1alpha1.IngressRouteUDP { return c.ingressRouteUDPs } -func (c clientMock) GetMiddlewares() []*v1alpha1.Middleware { +func (c clientMock) GetMiddlewares() []*traefikv1alpha1.Middleware { return c.middlewares } -func (c clientMock) GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP { +func (c clientMock) GetMiddlewareTCPs() []*traefikv1alpha1.MiddlewareTCP { return c.middlewareTCPs } -func (c clientMock) GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) { +func (c clientMock) GetTraefikService(namespace, name string) (*traefikv1alpha1.TraefikService, bool, error) { for _, svc := range c.traefikServices { if svc.Namespace == namespace && svc.Name == name { return svc, true, nil @@ -121,27 +121,27 @@ func (c clientMock) GetTraefikService(namespace, name string) (*v1alpha1.Traefik return nil, false, nil } -func (c clientMock) GetTraefikServices() []*v1alpha1.TraefikService { +func (c clientMock) GetTraefikServices() []*traefikv1alpha1.TraefikService { return c.traefikServices } -func (c clientMock) GetTLSOptions() []*v1alpha1.TLSOption { +func (c clientMock) GetTLSOptions() []*traefikv1alpha1.TLSOption { return c.tlsOptions } -func (c clientMock) GetTLSStores() []*v1alpha1.TLSStore { +func (c clientMock) GetTLSStores() []*traefikv1alpha1.TLSStore { return c.tlsStores } -func (c clientMock) GetServersTransports() []*v1alpha1.ServersTransport { +func (c clientMock) GetServersTransports() []*traefikv1alpha1.ServersTransport { return c.serversTransports } -func (c clientMock) GetServersTransportTCPs() []*v1alpha1.ServersTransportTCP { +func (c clientMock) GetServersTransportTCPs() []*traefikv1alpha1.ServersTransportTCP { return c.serversTransportTCPs } -func (c clientMock) GetTLSOption(namespace, name string) (*v1alpha1.TLSOption, bool, error) { +func (c clientMock) GetTLSOption(namespace, name string) (*traefikv1alpha1.TLSOption, bool, error) { for _, option := range c.tlsOptions { if option.Namespace == namespace && option.Name == name { return option, true, nil diff --git a/pkg/provider/kubernetes/crd/client_test.go b/pkg/provider/kubernetes/crd/client_test.go index 5d64d08f7..5d71b6a78 100644 --- a/pkg/provider/kubernetes/crd/client_test.go +++ b/pkg/provider/kubernetes/crd/client_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - crdfake "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake" + traefikcrdfake "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubefake "k8s.io/client-go/kubernetes/fake" @@ -30,7 +30,7 @@ func TestClientIgnoresHelmOwnedSecrets(t *testing.T) { } kubeClient := kubefake.NewSimpleClientset(helmSecret, secret) - crdClient := crdfake.NewSimpleClientset() + crdClient := traefikcrdfake.NewSimpleClientset() client := newClientImpl(kubeClient, crdClient) diff --git a/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake/clientset_generated.go b/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake/clientset_generated.go index 55b5edcb2..add7b0804 100644 --- a/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake/clientset_generated.go @@ -33,7 +33,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" - fakediscovery "k8s.io/client-go/discovery/fake" + discoveryfake "k8s.io/client-go/discovery/fake" "k8s.io/client-go/testing" ) @@ -50,7 +50,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { } cs := &Clientset{tracker: o} - cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.discovery = &discoveryfake.FakeDiscovery{Fake: &cs.Fake} cs.AddReactor("*", "*", testing.ObjectReaction(o)) cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { gvr := action.GetResource() @@ -70,7 +70,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset { // you want to test easier. type Clientset struct { testing.Fake - discovery *fakediscovery.FakeDiscovery + discovery *discoveryfake.FakeDiscovery tracker testing.ObjectTracker } diff --git a/pkg/provider/kubernetes/crd/kubernetes.go b/pkg/provider/kubernetes/crd/kubernetes.go index c0180b639..8d831d4e0 100644 --- a/pkg/provider/kubernetes/crd/kubernetes.go +++ b/pkg/provider/kubernetes/crd/kubernetes.go @@ -25,7 +25,7 @@ import ( "github.com/traefik/traefik/v3/pkg/job" "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/provider" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" + traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/types" @@ -598,7 +598,7 @@ func getSecretValue(c Client, ns, urn string) (string, error) { return string(secretValue), nil } -func createCircuitBreakerMiddleware(circuitBreaker *v1alpha1.CircuitBreaker) (*dynamic.CircuitBreaker, error) { +func createCircuitBreakerMiddleware(circuitBreaker *traefikv1alpha1.CircuitBreaker) (*dynamic.CircuitBreaker, error) { if circuitBreaker == nil { return nil, nil } @@ -627,7 +627,7 @@ func createCircuitBreakerMiddleware(circuitBreaker *v1alpha1.CircuitBreaker) (*d return cb, nil } -func createRateLimitMiddleware(rateLimit *v1alpha1.RateLimit) (*dynamic.RateLimit, error) { +func createRateLimitMiddleware(rateLimit *traefikv1alpha1.RateLimit) (*dynamic.RateLimit, error) { if rateLimit == nil { return nil, nil } @@ -653,7 +653,7 @@ func createRateLimitMiddleware(rateLimit *v1alpha1.RateLimit) (*dynamic.RateLimi return rl, nil } -func createRetryMiddleware(retry *v1alpha1.Retry) (*dynamic.Retry, error) { +func createRetryMiddleware(retry *traefikv1alpha1.Retry) (*dynamic.Retry, error) { if retry == nil { return nil, nil } @@ -668,7 +668,7 @@ func createRetryMiddleware(retry *v1alpha1.Retry) (*dynamic.Retry, error) { return r, nil } -func (p *Provider) createErrorPageMiddleware(client Client, namespace string, errorPage *v1alpha1.ErrorPage) (*dynamic.ErrorPage, *dynamic.Service, error) { +func (p *Provider) createErrorPageMiddleware(client Client, namespace string, errorPage *traefikv1alpha1.ErrorPage) (*dynamic.ErrorPage, *dynamic.Service, error) { if errorPage == nil { return nil, nil, nil } @@ -693,7 +693,7 @@ func (p *Provider) createErrorPageMiddleware(client Client, namespace string, er return errorPageMiddleware, balancerServerHTTP, nil } -func createForwardAuthMiddleware(k8sClient Client, namespace string, auth *v1alpha1.ForwardAuth) (*dynamic.ForwardAuth, error) { +func createForwardAuthMiddleware(k8sClient Client, namespace string, auth *traefikv1alpha1.ForwardAuth) (*dynamic.ForwardAuth, error) { if auth == nil { return nil, nil } @@ -784,7 +784,7 @@ func loadAuthTLSSecret(namespace, secretName string, k8sClient Client) (string, return getCertificateBlocks(secret, namespace, secretName) } -func createBasicAuthMiddleware(client Client, namespace string, basicAuth *v1alpha1.BasicAuth) (*dynamic.BasicAuth, error) { +func createBasicAuthMiddleware(client Client, namespace string, basicAuth *traefikv1alpha1.BasicAuth) (*dynamic.BasicAuth, error) { if basicAuth == nil { return nil, nil } @@ -831,7 +831,7 @@ func createBasicAuthMiddleware(client Client, namespace string, basicAuth *v1alp }, nil } -func createDigestAuthMiddleware(client Client, namespace string, digestAuth *v1alpha1.DigestAuth) (*dynamic.DigestAuth, error) { +func createDigestAuthMiddleware(client Client, namespace string, digestAuth *traefikv1alpha1.DigestAuth) (*dynamic.DigestAuth, error) { if digestAuth == nil { return nil, nil } @@ -906,7 +906,7 @@ func loadAuthCredentials(secret *corev1.Secret) ([]string, error) { return credentials, nil } -func createChainMiddleware(ctx context.Context, namespace string, chain *v1alpha1.Chain) *dynamic.Chain { +func createChainMiddleware(ctx context.Context, namespace string, chain *traefikv1alpha1.Chain) *dynamic.Chain { if chain == nil { return nil } @@ -1071,7 +1071,7 @@ func buildTLSStores(ctx context.Context, client Client) (map[string]tls.Store, m } // buildCertificates loads TLSStore certificates from secrets and sets them into tlsConfigs. -func buildCertificates(client Client, tlsStore, namespace string, certificates []v1alpha1.Certificate, tlsConfigs map[string]*tls.CertAndStores) error { +func buildCertificates(client Client, tlsStore, namespace string, certificates []traefikv1alpha1.Certificate, tlsConfigs map[string]*tls.CertAndStores) error { for _, c := range certificates { configKey := namespace + "/" + c.SecretName if _, tlsExists := tlsConfigs[configKey]; !tlsExists { diff --git a/pkg/provider/kubernetes/crd/kubernetes_http.go b/pkg/provider/kubernetes/crd/kubernetes_http.go index 66eb87dcd..bdaf48f67 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_http.go +++ b/pkg/provider/kubernetes/crd/kubernetes_http.go @@ -12,7 +12,7 @@ import ( "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/provider" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" + traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/tls" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" @@ -84,8 +84,8 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli serviceName := normalized if len(route.Services) > 1 { - spec := v1alpha1.TraefikServiceSpec{ - Weighted: &v1alpha1.WeightedRoundRobin{ + spec := traefikv1alpha1.TraefikServiceSpec{ + Weighted: &traefikv1alpha1.WeightedRoundRobin{ Services: route.Services, }, } @@ -155,7 +155,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli return conf } -func (p *Provider) makeMiddlewareKeys(ctx context.Context, ingRouteNamespace string, middlewares []v1alpha1.MiddlewareRef) ([]string, error) { +func (p *Provider) makeMiddlewareKeys(ctx context.Context, ingRouteNamespace string, middlewares []traefikv1alpha1.MiddlewareRef) ([]string, error) { var mds []string for _, mi := range middlewares { @@ -203,7 +203,7 @@ type configBuilder struct { // buildTraefikService creates the configuration for the traefik service defined in tService, // and adds it to the given conf map. -func (c configBuilder) buildTraefikService(ctx context.Context, tService *v1alpha1.TraefikService, conf map[string]*dynamic.Service) error { +func (c configBuilder) buildTraefikService(ctx context.Context, tService *traefikv1alpha1.TraefikService, conf map[string]*dynamic.Service) error { id := provider.Normalize(makeID(tService.Namespace, tService.Name)) if tService.Spec.Weighted != nil { @@ -217,7 +217,7 @@ func (c configBuilder) buildTraefikService(ctx context.Context, tService *v1alph // buildServicesLB creates the configuration for the load-balancer of services named id, and defined in tService. // It adds it to the given conf map. -func (c configBuilder) buildServicesLB(ctx context.Context, namespace string, tService v1alpha1.TraefikServiceSpec, id string, conf map[string]*dynamic.Service) error { +func (c configBuilder) buildServicesLB(ctx context.Context, namespace string, tService traefikv1alpha1.TraefikServiceSpec, id string, conf map[string]*dynamic.Service) error { var wrrServices []dynamic.WRRService for _, service := range tService.Weighted.Services { @@ -252,7 +252,7 @@ func (c configBuilder) buildServicesLB(ctx context.Context, namespace string, tS // buildMirroring creates the configuration for the mirroring service named id, and defined by tService. // It adds it to the given conf map. -func (c configBuilder) buildMirroring(ctx context.Context, tService *v1alpha1.TraefikService, id string, conf map[string]*dynamic.Service) error { +func (c configBuilder) buildMirroring(ctx context.Context, tService *traefikv1alpha1.TraefikService, id string, conf map[string]*dynamic.Service) error { fullNameMain, k8sService, err := c.nameAndService(ctx, tService.Namespace, tService.Spec.Mirroring.LoadBalancerSpec) if err != nil { return err @@ -291,7 +291,7 @@ func (c configBuilder) buildMirroring(ctx context.Context, tService *v1alpha1.Tr } // buildServersLB creates the configuration for the load-balancer of servers defined by svc. -func (c configBuilder) buildServersLB(namespace string, svc v1alpha1.LoadBalancerSpec) (*dynamic.Service, error) { +func (c configBuilder) buildServersLB(namespace string, svc traefikv1alpha1.LoadBalancerSpec) (*dynamic.Service, error) { servers, err := c.loadServers(namespace, svc) if err != nil { return nil, err @@ -344,7 +344,7 @@ func (c *configBuilder) makeServersTransportKey(parentNamespace string, serversT return provider.Normalize(makeID(parentNamespace, serversTransportName)), nil } -func (c configBuilder) loadServers(parentNamespace string, svc v1alpha1.LoadBalancerSpec) ([]dynamic.Server, error) { +func (c configBuilder) loadServers(parentNamespace string, svc traefikv1alpha1.LoadBalancerSpec) ([]dynamic.Server, error) { strategy := svc.Strategy if strategy == "" { strategy = roundRobinStrategy @@ -452,7 +452,7 @@ func (c configBuilder) loadServers(parentNamespace string, svc v1alpha1.LoadBala // In addition, if the service is a Kubernetes one, // it generates and returns the configuration part for such a service, // so that the caller can add it to the global config map. -func (c configBuilder) nameAndService(ctx context.Context, parentNamespace string, service v1alpha1.LoadBalancerSpec) (string, *dynamic.Service, error) { +func (c configBuilder) nameAndService(ctx context.Context, parentNamespace string, service traefikv1alpha1.LoadBalancerSpec) (string, *dynamic.Service, error) { svcCtx := log.Ctx(ctx).With().Str(logs.ServiceName, service.Name).Logger().WithContext(ctx) namespace := namespaceOrFallback(service, parentNamespace) @@ -487,7 +487,7 @@ func splitSvcNameProvider(name string) (string, string) { return svc, pvd } -func fullServiceName(ctx context.Context, namespace string, service v1alpha1.LoadBalancerSpec, port intstr.IntOrString) string { +func fullServiceName(ctx context.Context, namespace string, service traefikv1alpha1.LoadBalancerSpec, port intstr.IntOrString) string { if (port.Type == intstr.Int && port.IntVal != 0) || (port.Type == intstr.String && port.StrVal != "") { return provider.Normalize(fmt.Sprintf("%s-%s-%s", namespace, service.Name, &port)) } @@ -508,7 +508,7 @@ func fullServiceName(ctx context.Context, namespace string, service v1alpha1.Loa return provider.Normalize(name) + providerNamespaceSeparator + pName } -func namespaceOrFallback(lb v1alpha1.LoadBalancerSpec, fallback string) string { +func namespaceOrFallback(lb traefikv1alpha1.LoadBalancerSpec, fallback string) string { if lb.Namespace != "" { return lb.Namespace } @@ -516,7 +516,7 @@ func namespaceOrFallback(lb v1alpha1.LoadBalancerSpec, fallback string) string { } // getTLSHTTP mutates tlsConfigs. -func getTLSHTTP(ctx context.Context, ingressRoute *v1alpha1.IngressRoute, k8sClient Client, tlsConfigs map[string]*tls.CertAndStores) error { +func getTLSHTTP(ctx context.Context, ingressRoute *traefikv1alpha1.IngressRoute, k8sClient Client, tlsConfigs map[string]*tls.CertAndStores) error { if ingressRoute.Spec.TLS == nil { return nil } diff --git a/pkg/provider/kubernetes/crd/kubernetes_tcp.go b/pkg/provider/kubernetes/crd/kubernetes_tcp.go index 374a2a7ab..b0759786f 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_tcp.go +++ b/pkg/provider/kubernetes/crd/kubernetes_tcp.go @@ -12,7 +12,7 @@ import ( "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/logs" "github.com/traefik/traefik/v3/pkg/provider" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" + traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/tls" corev1 "k8s.io/api/core/v1" ) @@ -144,7 +144,7 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client return conf } -func (p *Provider) makeMiddlewareTCPKeys(ctx context.Context, ingRouteTCPNamespace string, middlewares []v1alpha1.ObjectReference) ([]string, error) { +func (p *Provider) makeMiddlewareTCPKeys(ctx context.Context, ingRouteTCPNamespace string, middlewares []traefikv1alpha1.ObjectReference) ([]string, error) { var mds []string for _, mi := range middlewares { @@ -173,7 +173,7 @@ func (p *Provider) makeMiddlewareTCPKeys(ctx context.Context, ingRouteTCPNamespa return mds, nil } -func (p *Provider) createLoadBalancerServerTCP(client Client, parentNamespace string, service v1alpha1.ServiceTCP) (*dynamic.TCPService, error) { +func (p *Provider) createLoadBalancerServerTCP(client Client, parentNamespace string, service traefikv1alpha1.ServiceTCP) (*dynamic.TCPService, error) { ns := parentNamespace if len(service.Namespace) > 0 { if !isNamespaceAllowed(p.AllowCrossNamespace, parentNamespace, service.Namespace) { @@ -213,7 +213,7 @@ func (p *Provider) createLoadBalancerServerTCP(client Client, parentNamespace st return tcpService, nil } -func (p *Provider) loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([]dynamic.TCPServer, error) { +func (p *Provider) loadTCPServers(client Client, namespace string, svc traefikv1alpha1.ServiceTCP) ([]dynamic.TCPServer, error) { service, exists, err := client.GetService(namespace, svc.Name) if err != nil { return nil, err @@ -304,7 +304,7 @@ func (p *Provider) makeTCPServersTransportKey(parentNamespace string, serversTra } // getTLSTCP mutates tlsConfigs. -func getTLSTCP(ctx context.Context, ingressRoute *v1alpha1.IngressRouteTCP, k8sClient Client, tlsConfigs map[string]*tls.CertAndStores) error { +func getTLSTCP(ctx context.Context, ingressRoute *traefikv1alpha1.IngressRouteTCP, k8sClient Client, tlsConfigs map[string]*tls.CertAndStores) error { if ingressRoute.Spec.TLS == nil { return nil } diff --git a/pkg/provider/kubernetes/crd/kubernetes_test.go b/pkg/provider/kubernetes/crd/kubernetes_test.go index d09989ed7..ab5bb60cb 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_test.go +++ b/pkg/provider/kubernetes/crd/kubernetes_test.go @@ -14,8 +14,8 @@ import ( ptypes "github.com/traefik/paerser/types" "github.com/traefik/traefik/v3/pkg/config/dynamic" "github.com/traefik/traefik/v3/pkg/provider" - crdfake "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" + traefikcrdfake "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake" + traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" "github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/types" @@ -6400,25 +6400,25 @@ func TestCrossNamespace(t *testing.T) { switch o := obj.(type) { case *corev1.Service, *corev1.Endpoints, *corev1.Secret: k8sObjects = append(k8sObjects, o) - case *v1alpha1.IngressRoute: + case *traefikv1alpha1.IngressRoute: crdObjects = append(crdObjects, o) - case *v1alpha1.IngressRouteTCP: + case *traefikv1alpha1.IngressRouteTCP: crdObjects = append(crdObjects, o) - case *v1alpha1.IngressRouteUDP: + case *traefikv1alpha1.IngressRouteUDP: crdObjects = append(crdObjects, o) - case *v1alpha1.Middleware: + case *traefikv1alpha1.Middleware: crdObjects = append(crdObjects, o) - case *v1alpha1.MiddlewareTCP: + case *traefikv1alpha1.MiddlewareTCP: crdObjects = append(crdObjects, o) - case *v1alpha1.TraefikService: + case *traefikv1alpha1.TraefikService: crdObjects = append(crdObjects, o) - case *v1alpha1.TLSOption: + case *traefikv1alpha1.TLSOption: crdObjects = append(crdObjects, o) - case *v1alpha1.TLSStore: + case *traefikv1alpha1.TLSStore: crdObjects = append(crdObjects, o) - case *v1alpha1.ServersTransport: + case *traefikv1alpha1.ServersTransport: crdObjects = append(crdObjects, o) - case *v1alpha1.ServersTransportTCP: + case *traefikv1alpha1.ServersTransportTCP: crdObjects = append(crdObjects, o) default: } @@ -6426,7 +6426,7 @@ func TestCrossNamespace(t *testing.T) { } kubeClient := kubefake.NewSimpleClientset(k8sObjects...) - crdClient := crdfake.NewSimpleClientset(crdObjects...) + crdClient := traefikcrdfake.NewSimpleClientset(crdObjects...) client := newClientImpl(kubeClient, crdClient) @@ -6707,19 +6707,19 @@ func TestExternalNameService(t *testing.T) { switch o := obj.(type) { case *corev1.Service, *corev1.Endpoints, *corev1.Secret: k8sObjects = append(k8sObjects, o) - case *v1alpha1.IngressRoute: + case *traefikv1alpha1.IngressRoute: crdObjects = append(crdObjects, o) - case *v1alpha1.IngressRouteTCP: + case *traefikv1alpha1.IngressRouteTCP: crdObjects = append(crdObjects, o) - case *v1alpha1.IngressRouteUDP: + case *traefikv1alpha1.IngressRouteUDP: crdObjects = append(crdObjects, o) - case *v1alpha1.Middleware: + case *traefikv1alpha1.Middleware: crdObjects = append(crdObjects, o) - case *v1alpha1.TraefikService: + case *traefikv1alpha1.TraefikService: crdObjects = append(crdObjects, o) - case *v1alpha1.TLSOption: + case *traefikv1alpha1.TLSOption: crdObjects = append(crdObjects, o) - case *v1alpha1.TLSStore: + case *traefikv1alpha1.TLSStore: crdObjects = append(crdObjects, o) default: } @@ -6727,7 +6727,7 @@ func TestExternalNameService(t *testing.T) { } kubeClient := kubefake.NewSimpleClientset(k8sObjects...) - crdClient := crdfake.NewSimpleClientset(crdObjects...) + crdClient := traefikcrdfake.NewSimpleClientset(crdObjects...) client := newClientImpl(kubeClient, crdClient) @@ -6920,19 +6920,19 @@ func TestNativeLB(t *testing.T) { switch o := obj.(type) { case *corev1.Service, *corev1.Endpoints, *corev1.Secret: k8sObjects = append(k8sObjects, o) - case *v1alpha1.IngressRoute: + case *traefikv1alpha1.IngressRoute: crdObjects = append(crdObjects, o) - case *v1alpha1.IngressRouteTCP: + case *traefikv1alpha1.IngressRouteTCP: crdObjects = append(crdObjects, o) - case *v1alpha1.IngressRouteUDP: + case *traefikv1alpha1.IngressRouteUDP: crdObjects = append(crdObjects, o) - case *v1alpha1.Middleware: + case *traefikv1alpha1.Middleware: crdObjects = append(crdObjects, o) - case *v1alpha1.TraefikService: + case *traefikv1alpha1.TraefikService: crdObjects = append(crdObjects, o) - case *v1alpha1.TLSOption: + case *traefikv1alpha1.TLSOption: crdObjects = append(crdObjects, o) - case *v1alpha1.TLSStore: + case *traefikv1alpha1.TLSStore: crdObjects = append(crdObjects, o) default: } @@ -6940,7 +6940,7 @@ func TestNativeLB(t *testing.T) { } kubeClient := kubefake.NewSimpleClientset(k8sObjects...) - crdClient := crdfake.NewSimpleClientset(crdObjects...) + crdClient := traefikcrdfake.NewSimpleClientset(crdObjects...) client := newClientImpl(kubeClient, crdClient) @@ -6980,7 +6980,7 @@ func TestCreateBasicAuthCredentials(t *testing.T) { } kubeClient := kubefake.NewSimpleClientset(k8sObjects...) - crdClient := crdfake.NewSimpleClientset(crdObjects...) + crdClient := traefikcrdfake.NewSimpleClientset(crdObjects...) client := newClientImpl(kubeClient, crdClient) @@ -6989,13 +6989,13 @@ func TestCreateBasicAuthCredentials(t *testing.T) { eventCh, err := client.WatchAll([]string{"default"}, stopCh) require.NoError(t, err) - if k8sObjects != nil || crdObjects != nil { + if len(k8sObjects) != 0 || len(crdObjects) != 0 { // just wait for the first event <-eventCh } // Testing for username/password components in basic-auth secret - basicAuth, secretErr := createBasicAuthMiddleware(client, "default", &v1alpha1.BasicAuth{Secret: "basic-auth-secret"}) + basicAuth, secretErr := createBasicAuthMiddleware(client, "default", &traefikv1alpha1.BasicAuth{Secret: "basic-auth-secret"}) require.NoError(t, secretErr) require.Len(t, basicAuth.Users, 1) @@ -7010,7 +7010,7 @@ func TestCreateBasicAuthCredentials(t *testing.T) { assert.True(t, auth.CheckSecret("password", hashedPassword)) // Testing for username/password components in htpasswd secret - basicAuth, secretErr = createBasicAuthMiddleware(client, "default", &v1alpha1.BasicAuth{Secret: "auth-secret"}) + basicAuth, secretErr = createBasicAuthMiddleware(client, "default", &traefikv1alpha1.BasicAuth{Secret: "auth-secret"}) require.NoError(t, secretErr) require.Len(t, basicAuth.Users, 2) diff --git a/pkg/provider/kubernetes/crd/kubernetes_udp.go b/pkg/provider/kubernetes/crd/kubernetes_udp.go index 5d0d02bb9..417e90d99 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_udp.go +++ b/pkg/provider/kubernetes/crd/kubernetes_udp.go @@ -9,7 +9,7 @@ import ( "github.com/rs/zerolog/log" "github.com/traefik/traefik/v3/pkg/config/dynamic" - "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" + traefikv1alpha1 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1" corev1 "k8s.io/api/core/v1" ) @@ -78,7 +78,7 @@ func (p *Provider) loadIngressRouteUDPConfiguration(ctx context.Context, client return conf } -func (p *Provider) createLoadBalancerServerUDP(client Client, parentNamespace string, service v1alpha1.ServiceUDP) (*dynamic.UDPService, error) { +func (p *Provider) createLoadBalancerServerUDP(client Client, parentNamespace string, service traefikv1alpha1.ServiceUDP) (*dynamic.UDPService, error) { ns := parentNamespace if len(service.Namespace) > 0 { if !isNamespaceAllowed(p.AllowCrossNamespace, parentNamespace, service.Namespace) { @@ -102,7 +102,7 @@ func (p *Provider) createLoadBalancerServerUDP(client Client, parentNamespace st return udpService, nil } -func (p *Provider) loadUDPServers(client Client, namespace string, svc v1alpha1.ServiceUDP) ([]dynamic.UDPServer, error) { +func (p *Provider) loadUDPServers(client Client, namespace string, svc traefikv1alpha1.ServiceUDP) ([]dynamic.UDPServer, error) { service, exists, err := client.GetService(namespace, svc.Name) if err != nil { return nil, err diff --git a/pkg/provider/kubernetes/crd/traefikio/v1alpha1/register.go b/pkg/provider/kubernetes/crd/traefikio/v1alpha1/register.go index e4c0d2c75..be2199db9 100644 --- a/pkg/provider/kubernetes/crd/traefikio/v1alpha1/register.go +++ b/pkg/provider/kubernetes/crd/traefikio/v1alpha1/register.go @@ -3,7 +3,7 @@ package v1alpha1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" + kschema "k8s.io/apimachinery/pkg/runtime/schema" ) // GroupName is the group name for Traefik. @@ -18,15 +18,15 @@ var ( ) // SchemeGroupVersion is group version used to register these objects. -var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} +var SchemeGroupVersion = kschema.GroupVersion{Group: GroupName, Version: "v1alpha1"} // Kind takes an unqualified kind and returns back a Group qualified GroupKind. -func Kind(kind string) schema.GroupKind { +func Kind(kind string) kschema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() } // Resource takes an unqualified resource and returns a Group qualified GroupResource. -func Resource(resource string) schema.GroupResource { +func Resource(resource string) kschema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/pkg/provider/kubernetes/gateway/client.go b/pkg/provider/kubernetes/gateway/client.go index 5ad1772bb..7fcdc4c98 100644 --- a/pkg/provider/kubernetes/gateway/client.go +++ b/pkg/provider/kubernetes/gateway/client.go @@ -9,16 +9,16 @@ import ( "github.com/rs/zerolog/log" corev1 "k8s.io/api/core/v1" - kubeerror "k8s.io/apimachinery/pkg/api/errors" + kerror "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/informers" - "k8s.io/client-go/kubernetes" + kinformers "k8s.io/client-go/informers" + kclientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "sigs.k8s.io/gateway-api/apis/v1alpha2" - "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned" - "sigs.k8s.io/gateway-api/pkg/client/informers/gateway/externalversions" + gatev1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + gateclientset "sigs.k8s.io/gateway-api/pkg/client/clientset/gateway/versioned" + gateinformers "sigs.k8s.io/gateway-api/pkg/client/informers/gateway/externalversions" ) const resyncPeriod = 10 * time.Minute @@ -33,7 +33,7 @@ func (reh *resourceEventHandler) OnAdd(obj interface{}) { func (reh *resourceEventHandler) OnUpdate(oldObj, newObj interface{}) { switch oldObj.(type) { - case *v1alpha2.GatewayClass: + case *gatev1alpha2.GatewayClass: // Skip update for gateway classes. We only manage addition or deletion for this cluster-wide resource. return default: @@ -50,13 +50,13 @@ func (reh *resourceEventHandler) OnDelete(obj interface{}) { // The stores can then be accessed via the Get* functions. type Client interface { WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) - GetGatewayClasses() ([]*v1alpha2.GatewayClass, error) - UpdateGatewayStatus(gateway *v1alpha2.Gateway, gatewayStatus v1alpha2.GatewayStatus) error - UpdateGatewayClassStatus(gatewayClass *v1alpha2.GatewayClass, condition metav1.Condition) error - GetGateways() []*v1alpha2.Gateway - GetHTTPRoutes(namespaces []string) ([]*v1alpha2.HTTPRoute, error) - GetTCPRoutes(namespaces []string) ([]*v1alpha2.TCPRoute, error) - GetTLSRoutes(namespaces []string) ([]*v1alpha2.TLSRoute, error) + GetGatewayClasses() ([]*gatev1alpha2.GatewayClass, error) + UpdateGatewayStatus(gateway *gatev1alpha2.Gateway, gatewayStatus gatev1alpha2.GatewayStatus) error + UpdateGatewayClassStatus(gatewayClass *gatev1alpha2.GatewayClass, condition metav1.Condition) error + GetGateways() []*gatev1alpha2.Gateway + GetHTTPRoutes(namespaces []string) ([]*gatev1alpha2.HTTPRoute, error) + GetTCPRoutes(namespaces []string) ([]*gatev1alpha2.TCPRoute, error) + GetTLSRoutes(namespaces []string) ([]*gatev1alpha2.TLSRoute, error) GetService(namespace, name string) (*corev1.Service, bool, error) GetSecret(namespace, name string) (*corev1.Secret, bool, error) GetEndpoints(namespace, name string) (*corev1.Endpoints, bool, error) @@ -64,14 +64,14 @@ type Client interface { } type clientWrapper struct { - csGateway versioned.Interface - csKube kubernetes.Interface + csGateway gateclientset.Interface + csKube kclientset.Interface - factoryNamespace informers.SharedInformerFactory - factoryGatewayClass externalversions.SharedInformerFactory - factoriesGateway map[string]externalversions.SharedInformerFactory - factoriesKube map[string]informers.SharedInformerFactory - factoriesSecret map[string]informers.SharedInformerFactory + factoryNamespace kinformers.SharedInformerFactory + factoryGatewayClass gateinformers.SharedInformerFactory + factoriesGateway map[string]gateinformers.SharedInformerFactory + factoriesKube map[string]kinformers.SharedInformerFactory + factoriesSecret map[string]kinformers.SharedInformerFactory isNamespaceAll bool watchedNamespaces []string @@ -80,12 +80,12 @@ type clientWrapper struct { } func createClientFromConfig(c *rest.Config) (*clientWrapper, error) { - csGateway, err := versioned.NewForConfig(c) + csGateway, err := gateclientset.NewForConfig(c) if err != nil { return nil, err } - csKube, err := kubernetes.NewForConfig(c) + csKube, err := kclientset.NewForConfig(c) if err != nil { return nil, err } @@ -93,13 +93,13 @@ func createClientFromConfig(c *rest.Config) (*clientWrapper, error) { return newClientImpl(csKube, csGateway), nil } -func newClientImpl(csKube kubernetes.Interface, csGateway versioned.Interface) *clientWrapper { +func newClientImpl(csKube kclientset.Interface, csGateway gateclientset.Interface) *clientWrapper { return &clientWrapper{ csGateway: csGateway, csKube: csKube, - factoriesGateway: make(map[string]externalversions.SharedInformerFactory), - factoriesKube: make(map[string]informers.SharedInformerFactory), - factoriesSecret: make(map[string]informers.SharedInformerFactory), + factoriesGateway: make(map[string]gateinformers.SharedInformerFactory), + factoriesKube: make(map[string]kinformers.SharedInformerFactory), + factoriesSecret: make(map[string]kinformers.SharedInformerFactory), } } @@ -171,27 +171,27 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< options.LabelSelector = c.labelSelector } - c.factoryNamespace = informers.NewSharedInformerFactory(c.csKube, resyncPeriod) + c.factoryNamespace = kinformers.NewSharedInformerFactory(c.csKube, resyncPeriod) c.factoryNamespace.Core().V1().Namespaces().Informer().AddEventHandler(eventHandler) - c.factoryGatewayClass = externalversions.NewSharedInformerFactoryWithOptions(c.csGateway, resyncPeriod, externalversions.WithTweakListOptions(labelSelectorOptions)) + c.factoryGatewayClass = gateinformers.NewSharedInformerFactoryWithOptions(c.csGateway, resyncPeriod, gateinformers.WithTweakListOptions(labelSelectorOptions)) c.factoryGatewayClass.Gateway().V1alpha2().GatewayClasses().Informer().AddEventHandler(eventHandler) // TODO manage Reference Policy // https://gateway-api.sigs.k8s.io/v1alpha2/references/spec/#gateway.networking.k8s.io/v1alpha2.ReferencePolicy for _, ns := range namespaces { - factoryGateway := externalversions.NewSharedInformerFactoryWithOptions(c.csGateway, resyncPeriod, externalversions.WithNamespace(ns)) + factoryGateway := gateinformers.NewSharedInformerFactoryWithOptions(c.csGateway, resyncPeriod, gateinformers.WithNamespace(ns)) factoryGateway.Gateway().V1alpha2().Gateways().Informer().AddEventHandler(eventHandler) factoryGateway.Gateway().V1alpha2().HTTPRoutes().Informer().AddEventHandler(eventHandler) factoryGateway.Gateway().V1alpha2().TCPRoutes().Informer().AddEventHandler(eventHandler) factoryGateway.Gateway().V1alpha2().TLSRoutes().Informer().AddEventHandler(eventHandler) - factoryKube := informers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, informers.WithNamespace(ns)) + factoryKube := kinformers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, kinformers.WithNamespace(ns)) factoryKube.Core().V1().Services().Informer().AddEventHandler(eventHandler) factoryKube.Core().V1().Endpoints().Informer().AddEventHandler(eventHandler) - factorySecret := informers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, informers.WithNamespace(ns), informers.WithTweakListOptions(notOwnedByHelm)) + factorySecret := kinformers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, kinformers.WithNamespace(ns), kinformers.WithTweakListOptions(notOwnedByHelm)) factorySecret.Core().V1().Secrets().Informer().AddEventHandler(eventHandler) c.factoriesGateway[ns] = factoryGateway @@ -260,8 +260,8 @@ func (c *clientWrapper) GetNamespaces(selector labels.Selector) ([]string, error return namespaces, nil } -func (c *clientWrapper) GetHTTPRoutes(namespaces []string) ([]*v1alpha2.HTTPRoute, error) { - var httpRoutes []*v1alpha2.HTTPRoute +func (c *clientWrapper) GetHTTPRoutes(namespaces []string) ([]*gatev1alpha2.HTTPRoute, error) { + var httpRoutes []*gatev1alpha2.HTTPRoute for _, namespace := range namespaces { if !c.isWatchedNamespace(namespace) { log.Warn().Msgf("Failed to get HTTPRoutes: %q is not within watched namespaces", namespace) @@ -284,8 +284,8 @@ func (c *clientWrapper) GetHTTPRoutes(namespaces []string) ([]*v1alpha2.HTTPRout return httpRoutes, nil } -func (c *clientWrapper) GetTCPRoutes(namespaces []string) ([]*v1alpha2.TCPRoute, error) { - var tcpRoutes []*v1alpha2.TCPRoute +func (c *clientWrapper) GetTCPRoutes(namespaces []string) ([]*gatev1alpha2.TCPRoute, error) { + var tcpRoutes []*gatev1alpha2.TCPRoute for _, namespace := range namespaces { if !c.isWatchedNamespace(namespace) { log.Warn().Msgf("Failed to get TCPRoutes: %q is not within watched namespaces", namespace) @@ -307,8 +307,8 @@ func (c *clientWrapper) GetTCPRoutes(namespaces []string) ([]*v1alpha2.TCPRoute, return tcpRoutes, nil } -func (c *clientWrapper) GetTLSRoutes(namespaces []string) ([]*v1alpha2.TLSRoute, error) { - var tlsRoutes []*v1alpha2.TLSRoute +func (c *clientWrapper) GetTLSRoutes(namespaces []string) ([]*gatev1alpha2.TLSRoute, error) { + var tlsRoutes []*gatev1alpha2.TLSRoute for _, namespace := range namespaces { if !c.isWatchedNamespace(namespace) { log.Warn().Msgf("Failed to get TLSRoutes: %q is not within watched namespaces", namespace) @@ -330,8 +330,8 @@ func (c *clientWrapper) GetTLSRoutes(namespaces []string) ([]*v1alpha2.TLSRoute, return tlsRoutes, nil } -func (c *clientWrapper) GetGateways() []*v1alpha2.Gateway { - var result []*v1alpha2.Gateway +func (c *clientWrapper) GetGateways() []*gatev1alpha2.Gateway { + var result []*gatev1alpha2.Gateway for ns, factory := range c.factoriesGateway { gateways, err := factory.Gateway().V1alpha2().Gateways().Lister().List(labels.Everything()) @@ -345,11 +345,11 @@ func (c *clientWrapper) GetGateways() []*v1alpha2.Gateway { return result } -func (c *clientWrapper) GetGatewayClasses() ([]*v1alpha2.GatewayClass, error) { +func (c *clientWrapper) GetGatewayClasses() ([]*gatev1alpha2.GatewayClass, error) { return c.factoryGatewayClass.Gateway().V1alpha2().GatewayClasses().Lister().List(labels.Everything()) } -func (c *clientWrapper) UpdateGatewayClassStatus(gatewayClass *v1alpha2.GatewayClass, condition metav1.Condition) error { +func (c *clientWrapper) UpdateGatewayClassStatus(gatewayClass *gatev1alpha2.GatewayClass, condition metav1.Condition) error { gc := gatewayClass.DeepCopy() var newConditions []metav1.Condition @@ -380,7 +380,7 @@ func (c *clientWrapper) UpdateGatewayClassStatus(gatewayClass *v1alpha2.GatewayC return nil } -func (c *clientWrapper) UpdateGatewayStatus(gateway *v1alpha2.Gateway, gatewayStatus v1alpha2.GatewayStatus) error { +func (c *clientWrapper) UpdateGatewayStatus(gateway *gatev1alpha2.Gateway, gatewayStatus gatev1alpha2.GatewayStatus) error { if !c.isWatchedNamespace(gateway.Namespace) { return fmt.Errorf("cannot update Gateway status %s/%s: namespace is not within watched namespaces", gateway.Namespace, gateway.Name) } @@ -403,7 +403,7 @@ func (c *clientWrapper) UpdateGatewayStatus(gateway *v1alpha2.Gateway, gatewaySt return nil } -func statusEquals(oldStatus, newStatus v1alpha2.GatewayStatus) bool { +func statusEquals(oldStatus, newStatus gatev1alpha2.GatewayStatus) bool { if len(oldStatus.Listeners) != len(newStatus.Listeners) { return false } @@ -510,7 +510,7 @@ func eventHandlerFunc(events chan<- interface{}, obj interface{}) { // translateNotFoundError will translate a "not found" error to a boolean return // value which indicates if the resource exists and a nil error. func translateNotFoundError(err error) (bool, error) { - if kubeerror.IsNotFound(err) { + if kerror.IsNotFound(err) { return false, nil } return err == nil, err diff --git a/pkg/provider/kubernetes/gateway/client_mock_test.go b/pkg/provider/kubernetes/gateway/client_mock_test.go index 1003a777c..10c78801c 100644 --- a/pkg/provider/kubernetes/gateway/client_mock_test.go +++ b/pkg/provider/kubernetes/gateway/client_mock_test.go @@ -9,15 +9,15 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/kubernetes/scheme" - "sigs.k8s.io/gateway-api/apis/v1alpha2" + kscheme "k8s.io/client-go/kubernetes/scheme" + gatev1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" ) var _ Client = (*clientMock)(nil) func init() { // required by k8s.MustParseYaml - err := v1alpha2.AddToScheme(scheme.Scheme) + err := gatev1alpha2.AddToScheme(kscheme.Scheme) if err != nil { panic(err) } @@ -33,11 +33,11 @@ type clientMock struct { apiSecretError error apiEndpointsError error - gatewayClasses []*v1alpha2.GatewayClass - gateways []*v1alpha2.Gateway - httpRoutes []*v1alpha2.HTTPRoute - tcpRoutes []*v1alpha2.TCPRoute - tlsRoutes []*v1alpha2.TLSRoute + gatewayClasses []*gatev1alpha2.GatewayClass + gateways []*gatev1alpha2.Gateway + httpRoutes []*gatev1alpha2.HTTPRoute + tcpRoutes []*gatev1alpha2.TCPRoute + tlsRoutes []*gatev1alpha2.TLSRoute watchChan chan interface{} } @@ -62,15 +62,15 @@ func newClientMock(paths ...string) clientMock { c.namespaces = append(c.namespaces, o) case *corev1.Endpoints: c.endpoints = append(c.endpoints, o) - case *v1alpha2.GatewayClass: + case *gatev1alpha2.GatewayClass: c.gatewayClasses = append(c.gatewayClasses, o) - case *v1alpha2.Gateway: + case *gatev1alpha2.Gateway: c.gateways = append(c.gateways, o) - case *v1alpha2.HTTPRoute: + case *gatev1alpha2.HTTPRoute: c.httpRoutes = append(c.httpRoutes, o) - case *v1alpha2.TCPRoute: + case *gatev1alpha2.TCPRoute: c.tcpRoutes = append(c.tcpRoutes, o) - case *v1alpha2.TLSRoute: + case *gatev1alpha2.TLSRoute: c.tlsRoutes = append(c.tlsRoutes, o) default: panic(fmt.Sprintf("Unknown runtime object %+v %T", o, o)) @@ -81,7 +81,7 @@ func newClientMock(paths ...string) clientMock { return c } -func (c clientMock) UpdateGatewayStatus(gateway *v1alpha2.Gateway, gatewayStatus v1alpha2.GatewayStatus) error { +func (c clientMock) UpdateGatewayStatus(gateway *gatev1alpha2.Gateway, gatewayStatus gatev1alpha2.GatewayStatus) error { for _, g := range c.gateways { if g.Name == gateway.Name { if !statusEquals(g.Status, gatewayStatus) { @@ -94,7 +94,7 @@ func (c clientMock) UpdateGatewayStatus(gateway *v1alpha2.Gateway, gatewayStatus return nil } -func (c clientMock) UpdateGatewayClassStatus(gatewayClass *v1alpha2.GatewayClass, condition metav1.Condition) error { +func (c clientMock) UpdateGatewayClassStatus(gatewayClass *gatev1alpha2.GatewayClass, condition metav1.Condition) error { for _, gc := range c.gatewayClasses { if gc.Name == gatewayClass.Name { for _, c := range gc.Status.Conditions { @@ -110,7 +110,7 @@ func (c clientMock) UpdateGatewayClassStatus(gatewayClass *v1alpha2.GatewayClass return nil } -func (c clientMock) UpdateGatewayStatusConditions(gateway *v1alpha2.Gateway, condition metav1.Condition) error { +func (c clientMock) UpdateGatewayStatusConditions(gateway *gatev1alpha2.Gateway, condition metav1.Condition) error { for _, g := range c.gatewayClasses { if g.Name == gateway.Name { for _, c := range g.Status.Conditions { @@ -126,11 +126,11 @@ func (c clientMock) UpdateGatewayStatusConditions(gateway *v1alpha2.Gateway, con return nil } -func (c clientMock) GetGatewayClasses() ([]*v1alpha2.GatewayClass, error) { +func (c clientMock) GetGatewayClasses() ([]*gatev1alpha2.GatewayClass, error) { return c.gatewayClasses, nil } -func (c clientMock) GetGateways() []*v1alpha2.Gateway { +func (c clientMock) GetGateways() []*gatev1alpha2.Gateway { return c.gateways } @@ -148,8 +148,8 @@ func (c clientMock) GetNamespaces(selector labels.Selector) ([]string, error) { return ns, nil } -func (c clientMock) GetHTTPRoutes(namespaces []string) ([]*v1alpha2.HTTPRoute, error) { - var httpRoutes []*v1alpha2.HTTPRoute +func (c clientMock) GetHTTPRoutes(namespaces []string) ([]*gatev1alpha2.HTTPRoute, error) { + var httpRoutes []*gatev1alpha2.HTTPRoute for _, namespace := range namespaces { for _, httpRoute := range c.httpRoutes { if inNamespace(httpRoute.ObjectMeta, namespace) { @@ -160,8 +160,8 @@ func (c clientMock) GetHTTPRoutes(namespaces []string) ([]*v1alpha2.HTTPRoute, e return httpRoutes, nil } -func (c clientMock) GetTCPRoutes(namespaces []string) ([]*v1alpha2.TCPRoute, error) { - var tcpRoutes []*v1alpha2.TCPRoute +func (c clientMock) GetTCPRoutes(namespaces []string) ([]*gatev1alpha2.TCPRoute, error) { + var tcpRoutes []*gatev1alpha2.TCPRoute for _, namespace := range namespaces { for _, tcpRoute := range c.tcpRoutes { if inNamespace(tcpRoute.ObjectMeta, namespace) { @@ -172,8 +172,8 @@ func (c clientMock) GetTCPRoutes(namespaces []string) ([]*v1alpha2.TCPRoute, err return tcpRoutes, nil } -func (c clientMock) GetTLSRoutes(namespaces []string) ([]*v1alpha2.TLSRoute, error) { - var tlsRoutes []*v1alpha2.TLSRoute +func (c clientMock) GetTLSRoutes(namespaces []string) ([]*gatev1alpha2.TLSRoute, error) { + var tlsRoutes []*gatev1alpha2.TLSRoute for _, namespace := range namespaces { for _, tlsRoute := range c.tlsRoutes { if inNamespace(tlsRoute.ObjectMeta, namespace) { diff --git a/pkg/provider/kubernetes/gateway/client_test.go b/pkg/provider/kubernetes/gateway/client_test.go index f90f7dfae..794f7d6a8 100644 --- a/pkg/provider/kubernetes/gateway/client_test.go +++ b/pkg/provider/kubernetes/gateway/client_test.go @@ -5,32 +5,32 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/gateway-api/apis/v1alpha2" + gatev1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" ) func TestStatusEquals(t *testing.T) { testCases := []struct { desc string - statusA v1alpha2.GatewayStatus - statusB v1alpha2.GatewayStatus + statusA gatev1alpha2.GatewayStatus + statusB gatev1alpha2.GatewayStatus expected bool }{ { desc: "Empty", - statusA: v1alpha2.GatewayStatus{}, - statusB: v1alpha2.GatewayStatus{}, + statusA: gatev1alpha2.GatewayStatus{}, + statusB: gatev1alpha2.GatewayStatus{}, expected: true, }, { desc: "Same status", - statusA: v1alpha2.GatewayStatus{ + statusA: gatev1alpha2.GatewayStatus{ Conditions: []metav1.Condition{ { Type: "foobar", Reason: "foobar", }, }, - Listeners: []v1alpha2.ListenerStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Name: "foo", Conditions: []metav1.Condition{ @@ -42,14 +42,14 @@ func TestStatusEquals(t *testing.T) { }, }, }, - statusB: v1alpha2.GatewayStatus{ + statusB: gatev1alpha2.GatewayStatus{ Conditions: []metav1.Condition{ { Type: "foobar", Reason: "foobar", }, }, - Listeners: []v1alpha2.ListenerStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Name: "foo", Conditions: []metav1.Condition{ @@ -65,11 +65,11 @@ func TestStatusEquals(t *testing.T) { }, { desc: "Listeners length not equal", - statusA: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{}, + statusA: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{}, }, - statusB: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusB: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ {}, }, }, @@ -77,10 +77,10 @@ func TestStatusEquals(t *testing.T) { }, { desc: "Gateway conditions length not equal", - statusA: v1alpha2.GatewayStatus{ + statusA: gatev1alpha2.GatewayStatus{ Conditions: []metav1.Condition{}, }, - statusB: v1alpha2.GatewayStatus{ + statusB: gatev1alpha2.GatewayStatus{ Conditions: []metav1.Condition{ {}, }, @@ -89,14 +89,14 @@ func TestStatusEquals(t *testing.T) { }, { desc: "Gateway conditions different types", - statusA: v1alpha2.GatewayStatus{ + statusA: gatev1alpha2.GatewayStatus{ Conditions: []metav1.Condition{ { Type: "foobar", }, }, }, - statusB: v1alpha2.GatewayStatus{ + statusB: gatev1alpha2.GatewayStatus{ Conditions: []metav1.Condition{ { Type: "foobir", @@ -107,14 +107,14 @@ func TestStatusEquals(t *testing.T) { }, { desc: "Gateway conditions same types but different reason", - statusA: v1alpha2.GatewayStatus{ + statusA: gatev1alpha2.GatewayStatus{ Conditions: []metav1.Condition{ { Type: "foobar", }, }, }, - statusB: v1alpha2.GatewayStatus{ + statusB: gatev1alpha2.GatewayStatus{ Conditions: []metav1.Condition{ { Type: "foobar", @@ -126,16 +126,16 @@ func TestStatusEquals(t *testing.T) { }, { desc: "Gateway listeners conditions length", - statusA: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusA: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Name: "foo", Conditions: []metav1.Condition{}, }, }, }, - statusB: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusB: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Name: "foo", Conditions: []metav1.Condition{ @@ -148,8 +148,8 @@ func TestStatusEquals(t *testing.T) { }, { desc: "Gateway listeners conditions same types but different status", - statusA: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusA: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Conditions: []metav1.Condition{ { @@ -159,8 +159,8 @@ func TestStatusEquals(t *testing.T) { }, }, }, - statusB: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusB: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Conditions: []metav1.Condition{ { @@ -175,8 +175,8 @@ func TestStatusEquals(t *testing.T) { }, { desc: "Gateway listeners conditions same types but different message", - statusA: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusA: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Conditions: []metav1.Condition{ { @@ -186,8 +186,8 @@ func TestStatusEquals(t *testing.T) { }, }, }, - statusB: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusB: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Conditions: []metav1.Condition{ { @@ -202,8 +202,8 @@ func TestStatusEquals(t *testing.T) { }, { desc: "Gateway listeners conditions same types/reason but different names", - statusA: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusA: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Name: "foo", Conditions: []metav1.Condition{ @@ -215,8 +215,8 @@ func TestStatusEquals(t *testing.T) { }, }, }, - statusB: v1alpha2.GatewayStatus{ - Listeners: []v1alpha2.ListenerStatus{ + statusB: gatev1alpha2.GatewayStatus{ + Listeners: []gatev1alpha2.ListenerStatus{ { Name: "bar", Conditions: []metav1.Condition{ diff --git a/pkg/provider/kubernetes/gateway/kubernetes.go b/pkg/provider/kubernetes/gateway/kubernetes.go index 170540394..d7a715de3 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes.go +++ b/pkg/provider/kubernetes/gateway/kubernetes.go @@ -31,7 +31,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/utils/pointer" "k8s.io/utils/strings/slices" - "sigs.k8s.io/gateway-api/apis/v1alpha2" + gatev1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" ) const ( @@ -209,14 +209,14 @@ func (p *Provider) loadConfigurationFromGateway(ctx context.Context, client Clie gatewayClassNames[gatewayClass.Name] = struct{}{} err := client.UpdateGatewayClassStatus(gatewayClass, metav1.Condition{ - Type: string(v1alpha2.GatewayClassConditionStatusAccepted), + Type: string(gatev1alpha2.GatewayClassConditionStatusAccepted), Status: metav1.ConditionTrue, Reason: "Handled", Message: "Handled by Traefik controller", LastTransitionTime: metav1.Now(), }) if err != nil { - logger.Error().Err(err).Msgf("Failed to update %s condition", v1alpha2.GatewayClassConditionStatusAccepted) + logger.Error().Err(err).Msgf("Failed to update %s condition", gatev1alpha2.GatewayClassConditionStatusAccepted) } } } @@ -272,7 +272,7 @@ func (p *Provider) loadConfigurationFromGateway(ctx context.Context, client Clie return conf } -func (p *Provider) createGatewayConf(ctx context.Context, client Client, gateway *v1alpha2.Gateway) (*dynamic.Configuration, error) { +func (p *Provider) createGatewayConf(ctx context.Context, client Client, gateway *gatev1alpha2.Gateway) (*dynamic.Configuration, error) { conf := &dynamic.Configuration{ HTTP: &dynamic.HTTPConfiguration{ Routers: map[string]*dynamic.Router{}, @@ -318,15 +318,15 @@ func (p *Provider) createGatewayConf(ctx context.Context, client Client, gateway return conf, nil } -func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway *v1alpha2.Gateway, conf *dynamic.Configuration, tlsConfigs map[string]*tls.CertAndStores) []v1alpha2.ListenerStatus { +func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway *gatev1alpha2.Gateway, conf *dynamic.Configuration, tlsConfigs map[string]*tls.CertAndStores) []gatev1alpha2.ListenerStatus { logger := log.Ctx(ctx) - listenerStatuses := make([]v1alpha2.ListenerStatus, len(gateway.Spec.Listeners)) + listenerStatuses := make([]gatev1alpha2.ListenerStatus, len(gateway.Spec.Listeners)) allocatedListeners := make(map[string]struct{}) for i, listener := range gateway.Spec.Listeners { - listenerStatuses[i] = v1alpha2.ListenerStatus{ + listenerStatuses[i] = gatev1alpha2.ListenerStatus{ Name: listener.Name, - SupportedKinds: []v1alpha2.RouteGroupKind{}, + SupportedKinds: []gatev1alpha2.RouteGroupKind{}, Conditions: []metav1.Condition{}, } @@ -348,7 +348,7 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * if _, ok := allocatedListeners[listenerKey]; ok { listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionConflicted), + Type: string(gatev1alpha2.ListenerConditionConflicted), Status: metav1.ConditionTrue, LastTransitionTime: metav1.Now(), Reason: "DuplicateListener", @@ -364,19 +364,19 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * if err != nil { // update "Detached" status with "PortUnavailable" reason listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionDetached), + Type: string(gatev1alpha2.ListenerConditionDetached), Status: metav1.ConditionTrue, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonPortUnavailable), + Reason: string(gatev1alpha2.ListenerReasonPortUnavailable), Message: fmt.Sprintf("Cannot find entryPoint for Gateway: %v", err), }) continue } - if (listener.Protocol == v1alpha2.HTTPProtocolType || listener.Protocol == v1alpha2.TCPProtocolType) && listener.TLS != nil { + if (listener.Protocol == gatev1alpha2.HTTPProtocolType || listener.Protocol == gatev1alpha2.TCPProtocolType) && listener.TLS != nil { listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionDetached), + Type: string(gatev1alpha2.ListenerConditionDetached), Status: metav1.ConditionTrue, LastTransitionTime: metav1.Now(), Reason: "InvalidTLSConfiguration", // TODO check the spec if a proper reason is introduced at some point @@ -387,11 +387,11 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * } // TLS - if listener.Protocol == v1alpha2.HTTPSProtocolType || listener.Protocol == v1alpha2.TLSProtocolType { - if listener.TLS == nil || (len(listener.TLS.CertificateRefs) == 0 && listener.TLS.Mode != nil && *listener.TLS.Mode != v1alpha2.TLSModePassthrough) { + if listener.Protocol == gatev1alpha2.HTTPSProtocolType || listener.Protocol == gatev1alpha2.TLSProtocolType { + if listener.TLS == nil || (len(listener.TLS.CertificateRefs) == 0 && listener.TLS.Mode != nil && *listener.TLS.Mode != gatev1alpha2.TLSModePassthrough) { // update "Detached" status with "UnsupportedProtocol" reason listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionDetached), + Type: string(gatev1alpha2.ListenerConditionDetached), Status: metav1.ConditionTrue, LastTransitionTime: metav1.Now(), Reason: "InvalidTLSConfiguration", // TODO check the spec if a proper reason is introduced at some point @@ -402,12 +402,12 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * continue } - var tlsModeType v1alpha2.TLSModeType + var tlsModeType gatev1alpha2.TLSModeType if listener.TLS.Mode != nil { tlsModeType = *listener.TLS.Mode } - isTLSPassthrough := tlsModeType == v1alpha2.TLSModePassthrough + isTLSPassthrough := tlsModeType == gatev1alpha2.TLSModePassthrough if isTLSPassthrough && len(listener.TLS.CertificateRefs) > 0 { // https://gateway-api.sigs.k8s.io/v1alpha2/references/spec/#gateway.networking.k8s.io/v1alpha2.GatewayTLSConfig @@ -418,12 +418,12 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * // Protocol TLS -> Passthrough -> TLSRoute/TCPRoute // Protocol TLS -> Terminate -> TLSRoute/TCPRoute // Protocol HTTPS -> Terminate -> HTTPRoute - if listener.Protocol == v1alpha2.HTTPSProtocolType && isTLSPassthrough { + if listener.Protocol == gatev1alpha2.HTTPSProtocolType && isTLSPassthrough { listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionDetached), + Type: string(gatev1alpha2.ListenerConditionDetached), Status: metav1.ConditionTrue, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonUnsupportedProtocol), + Reason: string(gatev1alpha2.ListenerReasonUnsupportedProtocol), Message: "HTTPS protocol is not supported with TLS mode Passthrough", }) @@ -434,10 +434,10 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * if len(listener.TLS.CertificateRefs) == 0 { // update "ResolvedRefs" status true with "InvalidCertificateRef" reason listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonInvalidCertificateRef), + Reason: string(gatev1alpha2.ListenerReasonInvalidCertificateRef), Message: "One TLS CertificateRef is required in Terminate mode", }) @@ -451,10 +451,10 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * certificateRef.Group == nil || (*certificateRef.Group != "" && *certificateRef.Group != "core") { // update "ResolvedRefs" status true with "InvalidCertificateRef" reason listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonInvalidCertificateRef), + Reason: string(gatev1alpha2.ListenerReasonInvalidCertificateRef), Message: fmt.Sprintf("Unsupported TLS CertificateRef group/kind: %v/%v", certificateRef.Group, certificateRef.Kind), }) @@ -464,10 +464,10 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * // TODO Support ReferencePolicy to support cross namespace references. if certificateRef.Namespace != nil && string(*certificateRef.Namespace) != gateway.Namespace { listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonInvalidCertificateRef), + Reason: string(gatev1alpha2.ListenerReasonInvalidCertificateRef), Message: "Cross namespace secrets are not supported", }) @@ -480,10 +480,10 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * if err != nil { // update "ResolvedRefs" status true with "InvalidCertificateRef" reason listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonInvalidCertificateRef), + Reason: string(gatev1alpha2.ListenerReasonInvalidCertificateRef), Message: fmt.Sprintf("Error while retrieving certificate: %v", err), }) @@ -510,10 +510,10 @@ func (p *Provider) fillGatewayConf(ctx context.Context, client Client, gateway * return listenerStatuses } -func (p *Provider) makeGatewayStatus(listenerStatuses []v1alpha2.ListenerStatus) (v1alpha2.GatewayStatus, error) { +func (p *Provider) makeGatewayStatus(listenerStatuses []gatev1alpha2.ListenerStatus) (gatev1alpha2.GatewayStatus, error) { // As Status.Addresses are not implemented yet, we initialize an empty array to follow the API expectations. - gatewayStatus := v1alpha2.GatewayStatus{ - Addresses: []v1alpha2.GatewayAddress{}, + gatewayStatus := gatev1alpha2.GatewayStatus{ + Addresses: []gatev1alpha2.GatewayAddress{}, } var result error @@ -521,7 +521,7 @@ func (p *Provider) makeGatewayStatus(listenerStatuses []v1alpha2.ListenerStatus) if len(listener.Conditions) == 0 { // GatewayConditionReady "Ready", GatewayConditionReason "ListenerReady" listenerStatuses[i].Conditions = append(listenerStatuses[i].Conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionReady), + Type: string(gatev1alpha2.ListenerConditionReady), Status: metav1.ConditionTrue, LastTransitionTime: metav1.Now(), Reason: "ListenerReady", @@ -539,10 +539,10 @@ func (p *Provider) makeGatewayStatus(listenerStatuses []v1alpha2.ListenerStatus) if result != nil { // GatewayConditionReady "Ready", GatewayConditionReason "ListenersNotValid" gatewayStatus.Conditions = append(gatewayStatus.Conditions, metav1.Condition{ - Type: string(v1alpha2.GatewayConditionReady), + Type: string(gatev1alpha2.GatewayConditionReady), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.GatewayReasonListenersNotValid), + Reason: string(gatev1alpha2.GatewayReasonListenersNotValid), Message: "All Listeners must be valid", }) @@ -554,7 +554,7 @@ func (p *Provider) makeGatewayStatus(listenerStatuses []v1alpha2.ListenerStatus) gatewayStatus.Conditions = append(gatewayStatus.Conditions, // update "Scheduled" status with "ResourcesAvailable" reason metav1.Condition{ - Type: string(v1alpha2.GatewayConditionScheduled), + Type: string(gatev1alpha2.GatewayConditionScheduled), Status: metav1.ConditionTrue, Reason: "ResourcesAvailable", Message: "Resources available", @@ -562,7 +562,7 @@ func (p *Provider) makeGatewayStatus(listenerStatuses []v1alpha2.ListenerStatus) }, // update "Ready" status with "ListenersValid" reason metav1.Condition{ - Type: string(v1alpha2.GatewayConditionReady), + Type: string(gatev1alpha2.GatewayConditionReady), Status: metav1.ConditionTrue, Reason: "ListenersValid", Message: "Listeners valid", @@ -573,14 +573,14 @@ func (p *Provider) makeGatewayStatus(listenerStatuses []v1alpha2.ListenerStatus) return gatewayStatus, nil } -func (p *Provider) entryPointName(port v1alpha2.PortNumber, protocol v1alpha2.ProtocolType) (string, error) { +func (p *Provider) entryPointName(port gatev1alpha2.PortNumber, protocol gatev1alpha2.ProtocolType) (string, error) { portStr := strconv.FormatInt(int64(port), 10) for name, entryPoint := range p.EntryPoints { if strings.HasSuffix(entryPoint.Address, ":"+portStr) { // If the protocol is HTTP the entryPoint must have no TLS conf - // Not relevant for v1alpha2.TLSProtocolType && v1alpha2.TCPProtocolType - if protocol == v1alpha2.HTTPProtocolType && entryPoint.HasHTTPTLSConf { + // Not relevant for gatev1alpha2.TLSProtocolType && gatev1alpha2.TCPProtocolType + if protocol == gatev1alpha2.HTTPProtocolType && entryPoint.HasHTTPTLSConf { continue } @@ -591,43 +591,43 @@ func (p *Provider) entryPointName(port v1alpha2.PortNumber, protocol v1alpha2.Pr return "", fmt.Errorf("no matching entryPoint for port %d and protocol %q", port, protocol) } -func supportedRouteKinds(protocol v1alpha2.ProtocolType) ([]v1alpha2.RouteGroupKind, []metav1.Condition) { - group := v1alpha2.Group(v1alpha2.GroupName) +func supportedRouteKinds(protocol gatev1alpha2.ProtocolType) ([]gatev1alpha2.RouteGroupKind, []metav1.Condition) { + group := gatev1alpha2.Group(gatev1alpha2.GroupName) switch protocol { - case v1alpha2.TCPProtocolType: - return []v1alpha2.RouteGroupKind{{Kind: kindTCPRoute, Group: &group}}, nil + case gatev1alpha2.TCPProtocolType: + return []gatev1alpha2.RouteGroupKind{{Kind: kindTCPRoute, Group: &group}}, nil - case v1alpha2.HTTPProtocolType, v1alpha2.HTTPSProtocolType: - return []v1alpha2.RouteGroupKind{{Kind: kindHTTPRoute, Group: &group}}, nil + case gatev1alpha2.HTTPProtocolType, gatev1alpha2.HTTPSProtocolType: + return []gatev1alpha2.RouteGroupKind{{Kind: kindHTTPRoute, Group: &group}}, nil - case v1alpha2.TLSProtocolType: - return []v1alpha2.RouteGroupKind{ + case gatev1alpha2.TLSProtocolType: + return []gatev1alpha2.RouteGroupKind{ {Kind: kindTCPRoute, Group: &group}, {Kind: kindTLSRoute, Group: &group}, }, nil } return nil, []metav1.Condition{{ - Type: string(v1alpha2.ListenerConditionDetached), + Type: string(gatev1alpha2.ListenerConditionDetached), Status: metav1.ConditionTrue, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonUnsupportedProtocol), + Reason: string(gatev1alpha2.ListenerReasonUnsupportedProtocol), Message: fmt.Sprintf("Unsupported listener protocol %q", protocol), }} } -func getAllowedRouteKinds(listener v1alpha2.Listener, supportedKinds []v1alpha2.RouteGroupKind) ([]v1alpha2.RouteGroupKind, []metav1.Condition) { +func getAllowedRouteKinds(listener gatev1alpha2.Listener, supportedKinds []gatev1alpha2.RouteGroupKind) ([]gatev1alpha2.RouteGroupKind, []metav1.Condition) { if listener.AllowedRoutes == nil || len(listener.AllowedRoutes.Kinds) == 0 { return supportedKinds, nil } var ( - routeKinds []v1alpha2.RouteGroupKind + routeKinds []gatev1alpha2.RouteGroupKind conditions []metav1.Condition ) - uniqRouteKinds := map[v1alpha2.Kind]struct{}{} + uniqRouteKinds := map[gatev1alpha2.Kind]struct{}{} for _, routeKind := range listener.AllowedRoutes.Kinds { var isSupported bool for _, kind := range supportedKinds { @@ -639,10 +639,10 @@ func getAllowedRouteKinds(listener v1alpha2.Listener, supportedKinds []v1alpha2. if !isSupported { conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionDetached), + Type: string(gatev1alpha2.ListenerConditionDetached), Status: metav1.ConditionTrue, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonInvalidRouteKinds), + Reason: string(gatev1alpha2.ListenerReasonInvalidRouteKinds), Message: fmt.Sprintf("Listener protocol %q does not support RouteGroupKind %v/%s", listener.Protocol, routeKind.Group, routeKind.Kind), }) continue @@ -657,7 +657,7 @@ func getAllowedRouteKinds(listener v1alpha2.Listener, supportedKinds []v1alpha2. return routeKinds, conditions } -func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha2.Listener, gateway *v1alpha2.Gateway, client Client, conf *dynamic.Configuration) []metav1.Condition { +func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener gatev1alpha2.Listener, gateway *gatev1alpha2.Gateway, client Client, conf *dynamic.Configuration) []metav1.Condition { if listener.AllowedRoutes == nil { // Should not happen due to validation. return nil @@ -667,7 +667,7 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha if err != nil { // update "ResolvedRefs" status true with "InvalidRoutesRef" reason return []metav1.Condition{{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidRouteNamespacesSelector", // Should never happen as the selector is validated by kubernetes @@ -679,10 +679,10 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha if err != nil { // update "ResolvedRefs" status true with "InvalidRoutesRef" reason return []metav1.Condition{{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonRefNotPermitted), + Reason: string(gatev1alpha2.ListenerReasonRefNotPermitted), Message: fmt.Sprintf("Cannot fetch HTTPRoutes: %v", err), }} } @@ -708,7 +708,7 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha hostRule, err := hostRule(hostnames) if err != nil { conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidRouteHostname", // TODO check the spec if a proper reason is introduced at some point @@ -722,7 +722,7 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha if err != nil { // update "ResolvedRefs" status true with "DroppedRoutes" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "UnsupportedPathOrHeaderType", // TODO check the spec if a proper reason is introduced at some point @@ -735,7 +735,7 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha EntryPoints: []string{ep}, } - if listener.Protocol == v1alpha2.HTTPSProtocolType && listener.TLS != nil { + if listener.Protocol == gatev1alpha2.HTTPSProtocolType && listener.TLS != nil { // TODO support let's encrypt router.TLS = &dynamic.RouterTLSConfig{} } @@ -746,7 +746,7 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha if err != nil { // update "ResolvedRefs" status true with "DroppedRoutes" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidRouterKey", // Should never happen @@ -761,7 +761,7 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha if err != nil { // update "ResolvedRefs" status true with "InvalidFilters" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidFilters", // TODO check the spec if a proper reason is introduced at some point @@ -789,7 +789,7 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha if err != nil { // update "ResolvedRefs" status true with "DroppedRoutes" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidBackendRefs", // TODO check the spec if a proper reason is introduced at some point @@ -818,7 +818,7 @@ func gatewayHTTPRouteToHTTPConf(ctx context.Context, ep string, listener v1alpha return conditions } -func gatewayTCPRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2.Listener, gateway *v1alpha2.Gateway, client Client, conf *dynamic.Configuration) []metav1.Condition { +func gatewayTCPRouteToTCPConf(ctx context.Context, ep string, listener gatev1alpha2.Listener, gateway *gatev1alpha2.Gateway, client Client, conf *dynamic.Configuration) []metav1.Condition { if listener.AllowedRoutes == nil { // Should not happen due to validation. return nil @@ -828,7 +828,7 @@ func gatewayTCPRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "InvalidRoutesRef" reason return []metav1.Condition{{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidRouteNamespacesSelector", // TODO should never happen as the selector is validated by Kubernetes @@ -840,10 +840,10 @@ func gatewayTCPRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "InvalidRoutesRef" reason return []metav1.Condition{{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonRefNotPermitted), + Reason: string(gatev1alpha2.ListenerReasonRefNotPermitted), Message: fmt.Sprintf("Cannot fetch TCPRoutes: %v", err), }} } @@ -864,10 +864,10 @@ func gatewayTCPRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. EntryPoints: []string{ep}, } - if listener.Protocol == v1alpha2.TLSProtocolType && listener.TLS != nil { + if listener.Protocol == gatev1alpha2.TLSProtocolType && listener.TLS != nil { // TODO support let's encrypt router.TLS = &dynamic.RouterTCPTLSConfig{ - Passthrough: listener.TLS.Mode != nil && *listener.TLS.Mode == v1alpha2.TLSModePassthrough, + Passthrough: listener.TLS.Mode != nil && *listener.TLS.Mode == gatev1alpha2.TLSModePassthrough, } } @@ -877,7 +877,7 @@ func gatewayTCPRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "DroppedRoutes" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidRouterKey", // Should never happen @@ -902,7 +902,7 @@ func gatewayTCPRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "DroppedRoutes" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidBackendRefs", // TODO check the spec if a proper reason is introduced at some point @@ -948,7 +948,7 @@ func gatewayTCPRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. return conditions } -func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2.Listener, gateway *v1alpha2.Gateway, client Client, conf *dynamic.Configuration) []metav1.Condition { +func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener gatev1alpha2.Listener, gateway *gatev1alpha2.Gateway, client Client, conf *dynamic.Configuration) []metav1.Condition { if listener.AllowedRoutes == nil { // Should not happen due to validation. return nil @@ -958,7 +958,7 @@ func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "InvalidRoutesRef" reason return []metav1.Condition{{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidRouteNamespacesSelector", // TODO should never happen as the selector is validated by Kubernetes @@ -970,10 +970,10 @@ func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "InvalidRoutesRef" reason return []metav1.Condition{{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), - Reason: string(v1alpha2.ListenerReasonRefNotPermitted), + Reason: string(gatev1alpha2.ListenerReasonRefNotPermitted), Message: fmt.Sprintf("Cannot fetch TLSRoutes: %v", err), }} } @@ -993,9 +993,9 @@ func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if len(hostnames) == 0 && listener.Hostname != nil && *listener.Hostname != "" && len(route.Spec.Hostnames) > 0 { for _, parent := range route.Status.Parents { parent.Conditions = append(parent.Conditions, metav1.Condition{ - Type: string(v1alpha2.GatewayClassConditionStatusAccepted), + Type: string(gatev1alpha2.GatewayClassConditionStatusAccepted), Status: metav1.ConditionFalse, - Reason: string(v1alpha2.ListenerReasonRouteConflict), + Reason: string(gatev1alpha2.ListenerReasonRouteConflict), Message: fmt.Sprintf("No hostname match between listener: %v and route: %v", listener.Hostname, route.Spec.Hostnames), LastTransitionTime: metav1.Now(), }) @@ -1008,7 +1008,7 @@ func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "DroppedRoutes" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidHostnames", // TODO check the spec if a proper reason is introduced at some point @@ -1022,7 +1022,7 @@ func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. Rule: rule, EntryPoints: []string{ep}, TLS: &dynamic.RouterTCPTLSConfig{ - Passthrough: listener.TLS.Mode != nil && *listener.TLS.Mode == v1alpha2.TLSModePassthrough, + Passthrough: listener.TLS.Mode != nil && *listener.TLS.Mode == gatev1alpha2.TLSModePassthrough, }, } @@ -1032,7 +1032,7 @@ func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "DroppedRoutes" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidRouterKey", // Should never happen @@ -1057,7 +1057,7 @@ func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. if err != nil { // update "ResolvedRefs" status true with "DroppedRoutes" reason conditions = append(conditions, metav1.Condition{ - Type: string(v1alpha2.ListenerConditionResolvedRefs), + Type: string(gatev1alpha2.ListenerConditionResolvedRefs), Status: metav1.ConditionFalse, LastTransitionTime: metav1.Now(), Reason: "InvalidBackendRefs", // TODO check the spec if a proper reason is introduced at some point @@ -1105,18 +1105,18 @@ func gatewayTLSRouteToTCPConf(ctx context.Context, ep string, listener v1alpha2. // Because of Kubernetes validation we admit that the given Hostnames are valid. // https://github.com/kubernetes-sigs/gateway-api/blob/ff9883da4cad8554cd300394f725ab3a27502785/apis/v1alpha2/shared_types.go#L252 -func matchingHostnames(listener v1alpha2.Listener, hostnames []v1alpha2.Hostname) []v1alpha2.Hostname { +func matchingHostnames(listener gatev1alpha2.Listener, hostnames []gatev1alpha2.Hostname) []gatev1alpha2.Hostname { if listener.Hostname == nil || *listener.Hostname == "" { return hostnames } if len(hostnames) == 0 { - return []v1alpha2.Hostname{*listener.Hostname} + return []gatev1alpha2.Hostname{*listener.Hostname} } listenerLabels := strings.Split(string(*listener.Hostname), ".") - var matches []v1alpha2.Hostname + var matches []gatev1alpha2.Hostname for _, hostname := range hostnames { if hostname == *listener.Hostname { @@ -1147,9 +1147,9 @@ func matchingHostnames(listener v1alpha2.Listener, hostnames []v1alpha2.Hostname return matches } -func shouldAttach(gateway *v1alpha2.Gateway, listener v1alpha2.Listener, routeNamespace string, routeSpec v1alpha2.CommonRouteSpec) bool { +func shouldAttach(gateway *gatev1alpha2.Gateway, listener gatev1alpha2.Listener, routeNamespace string, routeSpec gatev1alpha2.CommonRouteSpec) bool { for _, parentRef := range routeSpec.ParentRefs { - if parentRef.Group == nil || *parentRef.Group != v1alpha2.GroupName { + if parentRef.Group == nil || *parentRef.Group != gatev1alpha2.GroupName { continue } @@ -1174,19 +1174,19 @@ func shouldAttach(gateway *v1alpha2.Gateway, listener v1alpha2.Listener, routeNa return false } -func getRouteBindingSelectorNamespace(client Client, gatewayNamespace string, routeNamespaces *v1alpha2.RouteNamespaces) ([]string, error) { +func getRouteBindingSelectorNamespace(client Client, gatewayNamespace string, routeNamespaces *gatev1alpha2.RouteNamespaces) ([]string, error) { if routeNamespaces == nil || routeNamespaces.From == nil { return []string{gatewayNamespace}, nil } switch *routeNamespaces.From { - case v1alpha2.NamespacesFromAll: + case gatev1alpha2.NamespacesFromAll: return []string{metav1.NamespaceAll}, nil - case v1alpha2.NamespacesFromSame: + case gatev1alpha2.NamespacesFromSame: return []string{gatewayNamespace}, nil - case v1alpha2.NamespacesFromSelector: + case gatev1alpha2.NamespacesFromSelector: selector, err := metav1.LabelSelectorAsSelector(routeNamespaces.Selector) if err != nil { return nil, fmt.Errorf("malformed selector: %w", err) @@ -1198,7 +1198,7 @@ func getRouteBindingSelectorNamespace(client Client, gatewayNamespace string, ro return nil, fmt.Errorf("unsupported RouteSelectType: %q", *routeNamespaces.From) } -func hostRule(hostnames []v1alpha2.Hostname) (string, error) { +func hostRule(hostnames []gatev1alpha2.Hostname) (string, error) { var rules []string for _, hostname := range hostnames { @@ -1235,9 +1235,9 @@ func hostRule(hostnames []v1alpha2.Hostname) (string, error) { } } -func hostSNIRule(hostnames []v1alpha2.Hostname) (string, error) { +func hostSNIRule(hostnames []gatev1alpha2.Hostname) (string, error) { rules := make([]string, 0, len(hostnames)) - uniqHostnames := map[v1alpha2.Hostname]struct{}{} + uniqHostnames := map[gatev1alpha2.Hostname]struct{}{} for _, hostname := range hostnames { if len(hostname) == 0 { @@ -1272,7 +1272,7 @@ func hostSNIRule(hostnames []v1alpha2.Hostname) (string, error) { return strings.Join(rules, " || "), nil } -func extractRule(routeRule v1alpha2.HTTPRouteRule, hostRule string) (string, error) { +func extractRule(routeRule gatev1alpha2.HTTPRouteRule, hostRule string) (string, error) { var rule string var matchesRules []string @@ -1286,9 +1286,9 @@ func extractRule(routeRule v1alpha2.HTTPRouteRule, hostRule string) (string, err if match.Path != nil && match.Path.Type != nil && match.Path.Value != nil { // TODO handle other path types switch *match.Path.Type { - case v1alpha2.PathMatchExact: + case gatev1alpha2.PathMatchExact: matchRules = append(matchRules, fmt.Sprintf("Path(`%s`)", *match.Path.Value)) - case v1alpha2.PathMatchPathPrefix: + case gatev1alpha2.PathMatchPathPrefix: matchRules = append(matchRules, fmt.Sprintf("PathPrefix(`%s`)", *match.Path.Value)) default: return "", fmt.Errorf("unsupported path match %s", *match.Path.Type) @@ -1329,7 +1329,7 @@ func extractRule(routeRule v1alpha2.HTTPRouteRule, hostRule string) (string, err return rule + "(" + strings.Join(matchesRules, " || ") + ")", nil } -func extractHeaderRules(headers []v1alpha2.HTTPHeaderMatch) ([]string, error) { +func extractHeaderRules(headers []gatev1alpha2.HTTPHeaderMatch) ([]string, error) { var headerRules []string // TODO handle other headers types @@ -1340,7 +1340,7 @@ func extractHeaderRules(headers []v1alpha2.HTTPHeaderMatch) ([]string, error) { } switch *header.Type { - case v1alpha2.HeaderMatchExact: + case gatev1alpha2.HeaderMatchExact: headerRules = append(headerRules, fmt.Sprintf("Headers(`%s`,`%s`)", header.Name, header.Value)) default: return nil, fmt.Errorf("unsupported header match type %s", *header.Type) @@ -1369,7 +1369,7 @@ func makeID(namespace, name string) string { return namespace + "-" + name } -func getTLS(k8sClient Client, secretName v1alpha2.ObjectName, namespace string) (*tls.CertAndStores, error) { +func getTLS(k8sClient Client, secretName gatev1alpha2.ObjectName, namespace string) (*tls.CertAndStores, error) { secret, exists, err := k8sClient.GetSecret(namespace, string(secretName)) if err != nil { return nil, fmt.Errorf("failed to fetch secret %s/%s: %w", namespace, secretName, err) @@ -1443,7 +1443,7 @@ func getCertificateBlocks(secret *corev1.Secret, namespace, secretName string) ( } // loadServices is generating a WRR service, even when there is only one target. -func loadServices(client Client, namespace string, backendRefs []v1alpha2.HTTPBackendRef) (*dynamic.Service, map[string]*dynamic.Service, error) { +func loadServices(client Client, namespace string, backendRefs []gatev1alpha2.HTTPBackendRef) (*dynamic.Service, map[string]*dynamic.Service, error) { services := map[string]*dynamic.Service{} wrrSvc := &dynamic.Service{ @@ -1566,7 +1566,7 @@ func loadServices(client Client, namespace string, backendRefs []v1alpha2.HTTPBa } // loadTCPServices is generating a WRR service, even when there is only one target. -func loadTCPServices(client Client, namespace string, backendRefs []v1alpha2.BackendRef) (*dynamic.TCPService, map[string]*dynamic.TCPService, error) { +func loadTCPServices(client Client, namespace string, backendRefs []gatev1alpha2.BackendRef) (*dynamic.TCPService, map[string]*dynamic.TCPService, error) { services := map[string]*dynamic.TCPService{} wrrSvc := &dynamic.TCPService{ @@ -1684,16 +1684,16 @@ func loadTCPServices(client Client, namespace string, backendRefs []v1alpha2.Bac return wrrSvc, services, nil } -func loadMiddlewares(listener v1alpha2.Listener, prefix string, filters []v1alpha2.HTTPRouteFilter) (map[string]*dynamic.Middleware, error) { +func loadMiddlewares(listener gatev1alpha2.Listener, prefix string, filters []gatev1alpha2.HTTPRouteFilter) (map[string]*dynamic.Middleware, error) { middlewares := make(map[string]*dynamic.Middleware) // The spec allows for an empty string in which case we should use the // scheme of the request which in this case is the listener scheme. var listenerScheme string switch listener.Protocol { - case v1alpha2.HTTPProtocolType: + case gatev1alpha2.HTTPProtocolType: listenerScheme = "http" - case v1alpha2.HTTPSProtocolType: + case gatev1alpha2.HTTPSProtocolType: listenerScheme = "https" default: return nil, fmt.Errorf("invalid listener protocol %s", listener.Protocol) @@ -1702,7 +1702,7 @@ func loadMiddlewares(listener v1alpha2.Listener, prefix string, filters []v1alph for i, filter := range filters { var middleware *dynamic.Middleware switch filter.Type { - case v1alpha2.HTTPRouteFilterRequestRedirect: + case gatev1alpha2.HTTPRouteFilterRequestRedirect: var err error middleware, err = createRedirectRegexMiddleware(listenerScheme, filter.RequestRedirect) if err != nil { @@ -1724,7 +1724,7 @@ func loadMiddlewares(listener v1alpha2.Listener, prefix string, filters []v1alph return middlewares, nil } -func createRedirectRegexMiddleware(scheme string, filter *v1alpha2.HTTPRequestRedirectFilter) (*dynamic.Middleware, error) { +func createRedirectRegexMiddleware(scheme string, filter *gatev1alpha2.HTTPRequestRedirectFilter) (*dynamic.Middleware, error) { // Use the HTTPRequestRedirectFilter scheme if defined. filterScheme := scheme if filter.Scheme != nil { @@ -1802,7 +1802,7 @@ func throttleEvents(ctx context.Context, throttleDuration time.Duration, pool *s return eventsChanBuffered } -func isTraefikService(ref v1alpha2.BackendRef) bool { +func isTraefikService(ref gatev1alpha2.BackendRef) bool { if ref.Kind == nil || ref.Group == nil { return false } @@ -1810,13 +1810,13 @@ func isTraefikService(ref v1alpha2.BackendRef) bool { return *ref.Group == traefikv1alpha1.GroupName && *ref.Kind == kindTraefikService } -func isInternalService(ref v1alpha2.BackendRef) bool { +func isInternalService(ref gatev1alpha2.BackendRef) bool { return isTraefikService(ref) && strings.HasSuffix(string(ref.Name), "@internal") } // makeListenerKey joins protocol, hostname, and port of a listener into a string key. -func makeListenerKey(l v1alpha2.Listener) string { - var hostname v1alpha2.Hostname +func makeListenerKey(l gatev1alpha2.Listener) string { + var hostname gatev1alpha2.Hostname if l.Hostname != nil { hostname = *l.Hostname } diff --git a/pkg/provider/kubernetes/gateway/kubernetes_test.go b/pkg/provider/kubernetes/gateway/kubernetes_test.go index f7e2acafe..e3783796e 100644 --- a/pkg/provider/kubernetes/gateway/kubernetes_test.go +++ b/pkg/provider/kubernetes/gateway/kubernetes_test.go @@ -13,7 +13,7 @@ import ( "github.com/traefik/traefik/v3/pkg/tls" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/pointer" - "sigs.k8s.io/gateway-api/apis/v1alpha2" + gatev1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" ) var _ provider.Provider = (*Provider)(nil) @@ -4555,7 +4555,7 @@ func TestLoadMixedRoutes(t *testing.T) { func Test_hostRule(t *testing.T) { testCases := []struct { desc string - hostnames []v1alpha2.Hostname + hostnames []gatev1alpha2.Hostname expectedRule string expectErr bool }{ @@ -4565,14 +4565,14 @@ func Test_hostRule(t *testing.T) { }, { desc: "One Host", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "Foo", }, expectedRule: "Host(`Foo`)", }, { desc: "Multiple Hosts", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "Foo", "Bar", "Bir", @@ -4581,7 +4581,7 @@ func Test_hostRule(t *testing.T) { }, { desc: "Multiple Hosts with empty one", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "Foo", "", "Bir", @@ -4590,7 +4590,7 @@ func Test_hostRule(t *testing.T) { }, { desc: "Multiple empty hosts", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "", "", "", @@ -4599,7 +4599,7 @@ func Test_hostRule(t *testing.T) { }, { desc: "Several Host and wildcard", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "*.bar.foo", "bar.foo", "foo.foo", @@ -4608,21 +4608,21 @@ func Test_hostRule(t *testing.T) { }, { desc: "Host with wildcard", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "*.bar.foo", }, expectedRule: "HostRegexp(`^[a-zA-Z0-9-]+\\.bar\\.foo$`)", }, { desc: "Alone wildcard", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "*", "*.foo.foo", }, }, { desc: "Multiple alone Wildcard", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "foo.foo", "*.*", }, @@ -4630,7 +4630,7 @@ func Test_hostRule(t *testing.T) { }, { desc: "Multiple Wildcard", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "foo.foo", "*.toto.*.bar.foo", }, @@ -4638,7 +4638,7 @@ func Test_hostRule(t *testing.T) { }, { desc: "Multiple subdomain with misplaced wildcard", - hostnames: []v1alpha2.Hostname{ + hostnames: []gatev1alpha2.Hostname{ "foo.foo", "toto.*.bar.foo", }, @@ -4663,7 +4663,7 @@ func Test_hostRule(t *testing.T) { func Test_extractRule(t *testing.T) { testCases := []struct { desc string - routeRule v1alpha2.HTTPRouteRule + routeRule gatev1alpha2.HTTPRouteRule hostRule string expectedRule string expectedError bool @@ -4679,8 +4679,8 @@ func Test_extractRule(t *testing.T) { }, { desc: "One HTTPRouteMatch with nil HTTPHeaderMatch", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ {Headers: nil}, }, }, @@ -4688,10 +4688,10 @@ func Test_extractRule(t *testing.T) { }, { desc: "One HTTPRouteMatch with nil HTTPHeaderMatch Type", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Headers: []v1alpha2.HTTPHeaderMatch{ + Headers: []gatev1alpha2.HTTPHeaderMatch{ {Type: nil, Name: "foo", Value: "bar"}, }, }, @@ -4701,8 +4701,8 @@ func Test_extractRule(t *testing.T) { }, { desc: "One HTTPRouteMatch with nil HTTPPathMatch", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ {Path: nil}, }, }, @@ -4710,10 +4710,10 @@ func Test_extractRule(t *testing.T) { }, { desc: "One HTTPRouteMatch with nil HTTPPathMatch Type", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ + Path: &gatev1alpha2.HTTPPathMatch{ Type: nil, Value: pointer.String("/foo/"), }, @@ -4724,11 +4724,11 @@ func Test_extractRule(t *testing.T) { }, { desc: "One HTTPRouteMatch with nil HTTPPathMatch Values", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(v1alpha2.PathMatchExact), + Path: &gatev1alpha2.HTTPPathMatch{ + Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), Value: nil, }, }, @@ -4738,11 +4738,11 @@ func Test_extractRule(t *testing.T) { }, { desc: "One Path in matches", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(v1alpha2.PathMatchExact), + Path: &gatev1alpha2.HTTPPathMatch{ + Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, @@ -4752,16 +4752,16 @@ func Test_extractRule(t *testing.T) { }, { desc: "One Path in matches and another unknown", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(v1alpha2.PathMatchExact), + Path: &gatev1alpha2.HTTPPathMatch{ + Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, { - Path: &v1alpha2.HTTPPathMatch{ + Path: &gatev1alpha2.HTTPPathMatch{ Type: pathMatchTypePtr("unknown"), Value: pointer.String("/foo/"), }, @@ -4772,11 +4772,11 @@ func Test_extractRule(t *testing.T) { }, { desc: "One Path in matches and another empty", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(v1alpha2.PathMatchExact), + Path: &gatev1alpha2.HTTPPathMatch{ + Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, @@ -4787,18 +4787,18 @@ func Test_extractRule(t *testing.T) { }, { desc: "Path OR Header rules", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(v1alpha2.PathMatchExact), + Path: &gatev1alpha2.HTTPPathMatch{ + Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, { - Headers: []v1alpha2.HTTPHeaderMatch{ + Headers: []gatev1alpha2.HTTPHeaderMatch{ { - Type: headerMatchTypePtr(v1alpha2.HeaderMatchExact), + Type: headerMatchTypePtr(gatev1alpha2.HeaderMatchExact), Name: "my-header", Value: "foo", }, @@ -4810,16 +4810,16 @@ func Test_extractRule(t *testing.T) { }, { desc: "Path && Header rules", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(v1alpha2.PathMatchExact), + Path: &gatev1alpha2.HTTPPathMatch{ + Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, - Headers: []v1alpha2.HTTPHeaderMatch{ + Headers: []gatev1alpha2.HTTPHeaderMatch{ { - Type: headerMatchTypePtr(v1alpha2.HeaderMatchExact), + Type: headerMatchTypePtr(gatev1alpha2.HeaderMatchExact), Name: "my-header", Value: "foo", }, @@ -4832,16 +4832,16 @@ func Test_extractRule(t *testing.T) { { desc: "Host && Path && Header rules", hostRule: "Host(`foo.com`)", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(v1alpha2.PathMatchExact), + Path: &gatev1alpha2.HTTPPathMatch{ + Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, - Headers: []v1alpha2.HTTPHeaderMatch{ + Headers: []gatev1alpha2.HTTPHeaderMatch{ { - Type: headerMatchTypePtr(v1alpha2.HeaderMatchExact), + Type: headerMatchTypePtr(gatev1alpha2.HeaderMatchExact), Name: "my-header", Value: "foo", }, @@ -4854,18 +4854,18 @@ func Test_extractRule(t *testing.T) { { desc: "Host && (Path || Header) rules", hostRule: "Host(`foo.com`)", - routeRule: v1alpha2.HTTPRouteRule{ - Matches: []v1alpha2.HTTPRouteMatch{ + routeRule: gatev1alpha2.HTTPRouteRule{ + Matches: []gatev1alpha2.HTTPRouteMatch{ { - Path: &v1alpha2.HTTPPathMatch{ - Type: pathMatchTypePtr(v1alpha2.PathMatchExact), + Path: &gatev1alpha2.HTTPPathMatch{ + Type: pathMatchTypePtr(gatev1alpha2.PathMatchExact), Value: pointer.String("/foo/"), }, }, { - Headers: []v1alpha2.HTTPHeaderMatch{ + Headers: []gatev1alpha2.HTTPHeaderMatch{ { - Type: headerMatchTypePtr(v1alpha2.HeaderMatchExact), + Type: headerMatchTypePtr(gatev1alpha2.HeaderMatchExact), Name: "my-header", Value: "foo", }, @@ -4897,7 +4897,7 @@ func Test_extractRule(t *testing.T) { func Test_hostSNIRule(t *testing.T) { testCases := []struct { desc string - hostnames []v1alpha2.Hostname + hostnames []gatev1alpha2.Hostname expectedRule string expectError bool }{ @@ -4907,47 +4907,47 @@ func Test_hostSNIRule(t *testing.T) { }, { desc: "Empty hostname", - hostnames: []v1alpha2.Hostname{""}, + hostnames: []gatev1alpha2.Hostname{""}, expectedRule: "HostSNI(`*`)", }, { desc: "Unsupported wildcard", - hostnames: []v1alpha2.Hostname{"*"}, + hostnames: []gatev1alpha2.Hostname{"*"}, expectError: true, }, { desc: "Supported wildcard", - hostnames: []v1alpha2.Hostname{"*.foo"}, + hostnames: []gatev1alpha2.Hostname{"*.foo"}, expectedRule: "HostSNIRegexp(`^[a-zA-Z0-9-]+\\.foo$`)", }, { desc: "Multiple malformed wildcard", - hostnames: []v1alpha2.Hostname{"*.foo.*"}, + hostnames: []gatev1alpha2.Hostname{"*.foo.*"}, expectError: true, }, { desc: "Some empty hostnames", - hostnames: []v1alpha2.Hostname{"foo", "", "bar"}, + hostnames: []gatev1alpha2.Hostname{"foo", "", "bar"}, expectedRule: "HostSNI(`foo`) || HostSNI(`bar`)", }, { desc: "Valid hostname", - hostnames: []v1alpha2.Hostname{"foo"}, + hostnames: []gatev1alpha2.Hostname{"foo"}, expectedRule: "HostSNI(`foo`)", }, { desc: "Multiple valid hostnames", - hostnames: []v1alpha2.Hostname{"foo", "bar"}, + hostnames: []gatev1alpha2.Hostname{"foo", "bar"}, expectedRule: "HostSNI(`foo`) || HostSNI(`bar`)", }, { desc: "Multiple valid hostnames with wildcard", - hostnames: []v1alpha2.Hostname{"bar.foo", "foo.foo", "*.foo"}, + hostnames: []gatev1alpha2.Hostname{"bar.foo", "foo.foo", "*.foo"}, expectedRule: "HostSNI(`bar.foo`) || HostSNI(`foo.foo`) || HostSNIRegexp(`^[a-zA-Z0-9-]+\\.foo$`)", }, { desc: "Multiple overlapping hostnames", - hostnames: []v1alpha2.Hostname{"foo", "bar", "foo", "baz"}, + hostnames: []gatev1alpha2.Hostname{"foo", "bar", "foo", "baz"}, expectedRule: "HostSNI(`foo`) || HostSNI(`bar`) || HostSNI(`baz`)", }, } @@ -4972,49 +4972,49 @@ func Test_hostSNIRule(t *testing.T) { func Test_shouldAttach(t *testing.T) { testCases := []struct { desc string - gateway *v1alpha2.Gateway - listener v1alpha2.Listener + gateway *gatev1alpha2.Gateway + listener gatev1alpha2.Listener routeNamespace string - routeSpec v1alpha2.CommonRouteSpec + routeSpec gatev1alpha2.CommonRouteSpec expectedAttach bool }{ { desc: "No ParentRefs", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ + routeSpec: gatev1alpha2.CommonRouteSpec{ ParentRefs: nil, }, expectedAttach: false, }, { desc: "Unsupported Kind", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("bar"), Name: "gateway", Namespace: namespacePtr("default"), Kind: kindPtr("Foo"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), }, }, }, @@ -5022,18 +5022,18 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Unsupported Group", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("bar"), Name: "gateway", @@ -5047,23 +5047,23 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Kind is nil", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("bar"), Name: "gateway", Namespace: namespacePtr("default"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), }, }, }, @@ -5071,18 +5071,18 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Group is nil", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("bar"), Name: "gateway", @@ -5095,23 +5095,23 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "SectionName does not match a listener desc", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("bar"), Name: "gateway", Namespace: namespacePtr("default"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), Kind: kindPtr("Gateway"), }, }, @@ -5120,23 +5120,23 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Namespace does not match the Gateway namespace", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("bar"), Name: "gateway", Namespace: namespacePtr("bar"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), Kind: kindPtr("Gateway"), }, }, @@ -5145,22 +5145,22 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Route namespace does not match the Gateway namespace", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "bar", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("bar"), Name: "gateway", - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), Kind: kindPtr("Gateway"), }, }, @@ -5169,24 +5169,24 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Unsupported Kind", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("bar"), Name: "gateway", Namespace: namespacePtr("default"), Kind: kindPtr("Gateway"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), }, }, }, @@ -5194,23 +5194,23 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Route namespace matches the Gateway namespace", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "default", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("foo"), Name: "gateway", Kind: kindPtr("Gateway"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), }, }, }, @@ -5218,24 +5218,24 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Namespace matches the Gateway namespace", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "bar", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { SectionName: sectionNamePtr("foo"), Name: "gateway", Namespace: namespacePtr("default"), Kind: kindPtr("Gateway"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), }, }, }, @@ -5243,29 +5243,29 @@ func Test_shouldAttach(t *testing.T) { }, { desc: "Only one ParentRef matches the Gateway", - gateway: &v1alpha2.Gateway{ + gateway: &gatev1alpha2.Gateway{ ObjectMeta: metav1.ObjectMeta{ Name: "gateway", Namespace: "default", }, }, - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Name: "foo", }, routeNamespace: "bar", - routeSpec: v1alpha2.CommonRouteSpec{ - ParentRefs: []v1alpha2.ParentRef{ + routeSpec: gatev1alpha2.CommonRouteSpec{ + ParentRefs: []gatev1alpha2.ParentRef{ { Name: "gateway2", Namespace: namespacePtr("default"), Kind: kindPtr("Gateway"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), }, { Name: "gateway", Namespace: namespacePtr("default"), Kind: kindPtr("Gateway"), - Group: groupPtr(v1alpha2.GroupName), + Group: groupPtr(gatev1alpha2.GroupName), }, }, }, @@ -5287,93 +5287,93 @@ func Test_shouldAttach(t *testing.T) { func Test_matchingHostnames(t *testing.T) { testCases := []struct { desc string - listener v1alpha2.Listener - hostnames []v1alpha2.Hostname - want []v1alpha2.Hostname + listener gatev1alpha2.Listener + hostnames []gatev1alpha2.Hostname + want []gatev1alpha2.Hostname }{ { desc: "Empty", }, { desc: "Only listener hostname", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("foo.com"), }, - want: []v1alpha2.Hostname{"foo.com"}, + want: []gatev1alpha2.Hostname{"foo.com"}, }, { desc: "Only Route hostname", - hostnames: []v1alpha2.Hostname{"foo.com"}, - want: []v1alpha2.Hostname{"foo.com"}, + hostnames: []gatev1alpha2.Hostname{"foo.com"}, + want: []gatev1alpha2.Hostname{"foo.com"}, }, { desc: "Matching hostname", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("foo.com"), }, - hostnames: []v1alpha2.Hostname{"foo.com"}, - want: []v1alpha2.Hostname{"foo.com"}, + hostnames: []gatev1alpha2.Hostname{"foo.com"}, + want: []gatev1alpha2.Hostname{"foo.com"}, }, { desc: "Matching hostname with wildcard", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("*.foo.com"), }, - hostnames: []v1alpha2.Hostname{"*.foo.com"}, - want: []v1alpha2.Hostname{"*.foo.com"}, + hostnames: []gatev1alpha2.Hostname{"*.foo.com"}, + want: []gatev1alpha2.Hostname{"*.foo.com"}, }, { desc: "Matching subdomain with listener wildcard", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("*.foo.com"), }, - hostnames: []v1alpha2.Hostname{"bar.foo.com"}, - want: []v1alpha2.Hostname{"bar.foo.com"}, + hostnames: []gatev1alpha2.Hostname{"bar.foo.com"}, + want: []gatev1alpha2.Hostname{"bar.foo.com"}, }, { desc: "Matching subdomain with route hostname wildcard", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("bar.foo.com"), }, - hostnames: []v1alpha2.Hostname{"*.foo.com"}, - want: []v1alpha2.Hostname{"bar.foo.com"}, + hostnames: []gatev1alpha2.Hostname{"*.foo.com"}, + want: []gatev1alpha2.Hostname{"bar.foo.com"}, }, { desc: "Non matching root domain with listener wildcard", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("*.foo.com"), }, - hostnames: []v1alpha2.Hostname{"foo.com"}, + hostnames: []gatev1alpha2.Hostname{"foo.com"}, }, { desc: "Non matching root domain with route hostname wildcard", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("foo.com"), }, - hostnames: []v1alpha2.Hostname{"*.foo.com"}, + hostnames: []gatev1alpha2.Hostname{"*.foo.com"}, }, { desc: "Multiple route hostnames with one matching route hostname", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("*.foo.com"), }, - hostnames: []v1alpha2.Hostname{"bar.com", "test.foo.com", "test.buz.com"}, - want: []v1alpha2.Hostname{"test.foo.com"}, + hostnames: []gatev1alpha2.Hostname{"bar.com", "test.foo.com", "test.buz.com"}, + want: []gatev1alpha2.Hostname{"test.foo.com"}, }, { desc: "Multiple route hostnames with non matching route hostname", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("*.fuz.com"), }, - hostnames: []v1alpha2.Hostname{"bar.com", "test.foo.com", "test.buz.com"}, + hostnames: []gatev1alpha2.Hostname{"bar.com", "test.foo.com", "test.buz.com"}, }, { desc: "Multiple route hostnames with multiple matching route hostnames", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Hostname: hostnamePtr("*.foo.com"), }, - hostnames: []v1alpha2.Hostname{"toto.foo.com", "test.foo.com", "test.buz.com"}, - want: []v1alpha2.Hostname{"toto.foo.com", "test.foo.com"}, + hostnames: []gatev1alpha2.Hostname{"toto.foo.com", "test.foo.com", "test.buz.com"}, + want: []gatev1alpha2.Hostname{"toto.foo.com", "test.foo.com"}, }, } @@ -5391,9 +5391,9 @@ func Test_matchingHostnames(t *testing.T) { func Test_getAllowedRoutes(t *testing.T) { testCases := []struct { desc string - listener v1alpha2.Listener - supportedRouteKinds []v1alpha2.RouteGroupKind - wantKinds []v1alpha2.RouteGroupKind + listener gatev1alpha2.Listener + supportedRouteKinds []gatev1alpha2.RouteGroupKind + wantKinds []gatev1alpha2.RouteGroupKind wantErr bool }{ { @@ -5401,90 +5401,90 @@ func Test_getAllowedRoutes(t *testing.T) { }, { desc: "Empty AllowedRoutes", - supportedRouteKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, + supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, - wantKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, + wantKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, }, { desc: "AllowedRoutes with unsupported Group", - listener: v1alpha2.Listener{ - AllowedRoutes: &v1alpha2.AllowedRoutes{ - Kinds: []v1alpha2.RouteGroupKind{{ + listener: gatev1alpha2.Listener{ + AllowedRoutes: &gatev1alpha2.AllowedRoutes{ + Kinds: []gatev1alpha2.RouteGroupKind{{ Kind: kindTLSRoute, Group: groupPtr("foo"), }}, }, }, - supportedRouteKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, + supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, wantErr: true, }, { desc: "AllowedRoutes with nil Group", - listener: v1alpha2.Listener{ - AllowedRoutes: &v1alpha2.AllowedRoutes{ - Kinds: []v1alpha2.RouteGroupKind{{ + listener: gatev1alpha2.Listener{ + AllowedRoutes: &gatev1alpha2.AllowedRoutes{ + Kinds: []gatev1alpha2.RouteGroupKind{{ Kind: kindTLSRoute, Group: nil, }}, }, }, - supportedRouteKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, + supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, wantErr: true, }, { desc: "AllowedRoutes with unsupported Kind", - listener: v1alpha2.Listener{ - AllowedRoutes: &v1alpha2.AllowedRoutes{ - Kinds: []v1alpha2.RouteGroupKind{{ - Kind: "foo", Group: groupPtr(v1alpha2.GroupName), + listener: gatev1alpha2.Listener{ + AllowedRoutes: &gatev1alpha2.AllowedRoutes{ + Kinds: []gatev1alpha2.RouteGroupKind{{ + Kind: "foo", Group: groupPtr(gatev1alpha2.GroupName), }}, }, }, - supportedRouteKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, + supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, wantErr: true, }, { desc: "Supported AllowedRoutes", - listener: v1alpha2.Listener{ - AllowedRoutes: &v1alpha2.AllowedRoutes{ - Kinds: []v1alpha2.RouteGroupKind{{ - Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName), + listener: gatev1alpha2.Listener{ + AllowedRoutes: &gatev1alpha2.AllowedRoutes{ + Kinds: []gatev1alpha2.RouteGroupKind{{ + Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName), }}, }, }, - supportedRouteKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, + supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, - wantKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, + wantKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, }, { desc: "Supported AllowedRoutes with duplicates", - listener: v1alpha2.Listener{ - AllowedRoutes: &v1alpha2.AllowedRoutes{ - Kinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, - {Kind: kindTCPRoute, Group: groupPtr(v1alpha2.GroupName)}, - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, - {Kind: kindTCPRoute, Group: groupPtr(v1alpha2.GroupName)}, + listener: gatev1alpha2.Listener{ + AllowedRoutes: &gatev1alpha2.AllowedRoutes{ + Kinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTCPRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTCPRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, }, }, - supportedRouteKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, - {Kind: kindTCPRoute, Group: groupPtr(v1alpha2.GroupName)}, + supportedRouteKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTCPRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, - wantKinds: []v1alpha2.RouteGroupKind{ - {Kind: kindTLSRoute, Group: groupPtr(v1alpha2.GroupName)}, - {Kind: kindTCPRoute, Group: groupPtr(v1alpha2.GroupName)}, + wantKinds: []gatev1alpha2.RouteGroupKind{ + {Kind: kindTLSRoute, Group: groupPtr(gatev1alpha2.GroupName)}, + {Kind: kindTCPRoute, Group: groupPtr(gatev1alpha2.GroupName)}, }, }, } @@ -5509,7 +5509,7 @@ func Test_getAllowedRoutes(t *testing.T) { func Test_makeListenerKey(t *testing.T) { testCases := []struct { desc string - listener v1alpha2.Listener + listener gatev1alpha2.Listener expectedKey string }{ { @@ -5518,18 +5518,18 @@ func Test_makeListenerKey(t *testing.T) { }, { desc: "listener with port, protocol and hostname", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Port: 443, - Protocol: v1alpha2.HTTPSProtocolType, + Protocol: gatev1alpha2.HTTPSProtocolType, Hostname: hostnamePtr("www.example.com"), }, expectedKey: "HTTPS|www.example.com|443", }, { desc: "listener with port, protocol and nil hostname", - listener: v1alpha2.Listener{ + listener: gatev1alpha2.Listener{ Port: 443, - Protocol: v1alpha2.HTTPSProtocolType, + Protocol: gatev1alpha2.HTTPSProtocolType, }, expectedKey: "HTTPS||443", }, @@ -5545,26 +5545,26 @@ func Test_makeListenerKey(t *testing.T) { } } -func hostnamePtr(hostname v1alpha2.Hostname) *v1alpha2.Hostname { +func hostnamePtr(hostname gatev1alpha2.Hostname) *gatev1alpha2.Hostname { return &hostname } -func groupPtr(group v1alpha2.Group) *v1alpha2.Group { +func groupPtr(group gatev1alpha2.Group) *gatev1alpha2.Group { return &group } -func sectionNamePtr(sectionName v1alpha2.SectionName) *v1alpha2.SectionName { +func sectionNamePtr(sectionName gatev1alpha2.SectionName) *gatev1alpha2.SectionName { return §ionName } -func namespacePtr(namespace v1alpha2.Namespace) *v1alpha2.Namespace { +func namespacePtr(namespace gatev1alpha2.Namespace) *gatev1alpha2.Namespace { return &namespace } -func kindPtr(kind v1alpha2.Kind) *v1alpha2.Kind { +func kindPtr(kind gatev1alpha2.Kind) *gatev1alpha2.Kind { return &kind } -func pathMatchTypePtr(p v1alpha2.PathMatchType) *v1alpha2.PathMatchType { return &p } +func pathMatchTypePtr(p gatev1alpha2.PathMatchType) *gatev1alpha2.PathMatchType { return &p } -func headerMatchTypePtr(h v1alpha2.HeaderMatchType) *v1alpha2.HeaderMatchType { return &h } +func headerMatchTypePtr(h gatev1alpha2.HeaderMatchType) *gatev1alpha2.HeaderMatchType { return &h } diff --git a/pkg/provider/kubernetes/ingress/builder_ingress_test.go b/pkg/provider/kubernetes/ingress/builder_ingress_test.go index 56ba2d286..bd9bfb9a3 100644 --- a/pkg/provider/kubernetes/ingress/builder_ingress_test.go +++ b/pkg/provider/kubernetes/ingress/builder_ingress_test.go @@ -1,9 +1,9 @@ package ingress -import networkingv1 "k8s.io/api/networking/v1" +import netv1 "k8s.io/api/networking/v1" -func buildIngress(opts ...func(*networkingv1.Ingress)) *networkingv1.Ingress { - i := &networkingv1.Ingress{} +func buildIngress(opts ...func(*netv1.Ingress)) *netv1.Ingress { + i := &netv1.Ingress{} i.Kind = "Ingress" for _, opt := range opts { opt(i) @@ -11,15 +11,15 @@ func buildIngress(opts ...func(*networkingv1.Ingress)) *networkingv1.Ingress { return i } -func iNamespace(value string) func(*networkingv1.Ingress) { - return func(i *networkingv1.Ingress) { +func iNamespace(value string) func(*netv1.Ingress) { + return func(i *netv1.Ingress) { i.Namespace = value } } -func iRules(opts ...func(*networkingv1.IngressSpec)) func(*networkingv1.Ingress) { - return func(i *networkingv1.Ingress) { - s := &networkingv1.IngressSpec{} +func iRules(opts ...func(*netv1.IngressSpec)) func(*netv1.Ingress) { + return func(i *netv1.Ingress) { + s := &netv1.IngressSpec{} for _, opt := range opts { opt(s) } @@ -27,9 +27,9 @@ func iRules(opts ...func(*networkingv1.IngressSpec)) func(*networkingv1.Ingress) } } -func iRule(opts ...func(*networkingv1.IngressRule)) func(*networkingv1.IngressSpec) { - return func(spec *networkingv1.IngressSpec) { - r := &networkingv1.IngressRule{} +func iRule(opts ...func(*netv1.IngressRule)) func(*netv1.IngressSpec) { + return func(spec *netv1.IngressSpec) { + r := &netv1.IngressRule{} for _, opt := range opts { opt(r) } @@ -37,24 +37,24 @@ func iRule(opts ...func(*networkingv1.IngressRule)) func(*networkingv1.IngressSp } } -func iHost(name string) func(*networkingv1.IngressRule) { - return func(rule *networkingv1.IngressRule) { +func iHost(name string) func(*netv1.IngressRule) { + return func(rule *netv1.IngressRule) { rule.Host = name } } -func iTLSes(opts ...func(*networkingv1.IngressTLS)) func(*networkingv1.Ingress) { - return func(i *networkingv1.Ingress) { +func iTLSes(opts ...func(*netv1.IngressTLS)) func(*netv1.Ingress) { + return func(i *netv1.Ingress) { for _, opt := range opts { - iTLS := networkingv1.IngressTLS{} + iTLS := netv1.IngressTLS{} opt(&iTLS) i.Spec.TLS = append(i.Spec.TLS, iTLS) } } } -func iTLS(secret string, hosts ...string) func(*networkingv1.IngressTLS) { - return func(i *networkingv1.IngressTLS) { +func iTLS(secret string, hosts ...string) func(*netv1.IngressTLS) { + return func(i *netv1.IngressTLS) { i.SecretName = secret i.Hosts = hosts } diff --git a/pkg/provider/kubernetes/ingress/client.go b/pkg/provider/kubernetes/ingress/client.go index 11854c12b..40daf937c 100644 --- a/pkg/provider/kubernetes/ingress/client.go +++ b/pkg/provider/kubernetes/ingress/client.go @@ -14,14 +14,14 @@ import ( "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" traefikversion "github.com/traefik/traefik/v3/pkg/version" corev1 "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" - networkingv1beta1 "k8s.io/api/networking/v1beta1" - kubeerror "k8s.io/apimachinery/pkg/api/errors" + netv1 "k8s.io/api/networking/v1" + netv1beta1 "k8s.io/api/networking/v1beta1" + kerror "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/client-go/informers" - "k8s.io/client-go/kubernetes" + kinformers "k8s.io/client-go/informers" + kclientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" ) @@ -40,21 +40,21 @@ type marshaler interface { // The stores can then be accessed via the Get* functions. type Client interface { WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) - GetIngresses() []*networkingv1.Ingress - GetIngressClasses() ([]*networkingv1.IngressClass, error) + GetIngresses() []*netv1.Ingress + GetIngressClasses() ([]*netv1.IngressClass, error) GetService(namespace, name string) (*corev1.Service, bool, error) GetSecret(namespace, name string) (*corev1.Secret, bool, error) GetEndpoints(namespace, name string) (*corev1.Endpoints, bool, error) - UpdateIngressStatus(ing *networkingv1.Ingress, ingStatus []corev1.LoadBalancerIngress) error + UpdateIngressStatus(ing *netv1.Ingress, ingStatus []corev1.LoadBalancerIngress) error GetServerVersion() *version.Version } type clientWrapper struct { - clientset kubernetes.Interface - factoriesKube map[string]informers.SharedInformerFactory - factoriesSecret map[string]informers.SharedInformerFactory - factoriesIngress map[string]informers.SharedInformerFactory - clusterFactory informers.SharedInformerFactory + clientset kclientset.Interface + factoriesKube map[string]kinformers.SharedInformerFactory + factoriesSecret map[string]kinformers.SharedInformerFactory + factoriesIngress map[string]kinformers.SharedInformerFactory + clusterFactory kinformers.SharedInformerFactory ingressLabelSelector string isNamespaceAll bool disableIngressClassInformer bool @@ -118,7 +118,7 @@ func createClientFromConfig(c *rest.Config) (*clientWrapper, error) { runtime.GOARCH, ) - clientset, err := kubernetes.NewForConfig(c) + clientset, err := kclientset.NewForConfig(c) if err != nil { return nil, err } @@ -126,12 +126,12 @@ func createClientFromConfig(c *rest.Config) (*clientWrapper, error) { return newClientImpl(clientset), nil } -func newClientImpl(clientset kubernetes.Interface) *clientWrapper { +func newClientImpl(clientset kclientset.Interface) *clientWrapper { return &clientWrapper{ clientset: clientset, - factoriesSecret: make(map[string]informers.SharedInformerFactory), - factoriesIngress: make(map[string]informers.SharedInformerFactory), - factoriesKube: make(map[string]informers.SharedInformerFactory), + factoriesSecret: make(map[string]kinformers.SharedInformerFactory), + factoriesIngress: make(map[string]kinformers.SharedInformerFactory), + factoriesKube: make(map[string]kinformers.SharedInformerFactory), } } @@ -169,7 +169,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< } for _, ns := range namespaces { - factoryIngress := informers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod, informers.WithNamespace(ns), informers.WithTweakListOptions(matchesLabelSelector)) + factoryIngress := kinformers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod, kinformers.WithNamespace(ns), kinformers.WithTweakListOptions(matchesLabelSelector)) if supportsNetworkingV1Ingress(serverVersion) { factoryIngress.Networking().V1().Ingresses().Informer().AddEventHandler(eventHandler) @@ -179,12 +179,12 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< c.factoriesIngress[ns] = factoryIngress - factoryKube := informers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod, informers.WithNamespace(ns)) + factoryKube := kinformers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod, kinformers.WithNamespace(ns)) factoryKube.Core().V1().Services().Informer().AddEventHandler(eventHandler) factoryKube.Core().V1().Endpoints().Informer().AddEventHandler(eventHandler) c.factoriesKube[ns] = factoryKube - factorySecret := informers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod, informers.WithNamespace(ns), informers.WithTweakListOptions(notOwnedByHelm)) + factorySecret := kinformers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod, kinformers.WithNamespace(ns), kinformers.WithTweakListOptions(notOwnedByHelm)) factorySecret.Core().V1().Secrets().Informer().AddEventHandler(eventHandler) c.factoriesSecret[ns] = factorySecret } @@ -216,7 +216,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< } if !c.disableIngressClassInformer && supportsIngressClass(serverVersion) { - c.clusterFactory = informers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod) + c.clusterFactory = kinformers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod) if supportsNetworkingV1Ingress(serverVersion) { c.clusterFactory.Networking().V1().IngressClasses().Informer().AddEventHandler(eventHandler) @@ -237,8 +237,8 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (< } // GetIngresses returns all Ingresses for observed namespaces in the cluster. -func (c *clientWrapper) GetIngresses() []*networkingv1.Ingress { - var results []*networkingv1.Ingress +func (c *clientWrapper) GetIngresses() []*netv1.Ingress { + var results []*netv1.Ingress isNetworkingV1Supported := supportsNetworkingV1Ingress(c.serverVersion) @@ -277,13 +277,13 @@ func (c *clientWrapper) GetIngresses() []*networkingv1.Ingress { return results } -func toNetworkingV1(ing marshaler) (*networkingv1.Ingress, error) { +func toNetworkingV1(ing marshaler) (*netv1.Ingress, error) { data, err := ing.Marshal() if err != nil { return nil, err } - ni := &networkingv1.Ingress{} + ni := &netv1.Ingress{} err = ni.Unmarshal(data) if err != nil { return nil, err @@ -292,13 +292,13 @@ func toNetworkingV1(ing marshaler) (*networkingv1.Ingress, error) { return ni, nil } -func toNetworkingV1IngressClass(ing marshaler) (*networkingv1.IngressClass, error) { +func toNetworkingV1IngressClass(ing marshaler) (*netv1.IngressClass, error) { data, err := ing.Marshal() if err != nil { return nil, err } - ni := &networkingv1.IngressClass{} + ni := &netv1.IngressClass{} err = ni.Unmarshal(data) if err != nil { return nil, err @@ -307,9 +307,9 @@ func toNetworkingV1IngressClass(ing marshaler) (*networkingv1.IngressClass, erro return ni, nil } -func addServiceFromV1Beta1(ing *networkingv1.Ingress, old networkingv1beta1.Ingress) { +func addServiceFromV1Beta1(ing *netv1.Ingress, old netv1beta1.Ingress) { if old.Spec.Backend != nil { - port := networkingv1.ServiceBackendPort{} + port := netv1.ServiceBackendPort{} if old.Spec.Backend.ServicePort.Type == intstr.Int { port.Number = old.Spec.Backend.ServicePort.IntVal } else { @@ -317,8 +317,8 @@ func addServiceFromV1Beta1(ing *networkingv1.Ingress, old networkingv1beta1.Ingr } if old.Spec.Backend.ServiceName != "" { - ing.Spec.DefaultBackend = &networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ + ing.Spec.DefaultBackend = &netv1.IngressBackend{ + Service: &netv1.IngressServiceBackend{ Name: old.Spec.Backend.ServiceName, Port: port, }, @@ -334,14 +334,14 @@ func addServiceFromV1Beta1(ing *networkingv1.Ingress, old networkingv1beta1.Ingr if path.Backend.Service == nil { oldBackend := old.Spec.Rules[rc].HTTP.Paths[pc].Backend - port := networkingv1.ServiceBackendPort{} + port := netv1.ServiceBackendPort{} if oldBackend.ServicePort.Type == intstr.Int { port.Number = oldBackend.ServicePort.IntVal } else { port.Name = oldBackend.ServicePort.StrVal } - svc := networkingv1.IngressServiceBackend{ + svc := netv1.IngressServiceBackend{ Name: oldBackend.ServiceName, Port: port, } @@ -353,7 +353,7 @@ func addServiceFromV1Beta1(ing *networkingv1.Ingress, old networkingv1beta1.Ingr } // UpdateIngressStatus updates an Ingress with a provided status. -func (c *clientWrapper) UpdateIngressStatus(src *networkingv1.Ingress, ingStatus []corev1.LoadBalancerIngress) error { +func (c *clientWrapper) UpdateIngressStatus(src *netv1.Ingress, ingStatus []corev1.LoadBalancerIngress) error { if !c.isWatchedNamespace(src.Namespace) { return fmt.Errorf("failed to get ingress %s/%s: namespace is not within watched namespaces", src.Namespace, src.Name) } @@ -375,7 +375,7 @@ func (c *clientWrapper) UpdateIngressStatus(src *networkingv1.Ingress, ingStatus } ingCopy := ing.DeepCopy() - ingCopy.Status = networkingv1.IngressStatus{LoadBalancer: corev1.LoadBalancerStatus{Ingress: ingStatus}} + ingCopy.Status = netv1.IngressStatus{LoadBalancer: corev1.LoadBalancerStatus{Ingress: ingStatus}} ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout) defer cancel() @@ -389,7 +389,7 @@ func (c *clientWrapper) UpdateIngressStatus(src *networkingv1.Ingress, ingStatus return nil } -func (c *clientWrapper) updateIngressStatusOld(src *networkingv1.Ingress, ingStatus []corev1.LoadBalancerIngress) error { +func (c *clientWrapper) updateIngressStatusOld(src *netv1.Ingress, ingStatus []corev1.LoadBalancerIngress) error { ing, err := c.factoriesIngress[c.lookupNamespace(src.Namespace)].Networking().V1beta1().Ingresses().Lister().Ingresses(src.Namespace).Get(src.Name) if err != nil { return fmt.Errorf("failed to get ingress %s/%s: %w", src.Namespace, src.Name, err) @@ -403,7 +403,7 @@ func (c *clientWrapper) updateIngressStatusOld(src *networkingv1.Ingress, ingSta } ingCopy := ing.DeepCopy() - ingCopy.Status = networkingv1beta1.IngressStatus{LoadBalancer: corev1.LoadBalancerStatus{Ingress: ingStatus}} + ingCopy.Status = netv1beta1.IngressStatus{LoadBalancer: corev1.LoadBalancerStatus{Ingress: ingStatus}} ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout) defer cancel() @@ -469,12 +469,12 @@ func (c *clientWrapper) GetSecret(namespace, name string) (*corev1.Secret, bool, return secret, exist, err } -func (c *clientWrapper) GetIngressClasses() ([]*networkingv1.IngressClass, error) { +func (c *clientWrapper) GetIngressClasses() ([]*netv1.IngressClass, error) { if c.clusterFactory == nil { return nil, errors.New("cluster factory not loaded") } - var ics []*networkingv1.IngressClass + var ics []*netv1.IngressClass if !supportsNetworkingV1Ingress(c.serverVersion) { ingressClasses, err := c.clusterFactory.Networking().V1beta1().IngressClasses().Lister().List(labels.Everything()) if err != nil { @@ -530,7 +530,7 @@ func (c *clientWrapper) GetServerVersion() *version.Version { // translateNotFoundError will translate a "not found" error to a boolean return // value which indicates if the resource exists and a nil error. func translateNotFoundError(err error) (bool, error) { - if kubeerror.IsNotFound(err) { + if kerror.IsNotFound(err) { return false, nil } return err == nil, err @@ -559,8 +559,8 @@ func supportsIngressClass(serverVersion *version.Version) bool { } // filterIngressClassByName return a slice containing ingressclasses with the correct name. -func filterIngressClassByName(ingressClassName string, ics []*networkingv1.IngressClass) []*networkingv1.IngressClass { - var ingressClasses []*networkingv1.IngressClass +func filterIngressClassByName(ingressClassName string, ics []*netv1.IngressClass) []*netv1.IngressClass { + var ingressClasses []*netv1.IngressClass for _, ic := range ics { if ic.Name == ingressClassName { diff --git a/pkg/provider/kubernetes/ingress/client_mock_test.go b/pkg/provider/kubernetes/ingress/client_mock_test.go index 6d91c37c8..89de96ca6 100644 --- a/pkg/provider/kubernetes/ingress/client_mock_test.go +++ b/pkg/provider/kubernetes/ingress/client_mock_test.go @@ -7,18 +7,18 @@ import ( "github.com/hashicorp/go-version" "github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s" corev1 "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" - networkingv1beta1 "k8s.io/api/networking/v1beta1" + netv1 "k8s.io/api/networking/v1" + netv1beta1 "k8s.io/api/networking/v1beta1" ) var _ Client = (*clientMock)(nil) type clientMock struct { - ingresses []*networkingv1.Ingress + ingresses []*netv1.Ingress services []*corev1.Service secrets []*corev1.Secret endpoints []*corev1.Endpoints - ingressClasses []*networkingv1.IngressClass + ingressClasses []*netv1.IngressClass serverVersion *version.Version @@ -50,22 +50,22 @@ func newClientMock(serverVersion string, paths ...string) clientMock { c.secrets = append(c.secrets, o) case *corev1.Endpoints: c.endpoints = append(c.endpoints, o) - case *networkingv1beta1.Ingress: + case *netv1beta1.Ingress: ing, err := toNetworkingV1(o) if err != nil { panic(err) } addServiceFromV1Beta1(ing, *o) c.ingresses = append(c.ingresses, ing) - case *networkingv1.Ingress: + case *netv1.Ingress: c.ingresses = append(c.ingresses, o) - case *networkingv1beta1.IngressClass: + case *netv1beta1.IngressClass: ic, err := toNetworkingV1IngressClass(o) if err != nil { panic(err) } c.ingressClasses = append(c.ingressClasses, ic) - case *networkingv1.IngressClass: + case *netv1.IngressClass: c.ingressClasses = append(c.ingressClasses, o) default: panic(fmt.Sprintf("Unknown runtime object %+v %T", o, o)) @@ -76,7 +76,7 @@ func newClientMock(serverVersion string, paths ...string) clientMock { return c } -func (c clientMock) GetIngresses() []*networkingv1.Ingress { +func (c clientMock) GetIngresses() []*netv1.Ingress { return c.ingresses } @@ -124,7 +124,7 @@ func (c clientMock) GetSecret(namespace, name string) (*corev1.Secret, bool, err return nil, false, nil } -func (c clientMock) GetIngressClasses() ([]*networkingv1.IngressClass, error) { +func (c clientMock) GetIngressClasses() ([]*netv1.IngressClass, error) { return c.ingressClasses, nil } @@ -132,6 +132,6 @@ func (c clientMock) WatchAll(namespaces []string, stopCh <-chan struct{}) (<-cha return c.watchChan, nil } -func (c clientMock) UpdateIngressStatus(_ *networkingv1.Ingress, _ []corev1.LoadBalancerIngress) error { +func (c clientMock) UpdateIngressStatus(_ *netv1.Ingress, _ []corev1.LoadBalancerIngress) error { return c.apiIngressStatusError } diff --git a/pkg/provider/kubernetes/ingress/client_test.go b/pkg/provider/kubernetes/ingress/client_test.go index 48f0bf064..662a50e78 100644 --- a/pkg/provider/kubernetes/ingress/client_test.go +++ b/pkg/provider/kubernetes/ingress/client_test.go @@ -9,13 +9,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" - "k8s.io/api/networking/v1beta1" - kubeerror "k8s.io/apimachinery/pkg/api/errors" + netv1 "k8s.io/api/networking/v1" + netv1beta1 "k8s.io/api/networking/v1beta1" + kerror "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/version" - fakediscovery "k8s.io/client-go/discovery/fake" + kschema "k8s.io/apimachinery/pkg/runtime/schema" + kversion "k8s.io/apimachinery/pkg/version" + discoveryfake "k8s.io/client-go/discovery/fake" kubefake "k8s.io/client-go/kubernetes/fake" ) @@ -28,7 +28,7 @@ func TestTranslateNotFoundError(t *testing.T) { }{ { desc: "kubernetes not found error", - err: kubeerror.NewNotFound(schema.GroupResource{}, "foo"), + err: kerror.NewNotFound(kschema.GroupResource{}, "foo"), expectedExists: false, expectedError: nil, }, @@ -154,8 +154,8 @@ func TestClientIgnoresHelmOwnedSecrets(t *testing.T) { kubeClient := kubefake.NewSimpleClientset(helmSecret, secret) - discovery, _ := kubeClient.Discovery().(*fakediscovery.FakeDiscovery) - discovery.FakedServerVersion = &version.Info{ + discovery, _ := kubeClient.Discovery().(*discoveryfake.FakeDiscovery) + discovery.FakedServerVersion = &kversion.Info{ GitVersion: "v1.19", } @@ -223,8 +223,8 @@ func TestClientIgnoresEmptyEndpointUpdates(t *testing.T) { kubeClient := kubefake.NewSimpleClientset(emptyEndpoint, filledEndpoint) - discovery, _ := kubeClient.Discovery().(*fakediscovery.FakeDiscovery) - discovery.FakedServerVersion = &version.Info{ + discovery, _ := kubeClient.Discovery().(*discoveryfake.FakeDiscovery) + discovery.FakedServerVersion = &kversion.Info{ GitVersion: "v1.19", } @@ -291,14 +291,14 @@ func TestClientIgnoresEmptyEndpointUpdates(t *testing.T) { } func TestClientUsesCorrectServerVersion(t *testing.T) { - ingressV1Beta := &v1beta1.Ingress{ + ingressV1Beta := &netv1beta1.Ingress{ ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "ingress-v1beta", }, } - ingressV1 := &networkingv1.Ingress{ + ingressV1 := &netv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ Namespace: "default", Name: "ingress-v1", @@ -307,8 +307,8 @@ func TestClientUsesCorrectServerVersion(t *testing.T) { kubeClient := kubefake.NewSimpleClientset(ingressV1Beta, ingressV1) - discovery, _ := kubeClient.Discovery().(*fakediscovery.FakeDiscovery) - discovery.FakedServerVersion = &version.Info{ + discovery, _ := kubeClient.Discovery().(*discoveryfake.FakeDiscovery) + discovery.FakedServerVersion = &kversion.Info{ GitVersion: "v1.18.12+foobar", } @@ -321,7 +321,7 @@ func TestClientUsesCorrectServerVersion(t *testing.T) { select { case event := <-eventCh: - ingress, ok := event.(*v1beta1.Ingress) + ingress, ok := event.(*netv1beta1.Ingress) require.True(t, ok) assert.Equal(t, "ingress-v1beta", ingress.Name) @@ -335,7 +335,7 @@ func TestClientUsesCorrectServerVersion(t *testing.T) { case <-time.After(50 * time.Millisecond): } - discovery.FakedServerVersion = &version.Info{ + discovery.FakedServerVersion = &kversion.Info{ GitVersion: "v1.19", } @@ -344,7 +344,7 @@ func TestClientUsesCorrectServerVersion(t *testing.T) { select { case event := <-eventCh: - ingress, ok := event.(*networkingv1.Ingress) + ingress, ok := event.(*netv1.Ingress) require.True(t, ok) assert.Equal(t, "ingress-v1", ingress.Name) diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index 9bab326a2..eaea92752 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -25,7 +25,7 @@ import ( "github.com/traefik/traefik/v3/pkg/safe" "github.com/traefik/traefik/v3/pkg/tls" corev1 "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" + netv1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/labels" ) @@ -195,7 +195,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl serverVersion := client.GetServerVersion() - var ingressClasses []*networkingv1.IngressClass + var ingressClasses []*netv1.IngressClass if !p.DisableIngressClassLookup && supportsIngressClass(serverVersion) { ics, err := client.GetIngressClasses() @@ -346,7 +346,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl return conf } -func (p *Provider) updateIngressStatus(ing *networkingv1.Ingress, k8sClient Client) error { +func (p *Provider) updateIngressStatus(ing *netv1.Ingress, k8sClient Client) error { // Only process if an EndpointIngress has been configured. if p.IngressEndpoint == nil { return nil @@ -385,7 +385,7 @@ func (p *Provider) updateIngressStatus(ing *networkingv1.Ingress, k8sClient Clie return k8sClient.UpdateIngressStatus(ing, service.Status.LoadBalancer.Ingress) } -func (p *Provider) shouldProcessIngress(ingress *networkingv1.Ingress, ingressClasses []*networkingv1.IngressClass) bool { +func (p *Provider) shouldProcessIngress(ingress *netv1.Ingress, ingressClasses []*netv1.IngressClass) bool { // configuration through the new kubernetes ingressClass if ingress.Spec.IngressClassName != nil { for _, ic := range ingressClasses { @@ -410,7 +410,7 @@ func buildHostRule(host string) string { return fmt.Sprintf("Host(`%s`)", host) } -func getCertificates(ctx context.Context, ingress *networkingv1.Ingress, k8sClient Client, tlsConfigs map[string]*tls.CertAndStores) error { +func getCertificates(ctx context.Context, ingress *netv1.Ingress, k8sClient Client, tlsConfigs map[string]*tls.CertAndStores) error { for _, t := range ingress.Spec.TLS { if t.SecretName == "" { log.Ctx(ctx).Debug().Msg("Skipping TLS sub-section: No secret name provided") @@ -495,7 +495,7 @@ func getTLSConfig(tlsConfigs map[string]*tls.CertAndStores) []*tls.CertAndStores return configs } -func (p *Provider) loadService(client Client, namespace string, backend networkingv1.IngressBackend) (*dynamic.Service, error) { +func (p *Provider) loadService(client Client, namespace string, backend netv1.IngressBackend) (*dynamic.Service, error) { service, exists, err := client.GetService(namespace, backend.Service.Name) if err != nil { return nil, err @@ -645,7 +645,7 @@ func makeRouterKeyWithHash(key, rule string) (string, error) { return dupKey, nil } -func loadRouter(rule networkingv1.IngressRule, pa networkingv1.HTTPIngressPath, rtConfig *RouterConfig, serviceName string) *dynamic.Router { +func loadRouter(rule netv1.IngressRule, pa netv1.HTTPIngressPath, rtConfig *RouterConfig, serviceName string) *dynamic.Router { var rules []string if len(rule.Host) > 0 { rules = []string{buildHostRule(rule.Host)} @@ -654,11 +654,11 @@ func loadRouter(rule networkingv1.IngressRule, pa networkingv1.HTTPIngressPath, if len(pa.Path) > 0 { matcher := defaultPathMatcher - if pa.PathType == nil || *pa.PathType == "" || *pa.PathType == networkingv1.PathTypeImplementationSpecific { + if pa.PathType == nil || *pa.PathType == "" || *pa.PathType == netv1.PathTypeImplementationSpecific { if rtConfig != nil && rtConfig.Router != nil && rtConfig.Router.PathMatcher != "" { matcher = rtConfig.Router.PathMatcher } - } else if *pa.PathType == networkingv1.PathTypeExact { + } else if *pa.PathType == netv1.PathTypeExact { matcher = "Path" } diff --git a/pkg/provider/kubernetes/ingress/kubernetes_test.go b/pkg/provider/kubernetes/ingress/kubernetes_test.go index 9a3e4e05f..6a3119f0c 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes_test.go +++ b/pkg/provider/kubernetes/ingress/kubernetes_test.go @@ -17,7 +17,7 @@ import ( "github.com/traefik/traefik/v3/pkg/tls" "github.com/traefik/traefik/v3/pkg/types" corev1 "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" + netv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -2160,7 +2160,7 @@ func TestGetCertificates(t *testing.T) { testCases := []struct { desc string - ingress *networkingv1.Ingress + ingress *netv1.Ingress client Client result map[string]*tls.CertAndStores errResult string diff --git a/pkg/provider/kubernetes/k8s/event_handler_test.go b/pkg/provider/kubernetes/k8s/event_handler_test.go index 8f75ebbd2..e8b7a31a2 100644 --- a/pkg/provider/kubernetes/k8s/event_handler_test.go +++ b/pkg/provider/kubernetes/k8s/event_handler_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/networking/v1" + netv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -63,12 +63,12 @@ func Test_detectChanges(t *testing.T) { }, { name: "Ingress With same version", - oldObj: &v1.Ingress{ + oldObj: &netv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "1", }, }, - newObj: &v1.Ingress{ + newObj: &netv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "1", }, @@ -76,12 +76,12 @@ func Test_detectChanges(t *testing.T) { }, { name: "Ingress With different version", - oldObj: &v1.Ingress{ + oldObj: &netv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "1", }, }, - newObj: &v1.Ingress{ + newObj: &netv1.Ingress{ ObjectMeta: metav1.ObjectMeta{ ResourceVersion: "2", }, diff --git a/pkg/provider/kubernetes/k8s/parser.go b/pkg/provider/kubernetes/k8s/parser.go index 6cea900dc..769d5edf5 100644 --- a/pkg/provider/kubernetes/k8s/parser.go +++ b/pkg/provider/kubernetes/k8s/parser.go @@ -7,7 +7,7 @@ import ( "github.com/rs/zerolog/log" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/kubernetes/scheme" + kscheme "k8s.io/client-go/kubernetes/scheme" ) // MustParseYaml parses a YAML to objects. @@ -21,7 +21,7 @@ func MustParseYaml(content []byte) []runtime.Object { continue } - decode := scheme.Codecs.UniversalDeserializer().Decode + decode := kscheme.Codecs.UniversalDeserializer().Decode obj, groupVersionKind, err := decode([]byte(file), nil, nil) if err != nil { panic(fmt.Sprintf("Error while decoding YAML object. Err was: %s", err)) diff --git a/pkg/server/service/roundtripper_test.go b/pkg/server/service/roundtripper_test.go index 971604d92..c9af07a17 100644 --- a/pkg/server/service/roundtripper_test.go +++ b/pkg/server/service/roundtripper_test.go @@ -467,9 +467,6 @@ func newFakeSpiffePKI(trustDomain spiffeid.TrustDomain) (fakeSpiffePKI, error) { IsCA: true, PublicKey: caPrivateKey.Public(), } - if err != nil { - return fakeSpiffePKI{}, err - } caCertDER, err := x509.CreateCertificate( rand.Reader,