chore: update linter
This commit is contained in:
parent
ae65d5ff78
commit
be1b1a6489
38 changed files with 924 additions and 852 deletions
|
@ -9,16 +9,16 @@ import (
|
|||
|
||||
"github.com/traefik/traefik/v2/pkg/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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,8 +126,7 @@ func newExternalClusterClientFromFile(file string) (*clientWrapper, error) {
|
|||
return createClientFromConfig(configFromFlags)
|
||||
}
|
||||
|
||||
// newExternalClusterClient returns a new Provider client that may run outside
|
||||
// of the cluster.
|
||||
// newExternalClusterClient returns a new Provider client that may run outside of the cluster.
|
||||
// The endpoint parameter must not be empty.
|
||||
func newExternalClusterClient(endpoint, token, caFilePath string) (*clientWrapper, error) {
|
||||
if endpoint == "" {
|
||||
|
@ -171,13 +170,13 @@ 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)
|
||||
_, err := c.factoryNamespace.Core().V1().Namespaces().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.factoryGatewayClass = externalversions.NewSharedInformerFactoryWithOptions(c.csGateway, resyncPeriod, externalversions.WithTweakListOptions(labelSelectorOptions))
|
||||
c.factoryGatewayClass = gateinformers.NewSharedInformerFactoryWithOptions(c.csGateway, resyncPeriod, gateinformers.WithTweakListOptions(labelSelectorOptions))
|
||||
_, err = c.factoryGatewayClass.Gateway().V1alpha2().GatewayClasses().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -187,7 +186,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
|
|||
// 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))
|
||||
_, err = factoryGateway.Gateway().V1alpha2().Gateways().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -205,7 +204,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
|
|||
return nil, err
|
||||
}
|
||||
|
||||
factoryKube := informers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, informers.WithNamespace(ns))
|
||||
factoryKube := kinformers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, kinformers.WithNamespace(ns))
|
||||
_, err = factoryKube.Core().V1().Services().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -215,7 +214,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
|
|||
return nil, err
|
||||
}
|
||||
|
||||
factorySecret := informers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, informers.WithNamespace(ns), informers.WithTweakListOptions(notOwnedByHelm))
|
||||
factorySecret := kinformers.NewSharedInformerFactoryWithOptions(c.csKube, resyncPeriod, kinformers.WithNamespace(ns), kinformers.WithTweakListOptions(notOwnedByHelm))
|
||||
_, err = factorySecret.Core().V1().Secrets().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -287,8 +286,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.WithoutContext().Warnf("Failed to get HTTPRoutes: %q is not within watched namespaces", namespace)
|
||||
|
@ -311,8 +310,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.WithoutContext().Warnf("Failed to get TCPRoutes: %q is not within watched namespaces", namespace)
|
||||
|
@ -334,8 +333,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.WithoutContext().Warnf("Failed to get TLSRoutes: %q is not within watched namespaces", namespace)
|
||||
|
@ -357,8 +356,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())
|
||||
|
@ -372,11 +371,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
|
||||
|
@ -407,7 +406,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)
|
||||
}
|
||||
|
@ -430,7 +429,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
|
||||
}
|
||||
|
@ -537,7 +536,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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -29,7 +29,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.Errorf("Failed to update %s condition: %v", v1alpha2.GatewayClassConditionStatusAccepted, err)
|
||||
logger.Errorf("Failed to update %s condition: %v", gatev1alpha2.GatewayClassConditionStatusAccepted, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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{
|
||||
UDP: &dynamic.UDPConfiguration{
|
||||
Routers: map[string]*dynamic.UDPRouter{},
|
||||
|
@ -315,15 +315,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.FromContext(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{},
|
||||
}
|
||||
|
||||
|
@ -345,7 +345,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",
|
||||
|
@ -361,19 +361,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
|
||||
|
@ -384,11 +384,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
|
||||
|
@ -399,12 +399,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
|
||||
|
@ -415,12 +415,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",
|
||||
})
|
||||
|
||||
|
@ -431,10 +431,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",
|
||||
})
|
||||
|
||||
|
@ -448,10 +448,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),
|
||||
})
|
||||
|
||||
|
@ -461,10 +461,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",
|
||||
})
|
||||
|
||||
|
@ -477,10 +477,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),
|
||||
})
|
||||
|
||||
|
@ -507,10 +507,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
|
||||
|
@ -518,7 +518,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",
|
||||
|
@ -536,10 +536,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",
|
||||
})
|
||||
|
||||
|
@ -551,7 +551,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",
|
||||
|
@ -559,7 +559,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",
|
||||
|
@ -570,14 +570,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
|
||||
}
|
||||
|
||||
|
@ -588,43 +588,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 {
|
||||
|
@ -636,10 +636,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
|
||||
|
@ -654,7 +654,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
|
||||
|
@ -664,7 +664,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
|
||||
|
@ -676,10 +676,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),
|
||||
}}
|
||||
}
|
||||
|
@ -705,7 +705,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
|
||||
|
@ -719,7 +719,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
|
||||
|
@ -732,7 +732,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{}
|
||||
}
|
||||
|
@ -743,7 +743,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
|
||||
|
@ -766,7 +766,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
|
||||
|
@ -795,7 +795,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
|
||||
|
@ -805,7 +805,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
|
||||
|
@ -817,10 +817,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),
|
||||
}}
|
||||
}
|
||||
|
@ -841,10 +841,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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -854,7 +854,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
|
||||
|
@ -879,7 +879,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
|
||||
|
@ -925,7 +925,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
|
||||
|
@ -935,7 +935,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
|
||||
|
@ -947,10 +947,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),
|
||||
}}
|
||||
}
|
||||
|
@ -977,7 +977,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
|
||||
|
@ -991,7 +991,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,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1001,7 +1001,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
|
||||
|
@ -1026,7 +1026,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
|
||||
|
@ -1074,18 +1074,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 {
|
||||
|
@ -1116,9 +1116,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
|
||||
}
|
||||
|
||||
|
@ -1143,19 +1143,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)
|
||||
|
@ -1167,7 +1167,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 hostNames []string
|
||||
var hostRegexNames []string
|
||||
|
||||
|
@ -1212,9 +1212,9 @@ func hostRule(hostnames []v1alpha2.Hostname) (string, error) {
|
|||
return hostRegexp, nil
|
||||
}
|
||||
|
||||
func hostSNIRule(hostnames []v1alpha2.Hostname) (string, error) {
|
||||
func hostSNIRule(hostnames []gatev1alpha2.Hostname) (string, error) {
|
||||
var matchers []string
|
||||
uniqHostnames := map[v1alpha2.Hostname]struct{}{}
|
||||
uniqHostnames := map[gatev1alpha2.Hostname]struct{}{}
|
||||
|
||||
for _, hostname := range hostnames {
|
||||
if len(hostname) == 0 {
|
||||
|
@ -1243,7 +1243,7 @@ func hostSNIRule(hostnames []v1alpha2.Hostname) (string, error) {
|
|||
return "HostSNI(" + strings.Join(matchers, ",") + ")", 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
|
||||
|
||||
|
@ -1257,9 +1257,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)
|
||||
|
@ -1300,7 +1300,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
|
||||
|
@ -1311,7 +1311,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)
|
||||
|
@ -1340,7 +1340,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)
|
||||
|
@ -1414,7 +1414,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{
|
||||
|
@ -1538,7 +1538,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{
|
||||
|
@ -1695,7 +1695,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
|
||||
}
|
||||
|
@ -1703,13 +1703,13 @@ func isTraefikService(ref v1alpha2.BackendRef) bool {
|
|||
return (*ref.Group == containousv1alpha1.GroupName || *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
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue