2018-09-25 03:33:13 +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 defaultbackend
|
|
|
|
|
|
|
|
import (
|
2019-09-01 18:16:52 +00:00
|
|
|
"fmt"
|
2018-09-25 03:33:13 +00:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
2020-01-05 14:15:38 +00:00
|
|
|
"time"
|
2018-09-25 03:33:13 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2018-10-29 21:39:04 +00:00
|
|
|
|
2018-09-25 03:33:13 +00:00
|
|
|
"github.com/parnurzeal/gorequest"
|
|
|
|
|
2019-05-08 00:21:13 +00:00
|
|
|
appsv1 "k8s.io/api/apps/v1"
|
2018-09-25 03:33:13 +00:00
|
|
|
|
|
|
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
|
|
|
)
|
|
|
|
|
2019-04-10 00:24:45 +00:00
|
|
|
var _ = framework.IngressNginxDescribe("Custom Default Backend", func() {
|
2018-09-25 03:33:13 +00:00
|
|
|
f := framework.NewDefaultFramework("custom-default-backend")
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2018-10-29 21:39:04 +00:00
|
|
|
f.NewEchoDeploymentWithReplicas(1)
|
2018-09-25 03:33:13 +00:00
|
|
|
|
2020-01-05 14:15:38 +00:00
|
|
|
err := framework.UpdateDeployment(f.KubeClientSet, f.Namespace, "nginx-ingress-controller", 1,
|
2019-05-08 00:21:13 +00:00
|
|
|
func(deployment *appsv1.Deployment) error {
|
2018-09-25 03:33:13 +00:00
|
|
|
args := deployment.Spec.Template.Spec.Containers[0].Args
|
2020-01-05 14:15:38 +00:00
|
|
|
args = append(args, fmt.Sprintf("--default-backend-service=%v/%v", f.Namespace, framework.EchoService))
|
2018-09-25 03:33:13 +00:00
|
|
|
deployment.Spec.Template.Spec.Containers[0].Args = args
|
2019-05-08 00:21:13 +00:00
|
|
|
_, err := f.KubeClientSet.AppsV1().Deployments(f.Namespace).Update(deployment)
|
2018-09-25 03:33:13 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
})
|
2020-01-05 14:15:38 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
time.Sleep(1 * time.Second)
|
2018-09-25 03:33:13 +00:00
|
|
|
|
2018-10-29 21:39:04 +00:00
|
|
|
f.WaitForNginxServer("_",
|
2018-09-25 03:33:13 +00:00
|
|
|
func(server string) bool {
|
2020-01-05 14:15:38 +00:00
|
|
|
return strings.Contains(server, `set $proxy_upstream_name "upstream-default-backend"`)
|
2018-09-25 03:33:13 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
It("uses custom default backend", func() {
|
2019-02-22 14:03:42 +00:00
|
|
|
resp, _, errs := gorequest.New().Get(f.GetURL(framework.HTTP)).End()
|
2018-09-25 03:33:13 +00:00
|
|
|
Expect(errs).Should(BeEmpty())
|
|
|
|
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
|
|
|
|
})
|
|
|
|
})
|