Fix panic for empty defaultBackend and defaultBackend without resources
This commit is contained in:
parent
be27044099
commit
5d00096f82
4 changed files with 51 additions and 0 deletions
|
|
@ -0,0 +1,12 @@
|
|||
kind: Ingress
|
||||
apiVersion: networking.k8s.io/v1
|
||||
metadata:
|
||||
name: defaultbackend
|
||||
namespace: testing
|
||||
|
||||
spec:
|
||||
defaultBackend:
|
||||
resource:
|
||||
apiGroup: example.com
|
||||
kind: SomeBackend
|
||||
name: foo
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
kind: Ingress
|
||||
apiVersion: networking.k8s.io/v1
|
||||
metadata:
|
||||
name: defaultbackend
|
||||
namespace: testing
|
||||
|
||||
spec:
|
||||
defaultBackend: {}
|
||||
|
|
@ -269,6 +269,17 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
|||
continue
|
||||
}
|
||||
|
||||
if ingress.Spec.DefaultBackend.Resource != nil {
|
||||
// https://kubernetes.io/docs/concepts/services-networking/ingress/#resource-backend
|
||||
logger.Error().Msg("Resource is not supported for default backend")
|
||||
continue
|
||||
}
|
||||
|
||||
if ingress.Spec.DefaultBackend.Service == nil {
|
||||
logger.Error().Msg("Default backend is missing service definition")
|
||||
continue
|
||||
}
|
||||
|
||||
service, err := p.loadService(client, ingress.Namespace, *ingress.Spec.DefaultBackend)
|
||||
if err != nil {
|
||||
logger.Error().
|
||||
|
|
|
|||
|
|
@ -550,6 +550,26 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "Ingress with defaultbackend with resource",
|
||||
expected: &dynamic.Configuration{
|
||||
HTTP: &dynamic.HTTPConfiguration{
|
||||
Middlewares: map[string]*dynamic.Middleware{},
|
||||
Routers: map[string]*dynamic.Router{},
|
||||
Services: map[string]*dynamic.Service{},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "Ingress with empty defaultbackend",
|
||||
expected: &dynamic.Configuration{
|
||||
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",
|
||||
expected: &dynamic.Configuration{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue