Skip to content

Commit 048067e

Browse files
Add a test that validates ingress routes
Create a new test harness to simplify sending URL requests to running routers.
1 parent 375946d commit 048067e

File tree

7 files changed

+636
-1
lines changed

7 files changed

+636
-1
lines changed

test/extended/router/router.go

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

test/extended/testdata/bindata.go

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

test/extended/testdata/ingress.yaml

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
kind: List
2+
apiVersion: v1
3+
items:
4+
# an ingress that should be captured as three routes
5+
- apiVersion: extensions/v1beta1
6+
kind: Ingress
7+
metadata:
8+
name: test
9+
spec:
10+
tls:
11+
- hosts:
12+
- 3.ingress-test.com
13+
secretName: ingress-endpoint-secret
14+
rules:
15+
- host: 1.ingress-test.com
16+
http:
17+
paths:
18+
- path: /test
19+
backend:
20+
serviceName: ingress-endpoint-1
21+
servicePort: 80
22+
- path: /other
23+
backend:
24+
serviceName: ingress-endpoint-2
25+
servicePort: 80
26+
- host: 2.ingress-test.com
27+
http:
28+
paths:
29+
- path: /
30+
backend:
31+
serviceName: ingress-endpoint-1
32+
servicePort: 80
33+
- host: 3.ingress-test.com
34+
http:
35+
paths:
36+
- path: /
37+
backend:
38+
serviceName: ingress-endpoint-1
39+
servicePort: 80
40+
# an empty secret
41+
- apiVersion: v1
42+
kind: Secret
43+
metadata:
44+
name: ingress-endpoint-secret
45+
type: kubernetes.io/tls
46+
stringData:
47+
tls.key: ""
48+
tls.crt: ""
49+
# a service to be routed to
50+
- apiVersion: v1
51+
kind: Service
52+
metadata:
53+
name: ingress-endpoint-1
54+
spec:
55+
selector:
56+
app: ingress-endpoint-1
57+
ports:
58+
- port: 80
59+
targetPort: 8080
60+
# a service to be routed to
61+
- apiVersion: v1
62+
kind: Service
63+
metadata:
64+
name: ingress-endpoint-2
65+
spec:
66+
selector:
67+
app: ingress-endpoint-2
68+
ports:
69+
- port: 80
70+
targetPort: 8080
71+
# a pod that serves a response
72+
- apiVersion: v1
73+
kind: Pod
74+
metadata:
75+
name: ingress-endpoint-1
76+
labels:
77+
app: ingress-endpoint-1
78+
spec:
79+
terminationGracePeriodSeconds: 1
80+
containers:
81+
- name: test
82+
image: openshift/hello-openshift
83+
ports:
84+
- containerPort: 8080
85+
name: http
86+
- containerPort: 100
87+
protocol: UDP
88+
# a pod that serves a response
89+
- apiVersion: v1
90+
kind: Pod
91+
metadata:
92+
name: ingress-endpoint-2
93+
labels:
94+
app: ingress-endpoint-2
95+
spec:
96+
terminationGracePeriodSeconds: 1
97+
containers:
98+
- name: test
99+
image: openshift/hello-openshift
100+
ports:
101+
- containerPort: 8080
102+
name: http
103+
- containerPort: 100
104+
protocol: UDP

test/extended/util/cli.go

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
"k8s.io/apiserver/pkg/storage/names"
2222
kclientset "k8s.io/client-go/kubernetes"
23+
restclient "k8s.io/client-go/rest"
2324
clientcmd "k8s.io/client-go/tools/clientcmd"
2425
kinternalclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
2526
e2e "k8s.io/kubernetes/test/e2e/framework"
@@ -386,6 +387,14 @@ func (c *CLI) InternalAdminKubeClient() kinternalclientset.Interface {
386387
return kubeClient
387388
}
388389

390+
func (c *CLI) AdminConfig() *restclient.Config {
391+
_, clientConfig, err := configapi.GetExternalKubeClient(c.adminConfigPath, nil)
392+
if err != nil {
393+
FatalErr(err)
394+
}
395+
return clientConfig
396+
}
397+
389398
// Namespace returns the name of the namespace used in the current test case.
390399
// If the namespace is not set, an empty string is returned.
391400
func (c *CLI) Namespace() string {

test/extended/util/framework.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func DumpPodLogs(pods []kapiv1.Pod, oc *CLI) {
256256
}
257257

258258
dumpContainer := func(container *kapiv1.Container) {
259-
depOutput, err := oc.AsAdmin().Run("logs").Args("pod/"+pod.Name, "-c", container.Name).Output()
259+
depOutput, err := oc.AsAdmin().Run("logs").WithoutNamespace().Args("pod/"+pod.Name, "-c", container.Name, "-n", pod.Namespace).Output()
260260
if err == nil {
261261
e2e.Logf("Log for pod %q/%q\n---->\n%s\n<----end of log for %[1]q/%[2]q\n", pod.Name, container.Name, depOutput)
262262
} else {

0 commit comments

Comments
 (0)