|
| 1 | +package images |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + "time" |
| 6 | + |
| 7 | + g "github.com/onsi/ginkgo" |
| 8 | + o "github.com/onsi/gomega" |
| 9 | + |
| 10 | + kapierrs "k8s.io/apimachinery/pkg/api/errors" |
| 11 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 12 | + "k8s.io/apimachinery/pkg/labels" |
| 13 | + "k8s.io/apimachinery/pkg/util/wait" |
| 14 | + |
| 15 | + routev1 "github.com/openshift/api/route/v1" |
| 16 | + routeclientset "github.com/openshift/client-go/route/clientset/versioned" |
| 17 | + exutil "github.com/openshift/origin/test/extended/util" |
| 18 | + "github.com/openshift/origin/test/extended/util/url" |
| 19 | +) |
| 20 | + |
| 21 | +var _ = g.Describe("[Conformance][Area:Networking][Feature:Router]", func() { |
| 22 | + defer g.GinkgoRecover() |
| 23 | + var ( |
| 24 | + host, ns string |
| 25 | + oc *exutil.CLI |
| 26 | + |
| 27 | + configPath = exutil.FixturePath("testdata", "ingress.yaml") |
| 28 | + ) |
| 29 | + |
| 30 | + // this hook must be registered before the framework namespace teardown |
| 31 | + // hook |
| 32 | + g.AfterEach(func() { |
| 33 | + if g.CurrentGinkgoTestDescription().Failed { |
| 34 | + exutil.DumpPodLogsStartingWithInNamespace("router", "default", oc.AsAdmin()) |
| 35 | + selector, err := labels.Parse("router=router") |
| 36 | + if err != nil { |
| 37 | + panic(err) |
| 38 | + } |
| 39 | + exutil.DumpPodsCommand(oc.AdminKubeClient(), "default", selector, "cat /var/lib/haproxy/router/routes.json /var/lib//var/lib/haproxy/conf/haproxy.config") |
| 40 | + } |
| 41 | + }) |
| 42 | + |
| 43 | + oc = exutil.NewCLI("router-stress", exutil.KubeConfigPath()) |
| 44 | + |
| 45 | + g.BeforeEach(func() { |
| 46 | + _, err := oc.AdminAppsClient().Apps().DeploymentConfigs("default").Get("router", metav1.GetOptions{}) |
| 47 | + if kapierrs.IsNotFound(err) { |
| 48 | + g.Skip("no router installed on the cluster") |
| 49 | + return |
| 50 | + } |
| 51 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 52 | + |
| 53 | + // wait for the router endpoints to show up |
| 54 | + err = wait.PollImmediate(2*time.Second, 120*time.Second, func() (bool, error) { |
| 55 | + epts, err := oc.AdminKubeClient().CoreV1().Endpoints("default").Get("router", metav1.GetOptions{}) |
| 56 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 57 | + if len(epts.Subsets) == 0 || len(epts.Subsets[0].Addresses) == 0 { |
| 58 | + return false, nil |
| 59 | + } |
| 60 | + host = epts.Subsets[0].Addresses[0].IP |
| 61 | + return true, nil |
| 62 | + }) |
| 63 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 64 | + |
| 65 | + ns = oc.KubeFramework().Namespace.Name |
| 66 | + }) |
| 67 | + |
| 68 | + g.Describe("The HAProxy router", func() { |
| 69 | + g.It("should respond with 503 to unrecognized hosts", func() { |
| 70 | + t := url.NewTester(oc.AdminKubeClient(), ns) |
| 71 | + defer t.Close() |
| 72 | + t.Within( |
| 73 | + time.Minute, |
| 74 | + url.Expect("GET", "https://www.google.com").Through(host).SkipTLSVerification().HasStatusCode(503), |
| 75 | + url.Expect("GET", "http://www.google.com").Through(host).HasStatusCode(503), |
| 76 | + ) |
| 77 | + }) |
| 78 | + |
| 79 | + g.It("should serve routes that were created from an ingress", func() { |
| 80 | + g.By("deploying an ingress rule") |
| 81 | + err := oc.Run("create").Args("-f", configPath).Execute() |
| 82 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 83 | + |
| 84 | + g.By("waiting for the ingress rule to be converted to routes") |
| 85 | + client := routeclientset.NewForConfigOrDie(oc.AdminConfig()) |
| 86 | + var r []routev1.Route |
| 87 | + err = wait.Poll(time.Second, time.Minute, func() (bool, error) { |
| 88 | + routes, err := client.Route().Routes(ns).List(metav1.ListOptions{}) |
| 89 | + if err != nil { |
| 90 | + return false, err |
| 91 | + } |
| 92 | + r = routes.Items |
| 93 | + return len(routes.Items) == 4, nil |
| 94 | + }) |
| 95 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 96 | + |
| 97 | + g.By("verifying the router reports the correct behavior") |
| 98 | + t := url.NewTester(oc.AdminKubeClient(), ns) |
| 99 | + defer t.Close() |
| 100 | + t.Within( |
| 101 | + 3*time.Minute, |
| 102 | + url.Expect("GET", "http://1.ingress-test.com/test").Through(host).HasStatusCode(200), |
| 103 | + url.Expect("GET", "http://1.ingress-test.com/other/deep").Through(host).HasStatusCode(200), |
| 104 | + url.Expect("GET", "http://1.ingress-test.com/").Through(host).HasStatusCode(503), |
| 105 | + url.Expect("GET", "http://2.ingress-test.com/").Through(host).HasStatusCode(200), |
| 106 | + url.Expect("GET", "https://3.ingress-test.com/").Through(host).SkipTLSVerification().HasStatusCode(200), |
| 107 | + url.Expect("GET", "http://3.ingress-test.com/").Through(host).RedirectsTo("https://3.ingress-test.com/", http.StatusFound), |
| 108 | + ) |
| 109 | + }) |
| 110 | + }) |
| 111 | +}) |
0 commit comments