Fix panic for ingress with backend resource
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
parent
aa5f2b92d4
commit
b669981018
4 changed files with 68 additions and 9 deletions
|
@ -0,0 +1,18 @@
|
||||||
|
kind: Ingress
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: ""
|
||||||
|
namespace: testing
|
||||||
|
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: traefik.tchouk
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /bar
|
||||||
|
backend:
|
||||||
|
resource:
|
||||||
|
kind: Service
|
||||||
|
name: service1
|
||||||
|
pathType: Prefix
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
kind: Ingress
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
metadata:
|
||||||
|
name: ""
|
||||||
|
namespace: testing
|
||||||
|
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: traefik.tchouk
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /bar
|
||||||
|
backend: {}
|
||||||
|
pathType: Prefix
|
||||||
|
|
|
@ -300,6 +300,17 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pa := range rule.HTTP.Paths {
|
for _, pa := range rule.HTTP.Paths {
|
||||||
|
if pa.Backend.Resource != nil {
|
||||||
|
// https://kubernetes.io/docs/concepts/services-networking/ingress/#resource-backend
|
||||||
|
log.FromContext(ctxIngress).Error("Resource backends are not supported")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if pa.Backend.Service == nil {
|
||||||
|
log.FromContext(ctxIngress).Error("Missing service definition")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
service, err := p.loadService(client, ingress.Namespace, pa.Backend)
|
service, err := p.loadService(client, ingress.Namespace, pa.Backend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FromContext(ctxIngress).
|
log.FromContext(ctxIngress).
|
||||||
|
@ -516,15 +527,6 @@ func getTLSConfig(tlsConfigs map[string]*tls.CertAndStores) []*tls.CertAndStores
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) loadService(client Client, namespace string, backend netv1.IngressBackend) (*dynamic.Service, error) {
|
func (p *Provider) loadService(client Client, namespace string, backend netv1.IngressBackend) (*dynamic.Service, error) {
|
||||||
if backend.Resource != nil {
|
|
||||||
// https://kubernetes.io/docs/concepts/services-networking/ingress/#resource-backend
|
|
||||||
return nil, errors.New("resource backends are not supported")
|
|
||||||
}
|
|
||||||
|
|
||||||
if backend.Service == nil {
|
|
||||||
return nil, errors.New("missing service definition")
|
|
||||||
}
|
|
||||||
|
|
||||||
service, exists, err := client.GetService(namespace, backend.Service.Name)
|
service, exists, err := client.GetService(namespace, backend.Service.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -469,6 +469,30 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "Ingress with backend resource",
|
||||||
|
allowEmptyServices: true,
|
||||||
|
expected: &dynamic.Configuration{
|
||||||
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
|
Routers: map[string]*dynamic.Router{},
|
||||||
|
Services: map[string]*dynamic.Service{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "Ingress without backend",
|
||||||
|
allowEmptyServices: true,
|
||||||
|
expected: &dynamic.Configuration{
|
||||||
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
|
Routers: map[string]*dynamic.Router{},
|
||||||
|
Services: map[string]*dynamic.Service{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with one service without endpoint",
|
desc: "Ingress with one service without endpoint",
|
||||||
expected: &dynamic.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue