k8s Ingress: fix crash on rules with nil http
This commit is contained in:
parent
49356cadd4
commit
bd676922c3
3 changed files with 56 additions and 32 deletions
|
@ -0,0 +1,9 @@
|
||||||
|
kind: Ingress
|
||||||
|
apiVersion: extensions/v1beta1
|
||||||
|
metadata:
|
||||||
|
name: ""
|
||||||
|
namespace: testing
|
||||||
|
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: testing.example.com
|
|
@ -313,12 +313,14 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
conf.HTTP.Services["default-backend"] = service
|
conf.HTTP.Services["default-backend"] = service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rule := range ingress.Spec.Rules {
|
for _, rule := range ingress.Spec.Rules {
|
||||||
if err := checkStringQuoteValidity(rule.Host); err != nil {
|
if err := checkStringQuoteValidity(rule.Host); err != nil {
|
||||||
log.FromContext(ctx).Errorf("Invalid syntax for host: %s", rule.Host)
|
log.FromContext(ctx).Errorf("Invalid syntax for host: %s", rule.Host)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rule.HTTP != nil {
|
||||||
for _, p := range rule.HTTP.Paths {
|
for _, p := range rule.HTTP.Paths {
|
||||||
service, err := loadService(client, ingress.Namespace, p.Backend)
|
service, err := loadService(client, ingress.Namespace, p.Backend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -360,6 +362,8 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
}
|
}
|
||||||
conf.HTTP.Services[serviceName] = service
|
conf.HTTP.Services[serviceName] = service
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err := p.updateIngressStatus(ingress, client)
|
err := p.updateIngressStatus(ingress, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FromContext(ctx).Errorf("Error while updating ingress status: %v", err)
|
log.FromContext(ctx).Errorf("Error while updating ingress status: %v", err)
|
||||||
|
|
|
@ -38,6 +38,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "Ingress one rule host only",
|
||||||
|
expected: &dynamic.Configuration{
|
||||||
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
|
Routers: map[string]*dynamic.Router{},
|
||||||
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
|
Services: map[string]*dynamic.Service{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with a basic rule on one path",
|
desc: "Ingress with a basic rule on one path",
|
||||||
expected: &dynamic.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
|
|
Loading…
Reference in a new issue