forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unprivileged.go
102 lines (83 loc) · 3.51 KB
/
unprivileged.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package router
import (
"fmt"
"net/http"
"strings"
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
routeclientset "github.com/openshift/client-go/route/clientset/versioned"
exutil "github.com/openshift/origin/test/extended/util"
)
var _ = g.Describe("[Conformance][Area:Networking][Feature:Router]", func() {
defer g.GinkgoRecover()
var (
configPath = exutil.FixturePath("testdata", "scoped-router.yaml")
oc *exutil.CLI
ns string
)
// this hook must be registered before the framework namespace teardown
// hook
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed {
client := routeclientset.NewForConfigOrDie(oc.AdminConfig()).Route().Routes(ns)
if routes, _ := client.List(metav1.ListOptions{}); routes != nil {
outputIngress(routes.Items...)
}
exutil.DumpPodLogsStartingWith("unprivileged-router", oc)
}
})
oc = exutil.NewCLI("unprivileged-router", exutil.KubeConfigPath())
g.BeforeEach(func() {
ns = oc.Namespace()
routerImage, _ := exutil.FindImageFormatString(oc)
routerImage = strings.Replace(routerImage, "${component}", "haproxy-router", -1)
err := oc.AsAdmin().Run("new-app").Args("-f", configPath,
`-p=IMAGE=`+routerImage,
`-p=SCOPE=["--name=test-unprivileged", "--namespace=$(POD_NAMESPACE)", "--loglevel=4", "--labels=select=first", "--update-status=false"]`,
).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
})
g.Describe("The HAProxy router", func() {
g.It("should run even if it has no access to update status", func() {
ns := oc.KubeFramework().Namespace.Name
execPodName := exutil.CreateExecPodOrFail(oc.AdminKubeClient().CoreV1(), ns, "execpod")
defer func() { oc.AdminKubeClient().CoreV1().Pods(ns).Delete(execPodName, metav1.NewDeleteOptions(1)) }()
g.By(fmt.Sprintf("creating a scoped router from a config file %q", configPath))
var routerIP string
err := wait.Poll(time.Second, changeTimeoutSeconds*time.Second, func() (bool, error) {
pod, err := oc.KubeFramework().ClientSet.CoreV1().Pods(oc.KubeFramework().Namespace.Name).Get("router-scoped", metav1.GetOptions{})
if err != nil {
return false, err
}
if len(pod.Status.PodIP) == 0 {
return false, nil
}
routerIP = pod.Status.PodIP
return true, nil
})
o.Expect(err).NotTo(o.HaveOccurred())
// router expected to listen on port 80
routerURL := fmt.Sprintf("http://%s", routerIP)
g.By("waiting for the healthz endpoint to respond")
healthzURI := fmt.Sprintf("http://%s:1936/healthz", routerIP)
err = waitForRouterOKResponseExec(ns, execPodName, healthzURI, routerIP, changeTimeoutSeconds)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for the valid route to respond")
err = waitForRouterOKResponseExec(ns, execPodName, routerURL+"/Letter", "FIRST.example.com", changeTimeoutSeconds)
o.Expect(err).NotTo(o.HaveOccurred())
for _, host := range []string{"second.example.com", "third.example.com"} {
g.By(fmt.Sprintf("checking that %s does not match a route", host))
err = expectRouteStatusCodeExec(ns, execPodName, routerURL+"/Letter", host, http.StatusServiceUnavailable)
o.Expect(err).NotTo(o.HaveOccurred())
}
g.By("checking that the route doesn't have an ingress status")
r, err := oc.RouteClient().Route().Routes(ns).Get("route-1", metav1.GetOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
ingress := ingressForName(r, "test-unprivileged")
o.Expect(ingress).To(o.BeNil())
})
})
})