mirror of
https://github.com/containous/traefik.git
synced 2024-12-22 13:34:03 +03:00
chore: update linter
This commit is contained in:
parent
ae65d5ff78
commit
be1b1a6489
2
.github/workflows/validate.yaml
vendored
2
.github/workflows/validate.yaml
vendored
@ -7,7 +7,7 @@ on:
|
||||
|
||||
env:
|
||||
GO_VERSION: '1.20'
|
||||
GOLANGCI_LINT_VERSION: v1.51.2
|
||||
GOLANGCI_LINT_VERSION: v1.52.2
|
||||
MISSSPELL_VERSION: v0.4.0
|
||||
IN_DOCKER: ""
|
||||
|
||||
|
145
.golangci.yml
145
.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/v2/pkg/provider/kubernetes/crd/traefikcontainous/v1alpha1"
|
||||
- alias: traefikv1alpha1
|
||||
pkg: "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
- alias: traefikclientset
|
||||
pkg: "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned"
|
||||
- alias: traefikinformers
|
||||
pkg: "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/informers/externalversions"
|
||||
- alias: traefikscheme
|
||||
pkg: "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/scheme"
|
||||
- alias: traefikcrdfake
|
||||
pkg: "github.com/traefik/traefik/v2/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
|
||||
@ -188,3 +261,7 @@ issues:
|
||||
text: 'Duplicate words \(sub\) found'
|
||||
linters:
|
||||
- dupword
|
||||
- path: pkg/provider/kubernetes/gateway/client_mock_test.go
|
||||
text: 'unusedwrite: unused write to field'
|
||||
linters:
|
||||
- govet
|
||||
|
@ -25,7 +25,7 @@ global_job_config:
|
||||
- export "PATH=${GOPATH}/bin:${PATH}"
|
||||
- mkdir -vp "${SEMAPHORE_GIT_DIR}" "${GOPATH}/bin"
|
||||
- export GOPROXY=https://proxy.golang.org,direct
|
||||
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.50.0
|
||||
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.52.2
|
||||
- curl -sSfL https://gist.githubusercontent.com/traefiker/6d7ac019c11d011e4f131bb2cca8900e/raw/goreleaser.sh | bash -s -- -b "${GOPATH}/bin"
|
||||
- checkout
|
||||
- cache restore traefik-$(checksum go.sum)
|
||||
|
@ -13,7 +13,7 @@ RUN mkdir -p /usr/local/bin \
|
||||
| tar -xzC /usr/local/bin --transform 's#^.+/##x'
|
||||
|
||||
# Download golangci-lint binary to bin folder in $GOPATH
|
||||
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $GOPATH/bin v1.50.0
|
||||
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $GOPATH/bin v1.52.2
|
||||
|
||||
# Download misspell binary to bin folder in $GOPATH
|
||||
RUN curl -sfL https://raw.githubusercontent.com/golangci/misspell/master/install-misspell.sh | bash -s -- -b $GOPATH/bin v0.4.0
|
||||
|
@ -22,7 +22,7 @@ find "${PATH_TO_SITE}" -type f -not -path "/app/site/theme/*" \
|
||||
--alt_ignore="/traefikproxy-vertical-logo-color.svg/" \
|
||||
--http_status_ignore="0,500,501,503" \
|
||||
--file_ignore="/404.html/" \
|
||||
--url_ignore="/https://groups.google.com/a/traefik.io/forum/#!forum/security/,/localhost:/,/127.0.0.1:/,/fonts.gstatic.com/,/.minikube/,/github.com\/traefik\/traefik\/*edit*/,/github.com\/traefik\/traefik/,/doc.traefik.io/,/github\.com\/golang\/oauth2\/blob\/36a7019397c4c86cf59eeab3bc0d188bac444277\/.+/,/www.akamai.com/,/pilot.traefik.io\/profile/,/traefik.io/,/doc.traefik.io\/traefik-mesh/,/www.mkdocs.org/,/squidfunk.github.io/,/ietf.org/,/www.namesilo.com/,/www.youtube.com/,/www.linode.com/,/www.alibabacloud.com/,/www.cloudxns.net/,/www.vultr.com/,/vscale.io/,/hetzner.com/,/docs.github.com/,/njal.la/,/www.wedos.com/,/www.reg.ru/,/www.godaddy.com/" \
|
||||
--url_ignore="/https://groups.google.com/a/traefik.io/forum/#!forum/security/,/localhost:/,/127.0.0.1:/,/fonts.gstatic.com/,/.minikube/,/github.com\/traefik\/traefik\/*edit*/,/github.com\/traefik\/traefik/,/doc.traefik.io/,/github\.com\/golang\/oauth2\/blob\/36a7019397c4c86cf59eeab3bc0d188bac444277\/.+/,/www.akamai.com/,/pilot.traefik.io\/profile/,/traefik.io/,/doc.traefik.io\/traefik-mesh/,/www.mkdocs.org/,/squidfunk.github.io/,/ietf.org/,/www.namesilo.com/,/www.youtube.com/,/www.linode.com/,/www.alibabacloud.com/,/www.cloudxns.net/,/www.vultr.com/,/vscale.io/,/hetzner.com/,/docs.github.com/,/njal.la/,/www.wedos.com/,/www.reg.ru/,/www.godaddy.com/,/internetbs.net/" \
|
||||
'{}' 1>/dev/null
|
||||
## HTML-proofer options at https://github.com/gjtorikian/html-proofer#configuration
|
||||
|
||||
|
@ -199,8 +199,8 @@ type ResponseForwarding struct {
|
||||
// Server holds the server configuration.
|
||||
type Server struct {
|
||||
URL string `json:"url,omitempty" toml:"url,omitempty" yaml:"url,omitempty" label:"-"`
|
||||
Scheme string `toml:"-" json:"-" yaml:"-" file:"-"`
|
||||
Port string `toml:"-" json:"-" yaml:"-" file:"-"`
|
||||
Scheme string `json:"-" toml:"-" yaml:"-" file:"-"`
|
||||
Port string `json:"-" toml:"-" yaml:"-" file:"-"`
|
||||
}
|
||||
|
||||
// SetDefaults Default values for a Server.
|
||||
|
@ -391,7 +391,7 @@ func (s *IPStrategy) Get() (ip.Strategy, error) {
|
||||
type IPWhiteList struct {
|
||||
// SourceRange defines the set of allowed IPs (or ranges of allowed IPs by using CIDR notation).
|
||||
SourceRange []string `json:"sourceRange,omitempty" toml:"sourceRange,omitempty" yaml:"sourceRange,omitempty"`
|
||||
IPStrategy *IPStrategy `json:"ipStrategy,omitempty" toml:"ipStrategy,omitempty" yaml:"ipStrategy,omitempty" label:"allowEmpty" file:"allowEmpty" kv:"allowEmpty" export:"true"`
|
||||
IPStrategy *IPStrategy `json:"ipStrategy,omitempty" toml:"ipStrategy,omitempty" yaml:"ipStrategy,omitempty" label:"allowEmpty" file:"allowEmpty" kv:"allowEmpty" export:"true"`
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
|
@ -108,7 +108,7 @@ func (l *TCPServersLoadBalancer) Mergeable(loadBalancer *TCPServersLoadBalancer)
|
||||
// TCPServer holds a TCP Server configuration.
|
||||
type TCPServer struct {
|
||||
Address string `json:"address,omitempty" toml:"address,omitempty" yaml:"address,omitempty" label:"-"`
|
||||
Port string `toml:"-" json:"-" yaml:"-"`
|
||||
Port string `json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen=true
|
||||
|
@ -78,5 +78,5 @@ func (l *UDPServersLoadBalancer) Mergeable(loadBalancer *UDPServersLoadBalancer)
|
||||
// UDPServer defines a UDP server configuration.
|
||||
type UDPServer struct {
|
||||
Address string `json:"address,omitempty" toml:"address,omitempty" yaml:"address,omitempty" label:"-"`
|
||||
Port string `toml:"-" json:"-" yaml:"-" file:"-"`
|
||||
Port string `json:"-" toml:"-" yaml:"-" file:"-"`
|
||||
}
|
||||
|
@ -159,12 +159,12 @@ func (a *LifeCycle) SetDefaults() {
|
||||
type Tracing struct {
|
||||
ServiceName string `description:"Set the name for this service." json:"serviceName,omitempty" toml:"serviceName,omitempty" yaml:"serviceName,omitempty" export:"true"`
|
||||
SpanNameLimit int `description:"Set the maximum character limit for Span names (default 0 = no limit)." json:"spanNameLimit,omitempty" toml:"spanNameLimit,omitempty" yaml:"spanNameLimit,omitempty" export:"true"`
|
||||
Jaeger *jaeger.Config `description:"Settings for Jaeger." json:"jaeger,omitempty" toml:"jaeger,omitempty" yaml:"jaeger,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Zipkin *zipkin.Config `description:"Settings for Zipkin." json:"zipkin,omitempty" toml:"zipkin,omitempty" yaml:"zipkin,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Datadog *datadog.Config `description:"Settings for Datadog." json:"datadog,omitempty" toml:"datadog,omitempty" yaml:"datadog,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Instana *instana.Config `description:"Settings for Instana." json:"instana,omitempty" toml:"instana,omitempty" yaml:"instana,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Haystack *haystack.Config `description:"Settings for Haystack." json:"haystack,omitempty" toml:"haystack,omitempty" yaml:"haystack,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Elastic *elastic.Config `description:"Settings for Elastic." json:"elastic,omitempty" toml:"elastic,omitempty" yaml:"elastic,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Jaeger *jaeger.Config `description:"Settings for Jaeger." json:"jaeger,omitempty" toml:"jaeger,omitempty" yaml:"jaeger,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Zipkin *zipkin.Config `description:"Settings for Zipkin." json:"zipkin,omitempty" toml:"zipkin,omitempty" yaml:"zipkin,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Datadog *datadog.Config `description:"Settings for Datadog." json:"datadog,omitempty" toml:"datadog,omitempty" yaml:"datadog,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Instana *instana.Config `description:"Settings for Instana." json:"instana,omitempty" toml:"instana,omitempty" yaml:"instana,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Haystack *haystack.Config `description:"Settings for Haystack." json:"haystack,omitempty" toml:"haystack,omitempty" yaml:"haystack,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Elastic *elastic.Config `description:"Settings for Elastic." json:"elastic,omitempty" toml:"elastic,omitempty" yaml:"elastic,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
}
|
||||
|
||||
// SetDefaults sets the default values.
|
||||
@ -177,14 +177,14 @@ func (t *Tracing) SetDefaults() {
|
||||
type Providers struct {
|
||||
ProvidersThrottleDuration ptypes.Duration `description:"Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time." json:"providersThrottleDuration,omitempty" toml:"providersThrottleDuration,omitempty" yaml:"providersThrottleDuration,omitempty" export:"true"`
|
||||
|
||||
Docker *docker.Provider `description:"Enable Docker backend with default settings." json:"docker,omitempty" toml:"docker,omitempty" yaml:"docker,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Docker *docker.Provider `description:"Enable Docker backend with default settings." json:"docker,omitempty" toml:"docker,omitempty" yaml:"docker,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
File *file.Provider `description:"Enable File backend with default settings." json:"file,omitempty" toml:"file,omitempty" yaml:"file,omitempty" export:"true"`
|
||||
Marathon *marathon.Provider `description:"Enable Marathon backend with default settings." json:"marathon,omitempty" toml:"marathon,omitempty" yaml:"marathon,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
KubernetesIngress *ingress.Provider `description:"Enable Kubernetes backend with default settings." json:"kubernetesIngress,omitempty" toml:"kubernetesIngress,omitempty" yaml:"kubernetesIngress,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
KubernetesCRD *crd.Provider `description:"Enable Kubernetes backend with default settings." json:"kubernetesCRD,omitempty" toml:"kubernetesCRD,omitempty" yaml:"kubernetesCRD,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
KubernetesGateway *gateway.Provider `description:"Enable Kubernetes gateway api provider with default settings." json:"kubernetesGateway,omitempty" toml:"kubernetesGateway,omitempty" yaml:"kubernetesGateway,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Rest *rest.Provider `description:"Enable Rest backend with default settings." json:"rest,omitempty" toml:"rest,omitempty" yaml:"rest,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Rancher *rancher.Provider `description:"Enable Rancher backend with default settings." json:"rancher,omitempty" toml:"rancher,omitempty" yaml:"rancher,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||
Marathon *marathon.Provider `description:"Enable Marathon backend with default settings." json:"marathon,omitempty" toml:"marathon,omitempty" yaml:"marathon,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
KubernetesIngress *ingress.Provider `description:"Enable Kubernetes backend with default settings." json:"kubernetesIngress,omitempty" toml:"kubernetesIngress,omitempty" yaml:"kubernetesIngress,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
KubernetesCRD *crd.Provider `description:"Enable Kubernetes backend with default settings." json:"kubernetesCRD,omitempty" toml:"kubernetesCRD,omitempty" yaml:"kubernetesCRD,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
KubernetesGateway *gateway.Provider `description:"Enable Kubernetes gateway api provider with default settings." json:"kubernetesGateway,omitempty" toml:"kubernetesGateway,omitempty" yaml:"kubernetesGateway,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Rest *rest.Provider `description:"Enable Rest backend with default settings." json:"rest,omitempty" toml:"rest,omitempty" yaml:"rest,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Rancher *rancher.Provider `description:"Enable Rancher backend with default settings." json:"rancher,omitempty" toml:"rancher,omitempty" yaml:"rancher,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
ConsulCatalog *consulcatalog.ProviderBuilder `description:"Enable ConsulCatalog backend with default settings." json:"consulCatalog,omitempty" toml:"consulCatalog,omitempty" yaml:"consulCatalog,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Nomad *nomad.ProviderBuilder `description:"Enable Nomad backend with default settings." json:"nomad,omitempty" toml:"nomad,omitempty" yaml:"nomad,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
Ecs *ecs.Provider `description:"Enable AWS ECS backend with default settings." json:"ecs,omitempty" toml:"ecs,omitempty" yaml:"ecs,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||
|
@ -422,33 +422,30 @@ func preparePattern(template string) (string, error) {
|
||||
pattern := bytes.NewBufferString("")
|
||||
|
||||
// Host SNI matching is case-insensitive
|
||||
fmt.Fprint(pattern, "(?i)")
|
||||
_, _ = fmt.Fprint(pattern, "(?i)")
|
||||
|
||||
pattern.WriteByte('^')
|
||||
var end int
|
||||
var err error
|
||||
for i := 0; i < len(idxs); i += 2 {
|
||||
// Set all values we are interested in.
|
||||
raw := template[end:idxs[i]]
|
||||
end = idxs[i+1]
|
||||
parts := strings.SplitN(template[idxs[i]+1:end-1], ":", 2)
|
||||
name := parts[0]
|
||||
|
||||
patt := defaultPattern
|
||||
if len(parts) == 2 {
|
||||
patt = parts[1]
|
||||
}
|
||||
|
||||
// Name or pattern can't be empty.
|
||||
if name == "" || patt == "" {
|
||||
return "", fmt.Errorf("mux: missing name or pattern in %q",
|
||||
template[idxs[i]:end])
|
||||
}
|
||||
// Build the regexp pattern.
|
||||
fmt.Fprintf(pattern, "%s(?P<%s>%s)", regexp.QuoteMeta(raw), varGroupName(i/2), patt)
|
||||
|
||||
// Append variable name and compiled pattern.
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// Build the regexp pattern.
|
||||
_, _ = fmt.Fprintf(pattern, "%s(?P<%s>%s)", regexp.QuoteMeta(raw), varGroupName(i/2), patt)
|
||||
}
|
||||
|
||||
// Add the remaining.
|
||||
|
@ -4,15 +4,15 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/scheme"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/informers/externalversions"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikscheme "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/scheme"
|
||||
traefikinformers "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/informers/externalversions"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/k8s"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
)
|
||||
|
||||
func (c *clientWrapper) appendContainousIngressRoutes(result []*v1alpha1.IngressRoute) []*v1alpha1.IngressRoute {
|
||||
func (c *clientWrapper) appendContainousIngressRoutes(result []*traefikv1alpha1.IngressRoute) []*traefikv1alpha1.IngressRoute {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -31,20 +31,20 @@ func (c *clientWrapper) appendContainousIngressRoutes(result []*v1alpha1.Ingress
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(ing, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(ing, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert ingress route in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.IngressRoute))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.IngressRoute))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) appendContainousIngressRouteTCPs(result []*v1alpha1.IngressRouteTCP) []*v1alpha1.IngressRouteTCP {
|
||||
func (c *clientWrapper) appendContainousIngressRouteTCPs(result []*traefikv1alpha1.IngressRouteTCP) []*traefikv1alpha1.IngressRouteTCP {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -63,20 +63,20 @@ func (c *clientWrapper) appendContainousIngressRouteTCPs(result []*v1alpha1.Ingr
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(ing, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(ing, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert tcp ingress route in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.IngressRouteTCP))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.IngressRouteTCP))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) appendContainousIngressRouteUDPs(result []*v1alpha1.IngressRouteUDP) []*v1alpha1.IngressRouteUDP {
|
||||
func (c *clientWrapper) appendContainousIngressRouteUDPs(result []*traefikv1alpha1.IngressRouteUDP) []*traefikv1alpha1.IngressRouteUDP {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -95,20 +95,20 @@ func (c *clientWrapper) appendContainousIngressRouteUDPs(result []*v1alpha1.Ingr
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(ing, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(ing, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert udp ingress route in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.IngressRouteUDP))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.IngressRouteUDP))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) appendContainousMiddlewares(result []*v1alpha1.Middleware) []*v1alpha1.Middleware {
|
||||
func (c *clientWrapper) appendContainousMiddlewares(result []*traefikv1alpha1.Middleware) []*traefikv1alpha1.Middleware {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -127,20 +127,20 @@ func (c *clientWrapper) appendContainousMiddlewares(result []*v1alpha1.Middlewar
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(middleware, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(middleware, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert middleware in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.Middleware))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.Middleware))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) appendContainousMiddlewareTCPs(result []*v1alpha1.MiddlewareTCP) []*v1alpha1.MiddlewareTCP {
|
||||
func (c *clientWrapper) appendContainousMiddlewareTCPs(result []*traefikv1alpha1.MiddlewareTCP) []*traefikv1alpha1.MiddlewareTCP {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -159,20 +159,20 @@ func (c *clientWrapper) appendContainousMiddlewareTCPs(result []*v1alpha1.Middle
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(middleware, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(middleware, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert tcp middleware in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.MiddlewareTCP))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.MiddlewareTCP))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) appendContainousTraefikServices(result []*v1alpha1.TraefikService) []*v1alpha1.TraefikService {
|
||||
func (c *clientWrapper) appendContainousTraefikServices(result []*traefikv1alpha1.TraefikService) []*traefikv1alpha1.TraefikService {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -191,20 +191,20 @@ func (c *clientWrapper) appendContainousTraefikServices(result []*v1alpha1.Traef
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(traefikService, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(traefikService, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert Traefik service in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.TraefikService))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.TraefikService))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) appendContainousServersTransport(result []*v1alpha1.ServersTransport) []*v1alpha1.ServersTransport {
|
||||
func (c *clientWrapper) appendContainousServersTransport(result []*traefikv1alpha1.ServersTransport) []*traefikv1alpha1.ServersTransport {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -223,20 +223,20 @@ func (c *clientWrapper) appendContainousServersTransport(result []*v1alpha1.Serv
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(serversTransport, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(serversTransport, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert servers transport in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.ServersTransport))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.ServersTransport))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) appendContainousTLSOptions(result []*v1alpha1.TLSOption) []*v1alpha1.TLSOption {
|
||||
func (c *clientWrapper) appendContainousTLSOptions(result []*traefikv1alpha1.TLSOption) []*traefikv1alpha1.TLSOption {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -255,20 +255,20 @@ func (c *clientWrapper) appendContainousTLSOptions(result []*v1alpha1.TLSOption)
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(option, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(option, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert tls option in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.TLSOption))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.TLSOption))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) appendContainousTLSStores(result []*v1alpha1.TLSStore) []*v1alpha1.TLSStore {
|
||||
func (c *clientWrapper) appendContainousTLSStores(result []*traefikv1alpha1.TLSStore) []*traefikv1alpha1.TLSStore {
|
||||
listed := map[string]struct{}{}
|
||||
for _, obj := range result {
|
||||
listed[objectKey(obj.ObjectMeta)] = struct{}{}
|
||||
@ -287,20 +287,20 @@ func (c *clientWrapper) appendContainousTLSStores(result []*v1alpha1.TLSStore) [
|
||||
continue
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(store, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(store, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert tls store in namespace %s: %v", ns, err)
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, toVersion.(*v1alpha1.TLSStore))
|
||||
result = append(result, toVersion.(*traefikv1alpha1.TLSStore))
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (c *clientWrapper) getContainousTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) {
|
||||
func (c *clientWrapper) getContainousTraefikService(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)
|
||||
}
|
||||
@ -312,15 +312,15 @@ func (c *clientWrapper) getContainousTraefikService(namespace, name string) (*v1
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
toVersion, err := scheme.Scheme.ConvertToVersion(service, GroupVersioner)
|
||||
toVersion, err := traefikscheme.Scheme.ConvertToVersion(service, GroupVersioner)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to convert Traefik service in namespace %s: %v", namespace, err)
|
||||
}
|
||||
|
||||
return toVersion.(*v1alpha1.TraefikService), exist, err
|
||||
return toVersion.(*traefikv1alpha1.TraefikService), exist, err
|
||||
}
|
||||
|
||||
func addContainousInformers(factoryCrd externalversions.SharedInformerFactory, eventHandler *k8s.ResourceEventHandler) error {
|
||||
func addContainousInformers(factoryCrd traefikinformers.SharedInformerFactory, eventHandler *k8s.ResourceEventHandler) error {
|
||||
_, err := factoryCrd.TraefikContainous().V1alpha1().IngressRoutes().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -9,17 +9,17 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/informers/externalversions"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikclientset "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned"
|
||||
traefikinformers "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/informers/externalversions"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/k8s"
|
||||
"github.com/traefik/traefik/v2/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,16 +31,16 @@ 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
|
||||
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
|
||||
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)
|
||||
@ -48,12 +48,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
|
||||
|
||||
@ -70,12 +70,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
|
||||
}
|
||||
@ -83,13 +83,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),
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,7 +162,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))
|
||||
_, err := factoryCrd.Traefik().V1alpha1().IngressRoutes().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -205,7 +205,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 +215,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
|
||||
@ -255,8 +255,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())
|
||||
@ -269,8 +269,8 @@ func (c *clientWrapper) GetIngressRoutes() []*v1alpha1.IngressRoute {
|
||||
return c.appendContainousIngressRoutes(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())
|
||||
@ -283,8 +283,8 @@ func (c *clientWrapper) GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP {
|
||||
return c.appendContainousIngressRouteTCPs(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())
|
||||
@ -297,8 +297,8 @@ func (c *clientWrapper) GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP {
|
||||
return c.appendContainousIngressRouteUDPs(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())
|
||||
@ -311,8 +311,8 @@ func (c *clientWrapper) GetMiddlewares() []*v1alpha1.Middleware {
|
||||
return c.appendContainousMiddlewares(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())
|
||||
@ -326,7 +326,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)
|
||||
}
|
||||
@ -341,8 +341,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())
|
||||
@ -356,8 +356,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())
|
||||
@ -371,8 +371,8 @@ func (c *clientWrapper) GetServersTransports() []*v1alpha1.ServersTransport {
|
||||
}
|
||||
|
||||
// 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())
|
||||
@ -386,8 +386,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())
|
||||
@ -463,7 +463,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
|
||||
|
@ -5,17 +5,17 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/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,15 +30,15 @@ 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
|
||||
serversTransport []*v1alpha1.ServersTransport
|
||||
ingressRoutes []*traefikv1alpha1.IngressRoute
|
||||
ingressRouteTCPs []*traefikv1alpha1.IngressRouteTCP
|
||||
ingressRouteUDPs []*traefikv1alpha1.IngressRouteUDP
|
||||
middlewares []*traefikv1alpha1.Middleware
|
||||
middlewareTCPs []*traefikv1alpha1.MiddlewareTCP
|
||||
tlsOptions []*traefikv1alpha1.TLSOption
|
||||
tlsStores []*traefikv1alpha1.TLSStore
|
||||
traefikServices []*traefikv1alpha1.TraefikService
|
||||
serversTransport []*traefikv1alpha1.ServersTransport
|
||||
|
||||
watchChan chan interface{}
|
||||
}
|
||||
@ -59,23 +59,23 @@ 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.serversTransport = append(c.serversTransport, o)
|
||||
case *v1alpha1.TLSStore:
|
||||
case *traefikv1alpha1.TLSStore:
|
||||
c.tlsStores = append(c.tlsStores, o)
|
||||
case *corev1.Secret:
|
||||
c.secrets = append(c.secrets, o)
|
||||
@ -88,27 +88,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
|
||||
@ -118,23 +118,23 @@ 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.serversTransport
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
crdfake "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake"
|
||||
traefikcrdfake "github.com/traefik/traefik/v2/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)
|
||||
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"github.com/traefik/traefik/v2/pkg/job"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/safe"
|
||||
"github.com/traefik/traefik/v2/pkg/tls"
|
||||
"github.com/traefik/traefik/v2/pkg/types"
|
||||
@ -521,7 +521,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
|
||||
}
|
||||
@ -550,7 +550,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
|
||||
}
|
||||
@ -576,7 +576,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
|
||||
}
|
||||
@ -591,7 +591,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
|
||||
}
|
||||
@ -616,7 +616,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
|
||||
}
|
||||
@ -708,7 +708,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
|
||||
}
|
||||
@ -755,7 +755,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
|
||||
}
|
||||
@ -830,7 +830,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
|
||||
}
|
||||
@ -996,7 +996,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 {
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/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
|
||||
@ -338,7 +338,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
|
||||
@ -446,7 +446,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.With(ctx, log.Str(log.ServiceName, service.Name))
|
||||
|
||||
namespace := namespaceOrFallback(service, parentNamespace)
|
||||
@ -481,7 +481,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))
|
||||
}
|
||||
@ -502,7 +502,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
|
||||
}
|
||||
@ -510,7 +510,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
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/tls"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
@ -141,7 +141,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 {
|
||||
@ -170,7 +170,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) {
|
||||
@ -207,7 +207,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
|
||||
@ -279,7 +279,7 @@ func (p *Provider) loadTCPServers(client Client, namespace string, svc v1alpha1.
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ import (
|
||||
ptypes "github.com/traefik/paerser/types"
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/provider"
|
||||
crdfake "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikcrdfake "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/fake"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/k8s"
|
||||
"github.com/traefik/traefik/v2/pkg/tls"
|
||||
"github.com/traefik/traefik/v2/pkg/types"
|
||||
@ -5905,23 +5905,23 @@ 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)
|
||||
default:
|
||||
}
|
||||
@ -5929,7 +5929,7 @@ func TestCrossNamespace(t *testing.T) {
|
||||
}
|
||||
|
||||
kubeClient := kubefake.NewSimpleClientset(k8sObjects...)
|
||||
crdClient := crdfake.NewSimpleClientset(crdObjects...)
|
||||
crdClient := traefikcrdfake.NewSimpleClientset(crdObjects...)
|
||||
|
||||
client := newClientImpl(kubeClient, crdClient)
|
||||
|
||||
@ -6200,19 +6200,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:
|
||||
}
|
||||
@ -6220,7 +6220,7 @@ func TestExternalNameService(t *testing.T) {
|
||||
}
|
||||
|
||||
kubeClient := kubefake.NewSimpleClientset(k8sObjects...)
|
||||
crdClient := crdfake.NewSimpleClientset(crdObjects...)
|
||||
crdClient := traefikcrdfake.NewSimpleClientset(crdObjects...)
|
||||
|
||||
client := newClientImpl(kubeClient, crdClient)
|
||||
|
||||
@ -6408,19 +6408,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:
|
||||
}
|
||||
@ -6428,7 +6428,7 @@ func TestNativeLB(t *testing.T) {
|
||||
}
|
||||
|
||||
kubeClient := kubefake.NewSimpleClientset(k8sObjects...)
|
||||
crdClient := crdfake.NewSimpleClientset(crdObjects...)
|
||||
crdClient := traefikcrdfake.NewSimpleClientset(crdObjects...)
|
||||
|
||||
client := newClientImpl(kubeClient, crdClient)
|
||||
|
||||
@ -6452,7 +6452,6 @@ func TestNativeLB(t *testing.T) {
|
||||
|
||||
func TestCreateBasicAuthCredentials(t *testing.T) {
|
||||
var k8sObjects []runtime.Object
|
||||
var crdObjects []runtime.Object
|
||||
yamlContent, err := os.ReadFile(filepath.FromSlash("./fixtures/basic_auth_secrets.yml"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -6468,7 +6467,7 @@ func TestCreateBasicAuthCredentials(t *testing.T) {
|
||||
}
|
||||
|
||||
kubeClient := kubefake.NewSimpleClientset(k8sObjects...)
|
||||
crdClient := crdfake.NewSimpleClientset(crdObjects...)
|
||||
crdClient := traefikcrdfake.NewSimpleClientset()
|
||||
|
||||
client := newClientImpl(kubeClient, crdClient)
|
||||
|
||||
@ -6477,13 +6476,13 @@ func TestCreateBasicAuthCredentials(t *testing.T) {
|
||||
eventCh, err := client.WatchAll([]string{"default"}, stopCh)
|
||||
require.NoError(t, err)
|
||||
|
||||
if k8sObjects != nil || crdObjects != nil {
|
||||
if k8sObjects != nil {
|
||||
// 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)
|
||||
|
||||
@ -6498,7 +6497,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)
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
@ -77,7 +77,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) {
|
||||
@ -101,7 +101,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
|
||||
|
@ -4,51 +4,51 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/log"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/scheme"
|
||||
traefikscheme "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/scheme"
|
||||
containousv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikcontainous/v1alpha1"
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
k8sruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
kschema "k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
var GroupVersioner k8sruntime.GroupVersioner
|
||||
|
||||
func init() {
|
||||
GroupVersioner = k8sruntime.NewMultiGroupVersioner(
|
||||
v1alpha1.SchemeGroupVersion,
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.IngressRoute{}.Kind},
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.IngressRouteTCP{}.Kind},
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.IngressRouteUDP{}.Kind},
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.Middleware{}.Kind},
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.MiddlewareTCP{}.Kind},
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.TLSOption{}.Kind},
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.TLSStore{}.Kind},
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.ServersTransport{}.Kind},
|
||||
schema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.TraefikService{}.Kind},
|
||||
traefikv1alpha1.SchemeGroupVersion,
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.IngressRoute{}.Kind},
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.IngressRouteTCP{}.Kind},
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.IngressRouteUDP{}.Kind},
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.Middleware{}.Kind},
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.MiddlewareTCP{}.Kind},
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.TLSOption{}.Kind},
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.TLSStore{}.Kind},
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.ServersTransport{}.Kind},
|
||||
kschema.GroupKind{Group: containousv1alpha1.GroupName, Kind: containousv1alpha1.TraefikService{}.Kind},
|
||||
)
|
||||
|
||||
convert := map[interface{}]interface{}{}
|
||||
convert[&containousv1alpha1.IngressRoute{}] = &v1alpha1.IngressRoute{}
|
||||
convert[&containousv1alpha1.IngressRouteTCP{}] = &v1alpha1.IngressRouteTCP{}
|
||||
convert[&containousv1alpha1.IngressRouteUDP{}] = &v1alpha1.IngressRouteUDP{}
|
||||
convert[&containousv1alpha1.Middleware{}] = &v1alpha1.Middleware{}
|
||||
convert[&containousv1alpha1.MiddlewareTCP{}] = &v1alpha1.MiddlewareTCP{}
|
||||
convert[&containousv1alpha1.TLSOption{}] = &v1alpha1.TLSOption{}
|
||||
convert[&containousv1alpha1.TLSStore{}] = &v1alpha1.TLSStore{}
|
||||
convert[&containousv1alpha1.ServersTransport{}] = &v1alpha1.ServersTransport{}
|
||||
convert[&containousv1alpha1.TraefikService{}] = &v1alpha1.TraefikService{}
|
||||
convert[&containousv1alpha1.IngressRoute{}] = &traefikv1alpha1.IngressRoute{}
|
||||
convert[&containousv1alpha1.IngressRouteTCP{}] = &traefikv1alpha1.IngressRouteTCP{}
|
||||
convert[&containousv1alpha1.IngressRouteUDP{}] = &traefikv1alpha1.IngressRouteUDP{}
|
||||
convert[&containousv1alpha1.Middleware{}] = &traefikv1alpha1.Middleware{}
|
||||
convert[&containousv1alpha1.MiddlewareTCP{}] = &traefikv1alpha1.MiddlewareTCP{}
|
||||
convert[&containousv1alpha1.TLSOption{}] = &traefikv1alpha1.TLSOption{}
|
||||
convert[&containousv1alpha1.TLSStore{}] = &traefikv1alpha1.TLSStore{}
|
||||
convert[&containousv1alpha1.ServersTransport{}] = &traefikv1alpha1.ServersTransport{}
|
||||
convert[&containousv1alpha1.TraefikService{}] = &traefikv1alpha1.TraefikService{}
|
||||
|
||||
for interfaceA, interfaceB := range convert {
|
||||
err := scheme.Scheme.AddConversionFunc(interfaceA, interfaceB, func(a, b interface{}, scope conversion.Scope) error {
|
||||
err := traefikscheme.Scheme.AddConversionFunc(interfaceA, interfaceB, func(a, b interface{}, scope conversion.Scope) error {
|
||||
unstruct, err := k8sruntime.DefaultUnstructuredConverter.ToUnstructured(a)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unstruct interface: %w", err)
|
||||
}
|
||||
|
||||
u := &unstructured.Unstructured{Object: unstruct}
|
||||
u.SetGroupVersionKind(v1alpha1.SchemeGroupVersion.WithKind(u.GetKind()))
|
||||
u.SetGroupVersionKind(traefikv1alpha1.SchemeGroupVersion.WithKind(u.GetKind()))
|
||||
|
||||
if err = k8sruntime.DefaultUnstructuredConverter.FromUnstructured(u.Object, b); err != nil {
|
||||
return fmt.Errorf("failed to convert interface: %w", err)
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
@ -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
|
||||
}
|
||||
|
@ -14,14 +14,14 @@ import (
|
||||
"github.com/traefik/traefik/v2/pkg/provider/kubernetes/k8s"
|
||||
traefikversion "github.com/traefik/traefik/v2/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"
|
||||
)
|
||||
@ -36,21 +36,21 @@ const (
|
||||
// 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 []networkingv1.IngressLoadBalancerIngress) error
|
||||
UpdateIngressStatus(ing *netv1.Ingress, ingStatus []netv1.IngressLoadBalancerIngress) 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
|
||||
watchedNamespaces []string
|
||||
@ -113,7 +113,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
|
||||
}
|
||||
@ -121,12 +121,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),
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,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) {
|
||||
_, err = factoryIngress.Networking().V1().Ingresses().Informer().AddEventHandler(eventHandler)
|
||||
@ -180,7 +180,7 @@ 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))
|
||||
_, err = factoryKube.Core().V1().Services().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -191,7 +191,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
|
||||
}
|
||||
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))
|
||||
_, err = factorySecret.Core().V1().Secrets().Informer().AddEventHandler(eventHandler)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -226,7 +226,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
|
||||
}
|
||||
|
||||
if supportsIngressClass(serverVersion) {
|
||||
c.clusterFactory = informers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod)
|
||||
c.clusterFactory = kinformers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod)
|
||||
|
||||
if supportsNetworkingV1Ingress(serverVersion) {
|
||||
_, err = c.clusterFactory.Networking().V1().IngressClasses().Informer().AddEventHandler(eventHandler)
|
||||
@ -253,8 +253,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)
|
||||
|
||||
@ -279,7 +279,7 @@ func (c *clientWrapper) GetIngresses() []*networkingv1.Ingress {
|
||||
}
|
||||
|
||||
for _, ing := range list {
|
||||
n, err := convert[networkingv1.Ingress](ing)
|
||||
n, err := convert[netv1.Ingress](ing)
|
||||
if err != nil {
|
||||
log.WithoutContext().Errorf("Failed to convert ingress %s from networking/v1beta1 to networking/v1: %v", ns, err)
|
||||
continue
|
||||
@ -293,9 +293,9 @@ func (c *clientWrapper) GetIngresses() []*networkingv1.Ingress {
|
||||
return results
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -303,8 +303,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,
|
||||
},
|
||||
@ -320,14 +320,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,
|
||||
}
|
||||
@ -339,7 +339,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 []networkingv1.IngressLoadBalancerIngress) error {
|
||||
func (c *clientWrapper) UpdateIngressStatus(src *netv1.Ingress, ingStatus []netv1.IngressLoadBalancerIngress) 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)
|
||||
}
|
||||
@ -361,7 +361,7 @@ func (c *clientWrapper) UpdateIngressStatus(src *networkingv1.Ingress, ingStatus
|
||||
}
|
||||
|
||||
ingCopy := ing.DeepCopy()
|
||||
ingCopy.Status = networkingv1.IngressStatus{LoadBalancer: networkingv1.IngressLoadBalancerStatus{Ingress: ingStatus}}
|
||||
ingCopy.Status = netv1.IngressStatus{LoadBalancer: netv1.IngressLoadBalancerStatus{Ingress: ingStatus}}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
|
||||
defer cancel()
|
||||
@ -375,7 +375,7 @@ func (c *clientWrapper) UpdateIngressStatus(src *networkingv1.Ingress, ingStatus
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *clientWrapper) updateIngressStatusOld(src *networkingv1.Ingress, ingStatus []networkingv1.IngressLoadBalancerIngress) error {
|
||||
func (c *clientWrapper) updateIngressStatusOld(src *netv1.Ingress, ingStatus []netv1.IngressLoadBalancerIngress) 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)
|
||||
@ -383,7 +383,7 @@ func (c *clientWrapper) updateIngressStatusOld(src *networkingv1.Ingress, ingSta
|
||||
|
||||
logger := log.WithoutContext().WithField("namespace", ing.Namespace).WithField("ingress", ing.Name)
|
||||
|
||||
ingresses, err := convertSlice[networkingv1.IngressLoadBalancerIngress](ing.Status.LoadBalancer.Ingress)
|
||||
ingresses, err := convertSlice[netv1.IngressLoadBalancerIngress](ing.Status.LoadBalancer.Ingress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -393,13 +393,13 @@ func (c *clientWrapper) updateIngressStatusOld(src *networkingv1.Ingress, ingSta
|
||||
return nil
|
||||
}
|
||||
|
||||
ingressesBeta1, err := convertSlice[networkingv1beta1.IngressLoadBalancerIngress](ingStatus)
|
||||
ingressesBeta1, err := convertSlice[netv1beta1.IngressLoadBalancerIngress](ingStatus)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ingCopy := ing.DeepCopy()
|
||||
ingCopy.Status = networkingv1beta1.IngressStatus{LoadBalancer: networkingv1beta1.IngressLoadBalancerStatus{Ingress: ingressesBeta1}}
|
||||
ingCopy.Status = netv1beta1.IngressStatus{LoadBalancer: netv1beta1.IngressLoadBalancerStatus{Ingress: ingressesBeta1}}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
|
||||
defer cancel()
|
||||
@ -413,7 +413,7 @@ func (c *clientWrapper) updateIngressStatusOld(src *networkingv1.Ingress, ingSta
|
||||
}
|
||||
|
||||
// isLoadBalancerIngressEquals returns true if the given slices are equal, false otherwise.
|
||||
func isLoadBalancerIngressEquals(aSlice, bSlice []networkingv1.IngressLoadBalancerIngress) bool {
|
||||
func isLoadBalancerIngressEquals(aSlice, bSlice []netv1.IngressLoadBalancerIngress) bool {
|
||||
if len(aSlice) != len(bSlice) {
|
||||
return false
|
||||
}
|
||||
@ -465,12 +465,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 {
|
||||
@ -479,7 +479,7 @@ func (c *clientWrapper) GetIngressClasses() ([]*networkingv1.IngressClass, error
|
||||
|
||||
for _, ic := range ingressClasses {
|
||||
if ic.Spec.Controller == traefikDefaultIngressClassController {
|
||||
icN, err := convert[networkingv1.IngressClass](ic)
|
||||
icN, err := convert[netv1.IngressClass](ic)
|
||||
if err != nil {
|
||||
log.WithoutContext().Errorf("Failed to convert ingress class %s from networking/v1beta1 to networking/v1: %v", ic.Name, err)
|
||||
continue
|
||||
@ -526,7 +526,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
|
||||
@ -555,8 +555,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 {
|
||||
|
@ -7,18 +7,18 @@ import (
|
||||
"github.com/hashicorp/go-version"
|
||||
"github.com/traefik/traefik/v2/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:
|
||||
ing, err := convert[networkingv1.Ingress](o)
|
||||
case *netv1beta1.Ingress:
|
||||
ing, err := convert[netv1.Ingress](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:
|
||||
ic, err := convert[networkingv1.IngressClass](o)
|
||||
case *netv1beta1.IngressClass:
|
||||
ic, err := convert[netv1.IngressClass](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, _ []networkingv1.IngressLoadBalancerIngress) error {
|
||||
func (c clientMock) UpdateIngressStatus(_ *netv1.Ingress, _ []netv1.IngressLoadBalancerIngress) error {
|
||||
return c.apiIngressStatusError
|
||||
}
|
||||
|
@ -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,
|
||||
},
|
||||
@ -61,8 +61,8 @@ func TestTranslateNotFoundError(t *testing.T) {
|
||||
func TestIsLoadBalancerIngressEquals(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
aSlice []networkingv1.IngressLoadBalancerIngress
|
||||
bSlice []networkingv1.IngressLoadBalancerIngress
|
||||
aSlice []netv1.IngressLoadBalancerIngress
|
||||
bSlice []netv1.IngressLoadBalancerIngress
|
||||
expectedEqual bool
|
||||
}{
|
||||
{
|
||||
@ -71,28 +71,28 @@ func TestIsLoadBalancerIngressEquals(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "not the same length",
|
||||
bSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
bSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
},
|
||||
expectedEqual: false,
|
||||
},
|
||||
{
|
||||
desc: "same ordered content",
|
||||
aSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
aSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
},
|
||||
bSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
bSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
},
|
||||
expectedEqual: true,
|
||||
},
|
||||
{
|
||||
desc: "same unordered content",
|
||||
aSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
aSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
{IP: "192.168.1.2", Hostname: "traefik2"},
|
||||
},
|
||||
bSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
bSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.2", Hostname: "traefik2"},
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
},
|
||||
@ -100,11 +100,11 @@ func TestIsLoadBalancerIngressEquals(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "different ordered content",
|
||||
aSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
aSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
{IP: "192.168.1.2", Hostname: "traefik2"},
|
||||
},
|
||||
bSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
bSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
{IP: "192.168.1.2", Hostname: "traefik"},
|
||||
},
|
||||
@ -112,11 +112,11 @@ func TestIsLoadBalancerIngressEquals(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "different unordered content",
|
||||
aSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
aSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
{IP: "192.168.1.2", Hostname: "traefik2"},
|
||||
},
|
||||
bSlice: []networkingv1.IngressLoadBalancerIngress{
|
||||
bSlice: []netv1.IngressLoadBalancerIngress{
|
||||
{IP: "192.168.1.2", Hostname: "traefik3"},
|
||||
{IP: "192.168.1.1", Hostname: "traefik"},
|
||||
},
|
||||
@ -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)
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
type marshaler interface {
|
||||
@ -17,7 +17,7 @@ type unmarshaler interface {
|
||||
}
|
||||
|
||||
type LoadBalancerIngress interface {
|
||||
corev1.LoadBalancerIngress | networkingv1beta1.IngressLoadBalancerIngress | networkingv1.IngressLoadBalancerIngress
|
||||
corev1.LoadBalancerIngress | netv1beta1.IngressLoadBalancerIngress | netv1.IngressLoadBalancerIngress
|
||||
}
|
||||
|
||||
// convertSlice converts slice of LoadBalancerIngress to slice of LoadBalancerIngress.
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
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"
|
||||
)
|
||||
|
||||
func Test_convertSlice_corev1_to_networkingv1(t *testing.T) {
|
||||
@ -25,14 +25,14 @@ func Test_convertSlice_corev1_to_networkingv1(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, err := convertSlice[networkingv1.IngressLoadBalancerIngress](g)
|
||||
actual, err := convertSlice[netv1.IngressLoadBalancerIngress](g)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := []networkingv1.IngressLoadBalancerIngress{
|
||||
expected := []netv1.IngressLoadBalancerIngress{
|
||||
{
|
||||
IP: "132456",
|
||||
Hostname: "foo",
|
||||
Ports: []networkingv1.IngressPortStatus{
|
||||
Ports: []netv1.IngressPortStatus{
|
||||
{
|
||||
Port: 123,
|
||||
Protocol: "https",
|
||||
@ -46,11 +46,11 @@ func Test_convertSlice_corev1_to_networkingv1(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_convertSlice_networkingv1beta1_to_networkingv1(t *testing.T) {
|
||||
g := []networkingv1beta1.IngressLoadBalancerIngress{
|
||||
g := []netv1beta1.IngressLoadBalancerIngress{
|
||||
{
|
||||
IP: "132456",
|
||||
Hostname: "foo",
|
||||
Ports: []networkingv1beta1.IngressPortStatus{
|
||||
Ports: []netv1beta1.IngressPortStatus{
|
||||
{
|
||||
Port: 123,
|
||||
Protocol: "https",
|
||||
@ -60,14 +60,14 @@ func Test_convertSlice_networkingv1beta1_to_networkingv1(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, err := convertSlice[networkingv1.IngressLoadBalancerIngress](g)
|
||||
actual, err := convertSlice[netv1.IngressLoadBalancerIngress](g)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := []networkingv1.IngressLoadBalancerIngress{
|
||||
expected := []netv1.IngressLoadBalancerIngress{
|
||||
{
|
||||
IP: "132456",
|
||||
Hostname: "foo",
|
||||
Ports: []networkingv1.IngressPortStatus{
|
||||
Ports: []netv1.IngressPortStatus{
|
||||
{
|
||||
Port: 123,
|
||||
Protocol: "https",
|
||||
@ -81,11 +81,11 @@ func Test_convertSlice_networkingv1beta1_to_networkingv1(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_convertSlice_networkingv1_to_networkingv1beta1(t *testing.T) {
|
||||
g := []networkingv1.IngressLoadBalancerIngress{
|
||||
g := []netv1.IngressLoadBalancerIngress{
|
||||
{
|
||||
IP: "132456",
|
||||
Hostname: "foo",
|
||||
Ports: []networkingv1.IngressPortStatus{
|
||||
Ports: []netv1.IngressPortStatus{
|
||||
{
|
||||
Port: 123,
|
||||
Protocol: "https",
|
||||
@ -95,14 +95,14 @@ func Test_convertSlice_networkingv1_to_networkingv1beta1(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, err := convertSlice[networkingv1beta1.IngressLoadBalancerIngress](g)
|
||||
actual, err := convertSlice[netv1beta1.IngressLoadBalancerIngress](g)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := []networkingv1beta1.IngressLoadBalancerIngress{
|
||||
expected := []netv1beta1.IngressLoadBalancerIngress{
|
||||
{
|
||||
IP: "132456",
|
||||
Hostname: "foo",
|
||||
Ports: []networkingv1beta1.IngressPortStatus{
|
||||
Ports: []netv1beta1.IngressPortStatus{
|
||||
{
|
||||
Port: 123,
|
||||
Protocol: "https",
|
||||
@ -128,13 +128,13 @@ func Test_convert(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
actual, err := convert[networkingv1.IngressLoadBalancerIngress](g)
|
||||
actual, err := convert[netv1.IngressLoadBalancerIngress](g)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := &networkingv1.IngressLoadBalancerIngress{
|
||||
expected := &netv1.IngressLoadBalancerIngress{
|
||||
IP: "132456",
|
||||
Hostname: "foo",
|
||||
Ports: []networkingv1.IngressPortStatus{
|
||||
Ports: []netv1.IngressPortStatus{
|
||||
{
|
||||
Port: 123,
|
||||
Protocol: "https",
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
"github.com/traefik/traefik/v2/pkg/safe"
|
||||
"github.com/traefik/traefik/v2/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"
|
||||
)
|
||||
|
||||
@ -191,7 +191,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||
|
||||
serverVersion := client.GetServerVersion()
|
||||
|
||||
var ingressClasses []*networkingv1.IngressClass
|
||||
var ingressClasses []*netv1.IngressClass
|
||||
|
||||
if supportsIngressClass(serverVersion) {
|
||||
ics, err := client.GetIngressClasses()
|
||||
@ -339,7 +339,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
|
||||
@ -350,7 +350,7 @@ func (p *Provider) updateIngressStatus(ing *networkingv1.Ingress, k8sClient Clie
|
||||
return errors.New("publishedService or ip or hostname must be defined")
|
||||
}
|
||||
|
||||
return k8sClient.UpdateIngressStatus(ing, []networkingv1.IngressLoadBalancerIngress{{IP: p.IngressEndpoint.IP, Hostname: p.IngressEndpoint.Hostname}})
|
||||
return k8sClient.UpdateIngressStatus(ing, []netv1.IngressLoadBalancerIngress{{IP: p.IngressEndpoint.IP, Hostname: p.IngressEndpoint.Hostname}})
|
||||
}
|
||||
|
||||
serviceInfo := strings.Split(p.IngressEndpoint.PublishedService, "/")
|
||||
@ -375,7 +375,7 @@ func (p *Provider) updateIngressStatus(ing *networkingv1.Ingress, k8sClient Clie
|
||||
return fmt.Errorf("missing service: %s", p.IngressEndpoint.PublishedService)
|
||||
}
|
||||
|
||||
ingresses, err := convertSlice[networkingv1.IngressLoadBalancerIngress](service.Status.LoadBalancer.Ingress)
|
||||
ingresses, err := convertSlice[netv1.IngressLoadBalancerIngress](service.Status.LoadBalancer.Ingress)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -383,7 +383,7 @@ func (p *Provider) updateIngressStatus(ing *networkingv1.Ingress, k8sClient Clie
|
||||
return k8sClient.UpdateIngressStatus(ing, ingresses)
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -407,7 +407,7 @@ func buildHostRule(host string) string {
|
||||
return "Host(`" + 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.FromContext(ctx).Debugf("Skipping TLS sub-section: No secret name provided")
|
||||
@ -492,7 +492,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
|
||||
@ -643,7 +643,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)}
|
||||
@ -652,11 +652,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"
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
"github.com/traefik/traefik/v2/pkg/tls"
|
||||
"github.com/traefik/traefik/v2/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"
|
||||
)
|
||||
|
||||
@ -1898,7 +1898,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
|
||||
|
@ -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",
|
||||
},
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/traefik/traefik/v2/pkg/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))
|
||||
|
Loading…
Reference in New Issue
Block a user