Skip to content

Commit

Permalink
fix: allowemptyservice issue#9423
Browse files Browse the repository at this point in the history
  • Loading branch information
jerome-guiard-20230331 committed Oct 10, 2022
1 parent 39b0077 commit f79440e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
31 changes: 31 additions & 0 deletions pkg/provider/kubernetes/crd/fixtures/with_empty_services_ts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: test.route
namespace: default

spec:
entryPoints:
- foo

routes:
- match: Host(`foo.com`) && PathPrefix(`/bar`)
kind: Rule
priority: 12
services:
- name: tr-svc-es
kind: TraefikService

---
apiVersion: traefik.containo.us/v1alpha1
kind: TraefikService
metadata:
name: tr-svc-es
namespace: default

spec:
weighted:
services:
- name: whoami-without-endpoints-subsets
weight: 1
port: 80
8 changes: 6 additions & 2 deletions pkg/provider/kubernetes/crd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.
logger.Warn("ExternalName service loading is enabled, please ensure that this is expected (see AllowExternalNameServices option)")
}

if p.AllowEmptyServices {
logger.Warn("EmptyService service loading is enabled (see AllowEmptyServices option)")
}

pool.GoCtx(func(ctxPool context.Context) {
operation := func() error {
eventsChan, err := k8sClient.WatchAll(p.Namespaces, ctxPool.Done())
Expand Down Expand Up @@ -292,7 +296,7 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client)
}
}

cb := configBuilder{client: client, allowCrossNamespace: p.AllowCrossNamespace, allowExternalNameServices: p.AllowExternalNameServices}
cb := configBuilder{client: client, allowCrossNamespace: p.AllowCrossNamespace, allowExternalNameServices: p.AllowExternalNameServices, allowEmptyServices: p.AllowEmptyServices}

for _, service := range client.GetTraefikServices() {
err := cb.buildTraefikService(ctx, service, conf.HTTP.Services)
Expand Down Expand Up @@ -578,7 +582,7 @@ func (p *Provider) createErrorPageMiddleware(client Client, namespace string, er
Query: errorPage.Query,
}

balancerServerHTTP, err := configBuilder{client: client, allowCrossNamespace: p.AllowCrossNamespace, allowExternalNameServices: p.AllowExternalNameServices}.buildServersLB(namespace, errorPage.Service.LoadBalancerSpec)
balancerServerHTTP, err := configBuilder{client: client, allowCrossNamespace: p.AllowCrossNamespace, allowExternalNameServices: p.AllowExternalNameServices, allowEmptyServices: p.AllowEmptyServices}.buildServersLB(namespace, errorPage.Service.LoadBalancerSpec)
if err != nil {
return nil, nil, err
}
Expand Down
46 changes: 46 additions & 0 deletions pkg/provider/kubernetes/crd/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4037,6 +4037,52 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{},
},
},
{
desc: "TraefikService, empty service allowed",
allowEmptyServices: true,
paths: []string{"services.yml", "with_empty_services_ts.yml"},
expected: &dynamic.Configuration{
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"default-test-route-6b204d94623b3df4370c": {
EntryPoints: []string{"foo"},
Service: "default-tr-svc-es",
Rule: "Host(`foo.com`) && PathPrefix(`/bar`)",
Priority: 12,
},
},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"default-tr-svc-es": {
Weighted: &dynamic.WeightedRoundRobin{
Services: []dynamic.WRRService{
{
Name: "default-whoami-without-endpoints-subsets-80",
Weight: func(i int) *int { return &i }(1),
},
},
},
},
"default-whoami-without-endpoints-subsets-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: Bool(true),
},
},
},
ServersTransports: map[string]*dynamic.ServersTransport{},
},
TLS: &dynamic.TLSConfiguration{},
},
},
}

for _, test := range testCases {
Expand Down

0 comments on commit f79440e

Please sign in to comment.