Skip to content

Commit 56d8984

Browse files
Add a test that validates ingress routes
Create a new test harness to simplify sending URL requests to running routers.
1 parent 0eba27a commit 56d8984

File tree

5 files changed

+370
-14
lines changed

5 files changed

+370
-14
lines changed

Diff for: test/extended/router/metrics.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ var _ = g.Describe("[Conformance][Area:Networking][Feature:Router]", func() {
110110
o.Expect(err).NotTo(o.HaveOccurred())
111111

112112
g.By("checking for the expected metrics")
113-
routeLabels := labels{"backend": "http", "namespace": ns, "route": "weightedroute"}
114-
serverLabels := labels{"namespace": ns, "route": "weightedroute"}
113+
routeLabels := promLabels{"backend": "http", "namespace": ns, "route": "weightedroute"}
114+
serverLabels := promLabels{"namespace": ns, "route": "weightedroute"}
115115
var metrics map[string]*dto.MetricFamily
116116
times := 10
117117
p := expfmt.TextParser{}
@@ -222,10 +222,10 @@ var _ = g.Describe("[Conformance][Area:Networking][Feature:Router]", func() {
222222
})
223223
})
224224

225-
type labels map[string]string
225+
type promLabels map[string]string
226226

227-
func (l labels) With(name, value string) labels {
228-
n := make(labels)
227+
func (l promLabels) With(name, value string) promLabels {
228+
n := make(promLabels)
229229
for k, v := range l {
230230
n[k] = v
231231
}
@@ -242,48 +242,48 @@ func findEnvVar(vars []kapi.EnvVar, key string) string {
242242
return ""
243243
}
244244

245-
func findMetricsWithLabels(f *dto.MetricFamily, labels map[string]string) []*dto.Metric {
245+
func findMetricsWithLabels(f *dto.MetricFamily, promLabels map[string]string) []*dto.Metric {
246246
var result []*dto.Metric
247247
if f == nil {
248248
return result
249249
}
250250
for _, m := range f.Metric {
251251
matched := map[string]struct{}{}
252252
for _, l := range m.Label {
253-
if expect, ok := labels[l.GetName()]; ok {
253+
if expect, ok := promLabels[l.GetName()]; ok {
254254
if expect != l.GetValue() {
255255
break
256256
}
257257
matched[l.GetName()] = struct{}{}
258258
}
259259
}
260-
if len(matched) != len(labels) {
260+
if len(matched) != len(promLabels) {
261261
continue
262262
}
263263
result = append(result, m)
264264
}
265265
return result
266266
}
267267

268-
func findCountersWithLabels(f *dto.MetricFamily, labels map[string]string) []float64 {
268+
func findCountersWithLabels(f *dto.MetricFamily, promLabels map[string]string) []float64 {
269269
var result []float64
270-
for _, m := range findMetricsWithLabels(f, labels) {
270+
for _, m := range findMetricsWithLabels(f, promLabels) {
271271
result = append(result, m.Counter.GetValue())
272272
}
273273
return result
274274
}
275275

276-
func findGaugesWithLabels(f *dto.MetricFamily, labels map[string]string) []float64 {
276+
func findGaugesWithLabels(f *dto.MetricFamily, promLabels map[string]string) []float64 {
277277
var result []float64
278-
for _, m := range findMetricsWithLabels(f, labels) {
278+
for _, m := range findMetricsWithLabels(f, promLabels) {
279279
result = append(result, m.Gauge.GetValue())
280280
}
281281
return result
282282
}
283283

284-
func findMetricLabels(f *dto.MetricFamily, labels map[string]string, match string) []string {
284+
func findMetricLabels(f *dto.MetricFamily, promLabels map[string]string, match string) []string {
285285
var result []string
286-
for _, m := range findMetricsWithLabels(f, labels) {
286+
for _, m := range findMetricsWithLabels(f, promLabels) {
287287
for _, l := range m.Label {
288288
if l.GetName() == match {
289289
result = append(result, l.GetValue())

Diff for: test/extended/router/router.go

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
})

Diff for: test/extended/testdata/bindata.go

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)