2019-03-14 14:56:06 +00:00
|
|
|
package ingress
|
2019-02-21 22:08:05 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"math"
|
2023-03-20 15:46:05 +00:00
|
|
|
"path/filepath"
|
2019-03-14 14:56:06 +00:00
|
|
|
"strings"
|
2019-02-21 22:08:05 +00:00
|
|
|
"testing"
|
2022-11-16 10:38:07 +00:00
|
|
|
"time"
|
2019-02-21 22:08:05 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-11-16 10:38:07 +00:00
|
|
|
ptypes "github.com/traefik/paerser/types"
|
2023-02-03 14:24:05 +00:00
|
|
|
"github.com/traefik/traefik/v3/pkg/config/dynamic"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/provider"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/tls"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/types"
|
2019-02-21 22:08:05 +00:00
|
|
|
corev1 "k8s.io/api/core/v1"
|
2023-04-17 08:56:36 +00:00
|
|
|
netv1 "k8s.io/api/networking/v1"
|
2019-02-21 22:08:05 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
)
|
|
|
|
|
2019-03-14 14:56:06 +00:00
|
|
|
var _ provider.Provider = (*Provider)(nil)
|
|
|
|
|
2019-09-30 16:12:04 +00:00
|
|
|
func Bool(v bool) *bool { return &v }
|
|
|
|
|
2019-02-21 22:08:05 +00:00
|
|
|
func TestLoadConfigurationFromIngresses(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2022-12-22 15:30:05 +00:00
|
|
|
desc string
|
|
|
|
ingressClass string
|
|
|
|
expected *dynamic.Configuration
|
|
|
|
allowEmptyServices bool
|
|
|
|
disableIngressClassLookup bool
|
2019-02-21 22:08:05 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Empty ingresses",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
2020-01-07 15:26:08 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress one rule host only",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress with a basic rule on one path",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-14 14:48:06 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress with annotations",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-bar": {
|
2020-01-14 14:48:06 +00:00
|
|
|
Rule: "Path(`/bar`)",
|
|
|
|
EntryPoints: []string{"ep1", "ep2"},
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
Middlewares: []string{"md1", "md2"},
|
|
|
|
Priority: 42,
|
|
|
|
TLS: &dynamic.RouterTLSConfig{
|
|
|
|
CertResolver: "foobar",
|
|
|
|
Domains: []types.Domain{
|
|
|
|
{
|
|
|
|
Main: "domain.com",
|
|
|
|
SANs: []string{"one.domain.com", "two.domain.com"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Main: "example.com",
|
|
|
|
SANs: []string{"one.example.com", "two.example.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Options: "foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2020-01-14 14:48:06 +00:00
|
|
|
Sticky: &dynamic.Sticky{
|
|
|
|
Cookie: &dynamic.Cookie{
|
|
|
|
Name: "foobar",
|
|
|
|
Secure: true,
|
|
|
|
HTTPOnly: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "protocol://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
URL: "protocol://10.21.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
2021-04-20 15:19:29 +00:00
|
|
|
ServersTransport: "foobar@file",
|
2020-01-14 14:48:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress with two different rules with one path",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-foo": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/foo`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-01-05 11:26:04 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress with conflicting routers on host",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2022-11-28 14:48:05 +00:00
|
|
|
"testing-bar-bar-aba9a7d00e9b06a78e16": {
|
|
|
|
Rule: "HostRegexp(`^[a-zA-Z0-9-]+\\.bar$`) && PathPrefix(`/bar`)",
|
2021-01-05 11:26:04 +00:00
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
"testing-bar-bar-636bf36c00fedaab3d44": {
|
|
|
|
Rule: "Host(`bar`) && PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-01-05 11:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
URL: "http://10.21.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with conflicting routers on path",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-foo-bar-d0b30949e54d6a7515ca": {
|
|
|
|
Rule: "PathPrefix(`/foo/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
"testing-foo-bar-dcd54bae39a6d7557f48": {
|
|
|
|
Rule: "PathPrefix(`/foo-bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-01-05 11:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
URL: "http://10.21.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress one rule with two paths",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-foo": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/foo`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress one rule with one path and one host",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-01-14 14:48:06 +00:00
|
|
|
},
|
|
|
|
{
|
2019-02-21 22:08:05 +00:00
|
|
|
desc: "Ingress with one host without path",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-example-com": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`example.com`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-example-com-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-example-com-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.11.0.1:80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress one rule with one host and two paths",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-foo": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/foo`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress Two rules with one host and one path",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-courgette-carotte": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.courgette`) && PathPrefix(`/carotte`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with two services",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-courgette-carotte": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.courgette`) && PathPrefix(`/carotte`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service2-8082",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service2-8082": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.2:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.2:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-05-06 16:12:10 +00:00
|
|
|
desc: "Ingress with one service without endpoints subset",
|
|
|
|
allowEmptyServices: true,
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
2021-05-06 16:12:10 +00:00
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-traefik-tchouk-bar": {
|
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-05-06 16:12:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with one service without endpoint",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Single Service Ingress (without any rules)",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-10-09 15:16:07 +00:00
|
|
|
"default-router": {
|
2024-05-15 08:46:04 +00:00
|
|
|
Rule: "PathPrefix(`/`)",
|
|
|
|
RuleSyntax: "v3",
|
|
|
|
Service: "default-backend",
|
|
|
|
Priority: math.MinInt32,
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-03-14 08:30:04 +00:00
|
|
|
"default-backend": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with port value in backend and no pod replica",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with port name in backend and no pod replica",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-tchouk",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-tchouk": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.21.0.1:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-10-04 18:38:09 +00:00
|
|
|
desc: "Ingress with port name in backend and 2 pod replica",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-tchouk",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-tchouk": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.2:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with two paths using same service and different port name",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-tchouk",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-foo": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/foo`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-carotte",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-tchouk": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.2:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-carotte": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8090",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.2:8090",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-27 22:58:07 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress with a named port matching subset of service pods",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-traefik-tchouk-bar": {
|
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-tchouk",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-tchouk": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-05-27 22:58:07 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8089",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.2:8089",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
{
|
|
|
|
desc: "2 ingresses in different namespace with same service name",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-tchouk",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2020-02-18 16:34:05 +00:00
|
|
|
"toto-toto-traefik-tchouk-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`toto.traefik.tchouk`) && PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "toto-service1-tchouk",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-tchouk": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.2:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-09-13 18:44:04 +00:00
|
|
|
"toto-service1-tchouk": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.11.0.1:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.11.0.2:8089",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with unknown service port name",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with unknown service port",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-15 16:16:04 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress with port invalid for one service",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-traefik-port-port": {
|
|
|
|
Rule: "Host(`traefik.port`) && PathPrefix(`/port`)",
|
|
|
|
Service: "testing-service1-8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-8080": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-04-15 16:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.0.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
{
|
|
|
|
desc: "TLS support",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-example-com": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "Host(`example.com`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-example-com-80",
|
2019-08-14 17:16:06 +00:00
|
|
|
TLS: &dynamic.RouterTLSConfig{},
|
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-example-com-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.11.0.1:80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
TLS: &dynamic.TLSConfiguration{
|
2019-06-27 21:58:03 +00:00
|
|
|
Certificates: []*tls.CertAndStores{
|
|
|
|
{
|
|
|
|
Certificate: tls.Certificate{
|
2024-01-11 16:06:06 +00:00
|
|
|
CertFile: types.FileOrContent("-----BEGIN CERTIFICATE-----\n-----END CERTIFICATE-----"),
|
|
|
|
KeyFile: types.FileOrContent("-----BEGIN PRIVATE KEY-----\n-----END PRIVATE KEY-----"),
|
2019-06-27 21:58:03 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with a basic rule on one path with https (port == 443)",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-443": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-08-14 16:58:04 +00:00
|
|
|
URL: "https://10.10.0.1:8443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-08-14 16:58:04 +00:00
|
|
|
URL: "https://10.21.0.1:8443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with a basic rule on one path with https (portname == https)",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-8443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-8443": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "https://10.10.0.1:8443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "https://10.21.0.1:8443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-03-06 09:03:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with a basic rule on one path with https (portname starts with https)",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
2019-03-14 08:30:04 +00:00
|
|
|
|
2019-07-10 07:26:04 +00:00
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-8443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-03-06 09:03:29 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-8443": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "https://10.10.0.1:8443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "https://10.21.0.1:8443",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Double Single Service Ingress",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2019-10-09 15:16:07 +00:00
|
|
|
"default-router": {
|
2024-05-15 08:46:04 +00:00
|
|
|
Rule: "PathPrefix(`/`)",
|
|
|
|
RuleSyntax: "v3",
|
|
|
|
Service: "default-backend",
|
|
|
|
Priority: math.MinInt32,
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-03-14 08:30:04 +00:00
|
|
|
"default-backend": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.30.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.41.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with default traefik ingressClass",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-bar": {
|
2019-03-14 08:30:04 +00:00
|
|
|
Rule: "PathPrefix(`/bar`)",
|
2019-09-13 18:44:04 +00:00
|
|
|
Service: "testing-service1-80",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Services: map[string]*dynamic.Service{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-service1-80": {
|
2019-08-26 08:30:05 +00:00
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2019-09-30 16:12:04 +00:00
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2019-07-10 07:26:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
2019-03-14 08:30:04 +00:00
|
|
|
{
|
2019-06-05 20:18:06 +00:00
|
|
|
URL: "http://10.10.0.1:8080",
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress without provider traefik ingressClass and unknown annotation",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with non matching provider traefik ingressClass and annotation",
|
|
|
|
ingressClass: "tchouk",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with ingressClass without annotation",
|
|
|
|
ingressClass: "tchouk",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with ingressClass without annotation",
|
|
|
|
ingressClass: "toto",
|
2019-07-10 07:26:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
2019-03-14 08:30:04 +00:00
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
2020-02-03 10:24:06 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress with wildcard host",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2020-02-18 16:34:05 +00:00
|
|
|
"testing-foobar-com-bar": {
|
2022-11-28 14:48:05 +00:00
|
|
|
Rule: "HostRegexp(`^[a-zA-Z0-9-]+\\.foobar\\.com$`) && PathPrefix(`/bar`)",
|
2020-02-03 10:24:06 +00:00
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2020-02-03 10:24:06 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
Scheme: "",
|
|
|
|
Port: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-15 17:18:03 +00:00
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with multiple ingressClasses",
|
2021-01-28 14:08:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-foo": {
|
|
|
|
Rule: "PathPrefix(`/foo`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-01-28 14:08:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-07-28 15:50:04 +00:00
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with ingressClasses filter",
|
|
|
|
ingressClass: "traefik-lb2",
|
2021-03-02 20:34:03 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-foo": {
|
|
|
|
Rule: "PathPrefix(`/foo`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-02 20:34:03 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-22 15:30:05 +00:00
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with prefix pathType",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with empty pathType",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "Path(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with exact pathType",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "Path(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with implementationSpecific pathType",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "Path(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with ingress annotation",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-22 15:30:05 +00:00
|
|
|
{
|
|
|
|
// Duplicate test case with the same fixture as the one above, but with the disableIngressClassLookup option to true.
|
|
|
|
// Showing that disabling the ingressClass discovery still allow the discovery of ingresses with ingress annotation.
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with ingress annotation",
|
|
|
|
disableIngressClassLookup: true,
|
2022-12-22 15:30:05 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with ingressClass",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-80",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-80": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-12-22 15:30:05 +00:00
|
|
|
{
|
|
|
|
// Duplicate test case with the same fixture as the one above, but with the disableIngressClassLookup option to true.
|
|
|
|
// Showing that disabling the ingressClass discovery avoid discovering Ingresses with an IngressClass.
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with ingressClass",
|
2022-12-22 15:30:05 +00:00
|
|
|
disableIngressClassLookup: true,
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-17 14:50:09 +00:00
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with named port",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-bar": {
|
|
|
|
Rule: "PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-foobar",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-foobar": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:4711",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with missing ingressClass",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-06-20 08:26:05 +00:00
|
|
|
desc: "Ingress with defaultbackend",
|
2021-03-15 10:16:04 +00:00
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"default-router": {
|
2024-05-15 08:46:04 +00:00
|
|
|
Rule: "PathPrefix(`/`)",
|
|
|
|
RuleSyntax: "v3",
|
|
|
|
Priority: math.MinInt32,
|
|
|
|
Service: "default-backend",
|
2021-03-15 10:16:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"default-backend": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-03-15 10:16:04 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.10.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-02-21 22:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-03-14 14:56:06 +00:00
|
|
|
|
2023-06-20 08:26:05 +00:00
|
|
|
clientMock := newClientMock(generateTestFilename(test.desc))
|
2022-12-22 15:30:05 +00:00
|
|
|
p := Provider{
|
|
|
|
IngressClass: test.ingressClass,
|
|
|
|
AllowEmptyServices: test.allowEmptyServices,
|
|
|
|
DisableIngressClassLookup: test.disableIngressClassLookup,
|
|
|
|
}
|
2019-02-21 22:08:05 +00:00
|
|
|
conf := p.loadConfigurationFromIngresses(context.Background(), clientMock)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, conf)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 10:54:09 +00:00
|
|
|
func TestLoadConfigurationFromIngressesWithExternalNameServices(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
ingressClass string
|
|
|
|
allowExternalNameServices bool
|
|
|
|
expected *dynamic.Configuration
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Ingress with service with externalName",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with service with externalName enabled",
|
|
|
|
allowExternalNameServices: true,
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-traefik-tchouk-bar": {
|
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-8080": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-07-13 10:54:09 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://traefik.wtf:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with IPv6 endpoints",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2022-08-04 08:22:08 +00:00
|
|
|
"testing-example-com-bar": {
|
2021-07-13 10:54:09 +00:00
|
|
|
Rule: "PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service-bar-8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service-bar-8080": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://[2001:0db8:3c4d:0015:0000:0000:1a2f:1a2b]:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-07-13 10:54:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with IPv6 endpoints externalname enabled",
|
|
|
|
allowExternalNameServices: true,
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
2022-08-04 08:22:08 +00:00
|
|
|
"testing-example-com-foo": {
|
2021-07-13 10:54:09 +00:00
|
|
|
Rule: "PathPrefix(`/foo`)",
|
|
|
|
Service: "testing-service-foo-8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service-foo-8080": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://[2001:0db8:3c4d:0015:0000:0000:1a2f:2a3b]:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
PassHostHeader: Bool(true),
|
2022-11-16 10:38:07 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
|
|
|
FlushInterval: ptypes.Duration(100 * time.Millisecond),
|
|
|
|
},
|
2021-07-13 10:54:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-02-21 22:08:05 +00:00
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
2019-03-14 14:56:06 +00:00
|
|
|
|
2023-06-20 08:26:05 +00:00
|
|
|
clientMock := newClientMock(generateTestFilename(test.desc))
|
2019-03-14 14:56:06 +00:00
|
|
|
|
2019-02-21 22:08:05 +00:00
|
|
|
p := Provider{IngressClass: test.ingressClass}
|
2021-07-13 10:54:09 +00:00
|
|
|
p.AllowExternalNameServices = test.allowExternalNameServices
|
2019-02-21 22:08:05 +00:00
|
|
|
conf := p.loadConfigurationFromIngresses(context.Background(), clientMock)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, conf)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-20 15:46:05 +00:00
|
|
|
func TestLoadConfigurationFromIngressesWithNativeLB(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2023-06-20 08:26:05 +00:00
|
|
|
desc string
|
|
|
|
ingressClass string
|
|
|
|
expected *dynamic.Configuration
|
2023-03-20 15:46:05 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Ingress with native service lb",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-traefik-tchouk-bar": {
|
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-8080": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
2023-03-21 11:00:46 +00:00
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{FlushInterval: dynamic.DefaultFlushInterval},
|
|
|
|
PassHostHeader: Bool(true),
|
2023-03-20 15:46:05 +00:00
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.0.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2023-06-20 08:26:05 +00:00
|
|
|
clientMock := newClientMock(generateTestFilename(test.desc))
|
2023-03-20 15:46:05 +00:00
|
|
|
|
|
|
|
p := Provider{IngressClass: test.ingressClass}
|
|
|
|
conf := p.loadConfigurationFromIngresses(context.Background(), clientMock)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, conf)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-27 09:54:04 +00:00
|
|
|
func TestLoadConfigurationFromIngressesWithNodePortLB(t *testing.T) {
|
|
|
|
testCases := []struct {
|
2024-08-01 13:50:04 +00:00
|
|
|
desc string
|
|
|
|
clusterScopeDisabled bool
|
|
|
|
expected *dynamic.Configuration
|
2024-02-27 09:54:04 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Ingress with node port lb",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-traefik-tchouk-bar": {
|
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-8080": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{FlushInterval: dynamic.DefaultFlushInterval},
|
|
|
|
PassHostHeader: Bool(true),
|
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://172.16.4.4:32456",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-08-01 13:50:04 +00:00
|
|
|
{
|
|
|
|
desc: "Ingress with node port lb cluster scope disabled",
|
|
|
|
clusterScopeDisabled: true,
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{},
|
|
|
|
Services: map[string]*dynamic.Service{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-02-27 09:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clientMock := newClientMock(generateTestFilename(test.desc))
|
|
|
|
|
2024-08-01 13:50:04 +00:00
|
|
|
p := Provider{DisableClusterScopeResources: test.clusterScopeDisabled}
|
2024-02-27 09:54:04 +00:00
|
|
|
conf := p.loadConfigurationFromIngresses(context.Background(), clientMock)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, conf)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-20 08:26:05 +00:00
|
|
|
func generateTestFilename(desc string) string {
|
|
|
|
return filepath.Join("fixtures", strings.ReplaceAll(desc, " ", "-")+".yml")
|
2019-03-14 14:56:06 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 14:48:06 +00:00
|
|
|
func TestGetCertificates(t *testing.T) {
|
2019-02-21 22:08:05 +00:00
|
|
|
testIngressWithoutHostname := buildIngress(
|
|
|
|
iNamespace("testing"),
|
|
|
|
iRules(
|
|
|
|
iRule(iHost("ep1.example.com")),
|
|
|
|
iRule(iHost("ep2.example.com")),
|
|
|
|
),
|
|
|
|
iTLSes(
|
|
|
|
iTLS("test-secret"),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
testIngressWithoutSecret := buildIngress(
|
|
|
|
iNamespace("testing"),
|
|
|
|
iRules(
|
|
|
|
iRule(iHost("ep1.example.com")),
|
|
|
|
),
|
|
|
|
iTLSes(
|
|
|
|
iTLS("", "foo.com"),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
2023-04-17 08:56:36 +00:00
|
|
|
ingress *netv1.Ingress
|
2019-02-21 22:08:05 +00:00
|
|
|
client Client
|
2019-06-27 21:58:03 +00:00
|
|
|
result map[string]*tls.CertAndStores
|
2019-02-21 22:08:05 +00:00
|
|
|
errResult string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "api client returns error",
|
|
|
|
ingress: testIngressWithoutHostname,
|
|
|
|
client: clientMock{
|
|
|
|
apiSecretError: errors.New("api secret error"),
|
|
|
|
},
|
|
|
|
errResult: "failed to fetch secret testing/test-secret: api secret error",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "api client doesn't find secret",
|
|
|
|
ingress: testIngressWithoutHostname,
|
|
|
|
client: clientMock{},
|
|
|
|
errResult: "secret testing/test-secret does not exist",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "entry 'tls.crt' in secret missing",
|
|
|
|
ingress: testIngressWithoutHostname,
|
|
|
|
client: clientMock{
|
|
|
|
secrets: []*corev1.Secret{
|
|
|
|
{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "test-secret",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{
|
|
|
|
"tls.key": []byte("tls-key"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errResult: "secret testing/test-secret is missing the following TLS data entries: tls.crt",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "entry 'tls.key' in secret missing",
|
|
|
|
ingress: testIngressWithoutHostname,
|
|
|
|
client: clientMock{
|
|
|
|
secrets: []*corev1.Secret{
|
|
|
|
{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "test-secret",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{
|
|
|
|
"tls.crt": []byte("tls-crt"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errResult: "secret testing/test-secret is missing the following TLS data entries: tls.key",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "secret doesn't provide any of the required fields",
|
|
|
|
ingress: testIngressWithoutHostname,
|
|
|
|
client: clientMock{
|
|
|
|
secrets: []*corev1.Secret{
|
|
|
|
{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "test-secret",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
errResult: "secret testing/test-secret is missing the following TLS data entries: tls.crt, tls.key",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "add certificates to the configuration",
|
|
|
|
ingress: buildIngress(
|
|
|
|
iNamespace("testing"),
|
|
|
|
iRules(
|
|
|
|
iRule(iHost("ep1.example.com")),
|
|
|
|
iRule(iHost("ep2.example.com")),
|
|
|
|
iRule(iHost("ep3.example.com")),
|
|
|
|
),
|
|
|
|
iTLSes(
|
|
|
|
iTLS("test-secret"),
|
|
|
|
iTLS("test-secret2"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
client: clientMock{
|
|
|
|
secrets: []*corev1.Secret{
|
|
|
|
{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "test-secret2",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{
|
|
|
|
"tls.crt": []byte("tls-crt"),
|
|
|
|
"tls.key": []byte("tls-key"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "test-secret",
|
|
|
|
Namespace: "testing",
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{
|
|
|
|
"tls.crt": []byte("tls-crt"),
|
|
|
|
"tls.key": []byte("tls-key"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2019-06-27 21:58:03 +00:00
|
|
|
result: map[string]*tls.CertAndStores{
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-test-secret": {
|
2019-06-27 21:58:03 +00:00
|
|
|
Certificate: tls.Certificate{
|
2024-01-11 16:06:06 +00:00
|
|
|
CertFile: types.FileOrContent("tls-crt"),
|
|
|
|
KeyFile: types.FileOrContent("tls-key"),
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
2019-09-13 18:44:04 +00:00
|
|
|
"testing-test-secret2": {
|
2019-06-27 21:58:03 +00:00
|
|
|
Certificate: tls.Certificate{
|
2024-01-11 16:06:06 +00:00
|
|
|
CertFile: types.FileOrContent("tls-crt"),
|
|
|
|
KeyFile: types.FileOrContent("tls-key"),
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "return nil when no secret is defined",
|
|
|
|
ingress: testIngressWithoutSecret,
|
|
|
|
client: clientMock{},
|
2019-06-27 21:58:03 +00:00
|
|
|
result: map[string]*tls.CertAndStores{},
|
2019-02-21 22:08:05 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2019-06-27 21:58:03 +00:00
|
|
|
tlsConfigs := map[string]*tls.CertAndStores{}
|
2020-01-14 14:48:06 +00:00
|
|
|
err := getCertificates(context.Background(), test.ingress, test.client, tlsConfigs)
|
2019-02-21 22:08:05 +00:00
|
|
|
|
|
|
|
if test.errResult != "" {
|
|
|
|
assert.EqualError(t, err, test.errResult)
|
|
|
|
} else {
|
2020-07-19 11:10:03 +00:00
|
|
|
assert.NoError(t, err)
|
2019-02-21 22:08:05 +00:00
|
|
|
assert.Equal(t, test.result, tlsConfigs)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2024-04-29 10:20:04 +00:00
|
|
|
|
|
|
|
func TestLoadConfigurationFromIngressesWithNativeLBByDefault(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
desc string
|
|
|
|
ingressClass string
|
|
|
|
expected *dynamic.Configuration
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
desc: "Ingress with native service lb",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"testing-traefik-tchouk-bar": {
|
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
|
|
|
Service: "testing-service1-8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"testing-service1-8080": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{FlushInterval: dynamic.DefaultFlushInterval},
|
|
|
|
PassHostHeader: Bool(true),
|
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.0.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
desc: "Ingress with native lb by default",
|
|
|
|
expected: &dynamic.Configuration{
|
|
|
|
HTTP: &dynamic.HTTPConfiguration{
|
|
|
|
Middlewares: map[string]*dynamic.Middleware{},
|
|
|
|
Routers: map[string]*dynamic.Router{
|
|
|
|
"default-global-native-lb-traefik-tchouk-bar": {
|
|
|
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
|
|
|
Service: "default-service1-8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Services: map[string]*dynamic.Service{
|
|
|
|
"default-service1-8080": {
|
|
|
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
|
|
|
ResponseForwarding: &dynamic.ResponseForwarding{FlushInterval: dynamic.DefaultFlushInterval},
|
|
|
|
PassHostHeader: Bool(true),
|
|
|
|
Servers: []dynamic.Server{
|
|
|
|
{
|
|
|
|
URL: "http://10.0.0.1:8080",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
|
|
|
t.Run(test.desc, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
clientMock := newClientMock(generateTestFilename(test.desc))
|
|
|
|
|
|
|
|
p := Provider{
|
|
|
|
IngressClass: test.ingressClass,
|
|
|
|
NativeLBByDefault: true,
|
|
|
|
}
|
|
|
|
conf := p.loadConfigurationFromIngresses(context.Background(), clientMock)
|
|
|
|
|
|
|
|
assert.Equal(t, test.expected, conf)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|