2018-05-26 23:08:07 +00:00
|
|
|
/*
|
|
|
|
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"
|
2018-07-27 03:04:31 +00:00
|
|
|
"net/http"
|
2018-05-26 23:08:07 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-07-27 03:04:31 +00:00
|
|
|
"github.com/parnurzeal/gorequest"
|
2018-05-26 23:08:07 +00:00
|
|
|
|
|
|
|
"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 {
|
2018-07-27 03:04:31 +00:00
|
|
|
return Expect(server).Should(ContainSubstring(fmt.Sprintf("server_name %v", host)))
|
2018-05-26 23:08:07 +00:00
|
|
|
})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2018-07-27 03:04:31 +00:00
|
|
|
|
|
|
|
uri := "/alma/armud"
|
|
|
|
resp, body, errs := gorequest.New().
|
|
|
|
Get(f.IngressController.HTTPURL+uri).
|
|
|
|
Set("Host", host).
|
|
|
|
End()
|
|
|
|
|
|
|
|
Expect(len(errs)).Should(BeNumerically("==", 0))
|
|
|
|
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
|
|
|
|
|
|
|
Expect(body).To(ContainSubstring("x-code=503"))
|
|
|
|
Expect(body).To(ContainSubstring(fmt.Sprintf("x-ingress-name=%s", host)))
|
|
|
|
Expect(body).To(ContainSubstring("x-service-name=invalid"))
|
|
|
|
Expect(body).To(ContainSubstring(fmt.Sprintf("x-original-uri=%s", uri)))
|
2018-05-26 23:08:07 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|