-
Notifications
You must be signed in to change notification settings - Fork 11
/
e2e_hashivault_test.go
132 lines (112 loc) · 4.55 KB
/
e2e_hashivault_test.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package e2e
import (
"fmt"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/flomesh-io/fsm/tests/framework"
. "github.com/flomesh-io/fsm/tests/framework"
)
var _ = FSMDescribe("1 Client pod -> 1 Server pod test using Vault",
FSMDescribeInfo{
Tier: 2,
Bucket: 3,
},
func() {
Context("HashivaultSimpleClientServer", func() {
var (
clientNamespace = framework.RandomNameWithPrefix("client")
serverNamespace = framework.RandomNameWithPrefix("server")
ns = []string{clientNamespace, serverNamespace}
clientContainerName = "client-container"
)
It("Tests HTTP traffic for client pod -> server pod", func() {
// Install FSM
installOpts := Td.GetFSMInstallOpts()
installOpts.CertManager = "vault"
installOpts.SetOverrides = []string{
// increase timeout when using an external certificate provider due to
// potential slowness issuing certs
"fsm.injector.webhookTimeoutSeconds=30",
}
Expect(Td.InstallFSM(installOpts)).To(Succeed())
// Create Test NS
for _, n := range ns {
Expect(Td.CreateNs(n, nil)).To(Succeed())
Expect(Td.AddNsToMesh(true, n)).To(Succeed())
}
// Get simple pod definitions for the HTTP server
serverSvcAccDef, serverPodDef, serverSvcDef, err := Td.SimplePodApp(
SimplePodAppDef{
PodName: framework.RandomNameWithPrefix("serverpod"),
Namespace: serverNamespace,
Image: "flomesh/httpbin:ken",
Ports: []int{80},
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
serverServiceAccount, err := Td.CreateServiceAccount(serverNamespace, &serverSvcAccDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreatePod(serverNamespace, serverPodDef)
Expect(err).NotTo(HaveOccurred())
serverService, err := Td.CreateService(serverNamespace, serverSvcDef)
Expect(err).NotTo(HaveOccurred())
// Expect it to be up and running in it's receiver namespace
Expect(Td.WaitForPodsRunningReady(serverNamespace, 1, nil)).To(Succeed())
// Get simple Pod, Service, ServiceAccount definitions for the client
clientSvcAccDef, clientPodDef, clientSvcDef, err := Td.SimplePodApp(SimplePodAppDef{
PodName: framework.RandomNameWithPrefix("clientpod"),
Namespace: clientNamespace,
ContainerName: clientContainerName,
Command: []string{"/bin/bash", "-c", "--"},
Args: []string{"while true; do sleep 30; done;"},
Image: "flomesh/alpine-debug",
Ports: []int{80},
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
clientServiceAccount, err := Td.CreateServiceAccount(clientNamespace, &clientSvcAccDef)
Expect(err).NotTo(HaveOccurred())
srcPod, err := Td.CreatePod(clientNamespace, clientPodDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateService(clientNamespace, clientSvcDef)
Expect(err).NotTo(HaveOccurred())
// Expect it to be up and running in it's receiver namespace
Expect(Td.WaitForPodsRunningReady(clientNamespace, 1, nil)).To(Succeed())
// Deploy allow rule client->server
httpRG, trafficTarget := Td.CreateSimpleAllowPolicy(
SimpleAllowPolicy{
RouteGroupName: "routes",
TrafficTargetName: "test-target",
SourceNamespace: clientNamespace,
SourceSVCAccountName: clientServiceAccount.Name,
DestinationNamespace: serverNamespace,
DestinationSvcAccountName: serverServiceAccount.Name,
})
// Configs have to be put into a monitored NS, and fsm-system can't be by cli
_, err = Td.CreateHTTPRouteGroup(serverNamespace, httpRG)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateTrafficTarget(serverNamespace, trafficTarget)
Expect(err).NotTo(HaveOccurred())
// All ready. Expect client to reach server
// Need to get the pod though.
cond := Td.WaitForRepeatedSuccess(func() bool {
requestDef := HTTPRequestDef{
SourceNs: srcPod.Namespace,
SourcePod: srcPod.Name,
SourceContainer: clientContainerName,
Destination: fmt.Sprintf("%s.%s", serverService.Name, serverNamespace),
}
result :=
Td.HTTPRequest(requestDef)
if result.Err != nil || result.StatusCode != 200 {
Td.T.Logf("> REST req failed (status: %d) %v: request details: %#v", result.StatusCode, result.Err, requestDef)
return false
}
Td.T.Logf("> REST req succeeded: %d", result.StatusCode)
return true
}, 5 /*consecutive success threshold*/, 60*time.Second /*timeout*/)
Expect(cond).To(BeTrue())
})
})
})