forked from openservicemesh/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_deployment_client_server_test.go
215 lines (183 loc) · 7.03 KB
/
e2e_deployment_client_server_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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package e2e
import (
"context"
"fmt"
"sync"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/openservicemesh/osm/tests/framework"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var _ = OSMDescribe("Test HTTP traffic from N deployment client -> 1 deployment server",
OSMDescribeInfo{
Tier: 1,
Bucket: 2,
},
func() {
const (
// to name the header we will use to identify the server that replies
HTTPHeaderName = "podname"
)
var maxTestDuration = 150 * time.Second
Context("DeploymentsClientServer", func() {
var (
destApp = "server"
sourceAppBaseName = "client"
sourceNamespaces = []string{}
// Total (numberOfClientApps x replicaSetPerApp) pods
numberOfClientServices = 5
replicaSetPerService = 5
)
// Used across the test to wait for concurrent steps to finish
var wg sync.WaitGroup
for i := 0; i < numberOfClientServices; i++ {
// base names for each client service
sourceNamespaces = append(sourceNamespaces, fmt.Sprintf("%s%d", sourceAppBaseName, i))
}
It("Tests HTTP traffic from multiple client deployments to a server deployment", func() {
// Install OSM
Expect(Td.InstallOSM(Td.GetOSMInstallOpts())).To(Succeed())
// Server NS
Expect(Td.CreateNs(destApp, nil)).To(Succeed())
Expect(Td.AddNsToMesh(true, destApp)).To(Succeed())
// Client Applications
for _, srcClient := range sourceNamespaces {
Expect(Td.CreateNs(srcClient, nil)).To(Succeed())
Expect(Td.AddNsToMesh(true, srcClient)).To(Succeed())
}
// Use a deployment with multiple replicaset at serverside
svcAccDef, deploymentDef, svcDef, err := Td.SimpleDeploymentApp(
SimpleDeploymentAppDef{
DeploymentName: destApp,
Namespace: destApp,
ServiceName: destApp,
ServiceAccountName: destApp,
ReplicaCount: int32(replicaSetPerService),
Image: "simonkowallik/httpbin",
Ports: []int{DefaultUpstreamServicePort},
Command: HttpbinCmd,
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
// Expose an env variable such as XHTTPBIN_X_POD_NAME:
// This httpbin fork will pick certain env variable formats and reply the values as headers.
// We will expose pod name as one of these env variables, and will use it
// to identify the pod that replies to the request, and validate the test
deploymentDef.Spec.Template.Spec.Containers[0].Env = []v1.EnvVar{
{
Name: fmt.Sprintf("XHTTPBIN_%s", HTTPHeaderName),
ValueFrom: &v1.EnvVarSource{
FieldRef: &v1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
}
_, err = Td.CreateServiceAccount(destApp, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateDeployment(destApp, deploymentDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateService(destApp, svcDef)
Expect(err).NotTo(HaveOccurred())
wg.Add(1)
go func(wg *sync.WaitGroup, srcClient string) {
defer GinkgoRecover()
defer wg.Done()
Expect(Td.WaitForPodsRunningReady(destApp, 200*time.Second, replicaSetPerService, nil)).To(Succeed())
}(&wg, destApp)
// Create all client deployments, also with replicaset
for _, srcClient := range sourceNamespaces {
svcAccDef, deploymentDef, svcDef, err = Td.SimpleDeploymentApp(
SimpleDeploymentAppDef{
DeploymentName: srcClient,
Namespace: srcClient,
ServiceAccountName: srcClient,
ServiceName: srcClient,
ContainerName: srcClient,
ReplicaCount: int32(replicaSetPerService),
Command: []string{"/bin/bash", "-c", "--"},
Args: []string{"while true; do sleep 30; done;"},
Image: "songrgg/alpine-debug",
Ports: []int{DefaultUpstreamServicePort}, // Can't deploy services with empty/no ports
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateServiceAccount(srcClient, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateDeployment(srcClient, deploymentDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateService(srcClient, svcDef)
Expect(err).NotTo(HaveOccurred())
wg.Add(1)
go func(wg *sync.WaitGroup, srcClient string) {
defer GinkgoRecover()
defer wg.Done()
Expect(Td.WaitForPodsRunningReady(srcClient, 200*time.Second, replicaSetPerService, nil)).To(Succeed())
}(&wg, srcClient)
}
wg.Wait()
// Create traffic rules
// Deploy allow rules (10x)clients -> server
for _, srcClient := range sourceNamespaces {
httpRG, trafficTarget := Td.CreateSimpleAllowPolicy(
SimpleAllowPolicy{
RouteGroupName: srcClient,
TrafficTargetName: srcClient,
SourceNamespace: srcClient,
SourceSVCAccountName: srcClient,
DestinationNamespace: destApp,
DestinationSvcAccountName: destApp,
})
// Configs have to be put into a monitored NS, and osm-system can't be by cli
_, err = Td.CreateHTTPRouteGroup(destApp, httpRG)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateTrafficTarget(destApp, trafficTarget)
Expect(err).NotTo(HaveOccurred())
}
// Create Multiple HTTP request structure and fill it with appropriate details
requests := HTTPMultipleRequest{
Sources: []HTTPRequestDef{},
}
for _, ns := range sourceNamespaces {
pods, err := Td.Client.CoreV1().Pods(ns).List(context.Background(), metav1.ListOptions{})
Expect(err).To(BeNil())
for _, pod := range pods.Items {
requests.Sources = append(requests.Sources, HTTPRequestDef{
SourceNs: ns,
SourcePod: pod.Name,
SourceContainer: ns, // container_name == NS for this test
Destination: fmt.Sprintf("%s.%s:%d", destApp, destApp, DefaultUpstreamServicePort),
})
}
}
var results HTTPMultipleResults
var serversSeen map[string]bool = map[string]bool{} // Just counts unique servers seen
success := Td.WaitForRepeatedSuccess(func() bool {
// Issue all calls, get results
results = Td.MultipleHTTPRequest(&requests)
// Care, depending on variables there could be a lot of results
Td.PrettyPrintHTTPResults(&results)
// Verify success conditions
for _, ns := range results {
for _, podResult := range ns {
if podResult.Err != nil || podResult.StatusCode != 200 {
return false
}
// We should see pod header populated
dstPod, ok := podResult.Headers[HTTPHeaderName]
if ok {
// Store and mark that we have seen a response for this server pod
serversSeen[dstPod] = true
}
}
}
Td.T.Logf("Unique servers replied %d/%d", len(serversSeen), replicaSetPerService)
Expect(len(serversSeen)).To(Equal(replicaSetPerService))
return true
}, 5, maxTestDuration)
Expect(success).To(BeTrue())
})
})
})