Fix default-backend annotation

This commit is contained in:
Manuel de Brito Fontes 2018-05-26 19:08:07 -04:00 committed by Manuel Alejandro de Brito Fontes
parent 8f6cd56274
commit 3025e24996
3 changed files with 62 additions and 1 deletions

View file

@ -21,6 +21,7 @@ import (
"github.com/imdario/mergo" "github.com/imdario/mergo"
"k8s.io/ingress-nginx/internal/ingress/annotations/sslcipher" "k8s.io/ingress-nginx/internal/ingress/annotations/sslcipher"
apiv1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1" extensions "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -72,7 +73,7 @@ type Ingress struct {
ConfigurationSnippet string ConfigurationSnippet string
Connection connection.Config Connection connection.Config
CorsConfig cors.Config CorsConfig cors.Config
DefaultBackend string DefaultBackend *apiv1.Service
Denied error Denied error
ExternalAuth authreq.Config ExternalAuth authreq.Config
HealthCheck healthcheck.Config HealthCheck healthcheck.Config

View file

@ -451,6 +451,7 @@ func (n *NGINXController) getBackendServers(ingresses []*extensions.Ingress) ([]
loc.GRPC = anns.GRPC loc.GRPC = anns.GRPC
loc.LuaRestyWAF = anns.LuaRestyWAF loc.LuaRestyWAF = anns.LuaRestyWAF
loc.InfluxDB = anns.InfluxDB loc.InfluxDB = anns.InfluxDB
loc.DefaultBackend = anns.DefaultBackend
if loc.Redirect.FromToWWW { if loc.Redirect.FromToWWW {
server.RedirectFromToWWW = true server.RedirectFromToWWW = true
@ -488,6 +489,7 @@ func (n *NGINXController) getBackendServers(ingresses []*extensions.Ingress) ([]
GRPC: anns.GRPC, GRPC: anns.GRPC,
LuaRestyWAF: anns.LuaRestyWAF, LuaRestyWAF: anns.LuaRestyWAF,
InfluxDB: anns.InfluxDB, InfluxDB: anns.InfluxDB,
DefaultBackend: anns.DefaultBackend,
} }
if loc.Redirect.FromToWWW { if loc.Redirect.FromToWWW {

View file

@ -0,0 +1,58 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package annotations
import (
"fmt"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.IngressNginxDescribe("Annotations - custom default-backend", func() {
f := framework.NewDefaultFramework("default-backend")
BeforeEach(func() {
err := f.NewEchoDeployment()
Expect(err).NotTo(HaveOccurred())
})
Context("when default backend annotation is enabled", func() {
It("should use a custom default backend as upstream", func() {
host := "default-backend"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/default-backend": "http-svc",
}
ing, err := f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.IngressController.Namespace, "invalid", 80, &annotations))
Expect(err).NotTo(HaveOccurred())
Expect(ing).NotTo(BeNil())
time.Sleep(5 * time.Second)
err = f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(fmt.Sprintf("server_name %v", host))) &&
Expect(server).Should(ContainSubstring("proxy_pass http://custom-default-backend"))
})
Expect(err).NotTo(HaveOccurred())
})
})
})