forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
reencrypt.go
102 lines (86 loc) · 3.13 KB
/
reencrypt.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"
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
kapierrs "k8s.io/apimachinery/pkg/api/errors"
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", "reencrypt-serving-cert.yaml")
oc *exutil.CLI
ip, 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.DumpPodLogsStartingWithInNamespace("router", "default", oc.AsAdmin())
}
})
oc = exutil.NewCLI("router-reencrypt", exutil.KubeConfigPath())
g.BeforeEach(func() {
var err error
ip, err = waitForRouterServiceIP(oc)
if kapierrs.IsNotFound(err) {
g.Skip("no router installed on the cluster")
return
}
o.Expect(err).NotTo(o.HaveOccurred())
ns = oc.KubeFramework().Namespace.Name
})
g.Describe("The HAProxy router", func() {
g.It("should support reencrypt to services backed by a serving certificate automatically", func() {
routerURL := fmt.Sprintf("https://%s", ip)
execPodName := exutil.CreateExecPodOrFail(oc.AdminKubeClient().Core(), ns, "execpod")
defer func() { oc.AdminKubeClient().Core().Pods(ns).Delete(execPodName, metav1.NewDeleteOptions(1)) }()
g.By(fmt.Sprintf("deploying a service using a reencrypt route without a destinationCACertificate"))
err := oc.Run("create").Args("-f", configPath).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
var hostname string
err = wait.Poll(time.Second, changeTimeoutSeconds*time.Second, func() (bool, error) {
route, err := oc.RouteClient().Route().Routes(ns).Get("serving-cert", metav1.GetOptions{})
if err != nil {
return false, err
}
if len(route.Status.Ingress) == 0 || len(route.Status.Ingress[0].Host) == 0 {
return false, nil
}
hostname = route.Status.Ingress[0].Host
return true, nil
})
o.Expect(err).NotTo(o.HaveOccurred())
// don't assume the router is available via external DNS, because of complexity
err = waitForRouterOKResponseExec(ns, execPodName, routerURL, hostname, changeTimeoutSeconds)
o.Expect(err).NotTo(o.HaveOccurred())
})
})
})
func waitForRouterServiceIP(oc *exutil.CLI) (string, error) {
_, ns, err := exutil.GetRouterPodTemplate(oc)
if err != nil {
return "", err
}
// wait for the service to show up
var host string
err = wait.PollImmediate(2*time.Second, 60*time.Second, func() (bool, error) {
svc, err := oc.AdminKubeClient().CoreV1().Services(ns).Get("router", metav1.GetOptions{})
if kapierrs.IsNotFound(err) {
return false, nil
}
o.Expect(err).NotTo(o.HaveOccurred())
host = svc.Spec.ClusterIP
return true, nil
})
return host, err
}