diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index a29b0b14b..3f9aab8ee 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -224,6 +224,10 @@ func (n *NGINXController) CheckIngress(ing *networking.Ingress) error { return nil } + if n.cfg.DisableCatchAll && ing.Spec.Backend != nil { + return fmt.Errorf("This deployment is trying to create a catch-all ingress while DisableCatchAll flag is set to true. Remove '.spec.backend' or set DisableCatchAll flag to false.") + } + if parser.AnnotationsPrefix != parser.DefaultAnnotationsPrefix { for key := range ing.ObjectMeta.GetAnnotations() { if strings.HasPrefix(key, fmt.Sprintf("%s/", parser.DefaultAnnotationsPrefix)) { diff --git a/internal/ingress/controller/controller_test.go b/internal/ingress/controller/controller_test.go index 1542c7abb..c5b29ba8c 100644 --- a/internal/ingress/controller/controller_test.go +++ b/internal/ingress/controller/controller_test.go @@ -256,6 +256,28 @@ func TestCheckIngress(t *testing.T) { } }) + t.Run("When a new catch-all ingress is being created despite catch-alls being disabled ", func(t *testing.T) { + nginx.command = testNginxTestCommand{ + t: t, + err: nil, + } + nginx.cfg.DisableCatchAll = true + + ing.Spec.Backend = &networking.IngressBackend{ + ServiceName: "http-svc", + ServicePort: intstr.IntOrString{ + IntVal: 80, + }, + } + + if nginx.CheckIngress(ing) == nil { + t.Errorf("with a new catch-all ingress and catch-alls disable, should return error") + } + + // set back to nil for next test + ing.Spec.Backend = nil + }) + t.Run("When the ingress is in a different namespace than the watched one", func(t *testing.T) { nginx.command = testNginxTestCommand{ t: t,