forked from openservicemesh/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_k8s_version_test.go
122 lines (98 loc) · 3.43 KB
/
e2e_k8s_version_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
package e2e
import (
"fmt"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/openservicemesh/osm/tests/framework"
)
// This test is meant to install k8s clusters of different versions and run
// a correctness test to ensure OSM works on these versions.
var _ = OSMDescribe("Test HTTP traffic for different k8s versions",
OSMDescribeInfo{
Tier: 2,
Bucket: 6,
},
func() {
Context("Version v1.22.0", func() {
testK8sVersion("v1.22.0")
})
Context("Version v1.19.7", func() {
testK8sVersion("v1.19.7")
})
})
func testK8sVersion(version string) {
const sourceName = "client"
const destName = "server"
var ns = []string{sourceName, destName}
Td.ClusterVersion = version // set the cluster version to test
It("Tests HTTP traffic for client pod -> server pod", func() {
if Td.InstType != KindCluster {
Skip("Test is only meant to be run when installing a Kind cluster")
}
// Install OSM
Expect(Td.InstallOSM(Td.GetOSMInstallOpts())).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
svcAccDef, podDef, svcDef, err := Td.SimplePodApp(
SimplePodAppDef{
PodName: destName,
Namespace: destName,
Image: "kennethreitz/httpbin",
Ports: []int{80},
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateServiceAccount(destName, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreatePod(destName, podDef)
Expect(err).NotTo(HaveOccurred())
dstSvc, err := Td.CreateService(destName, svcDef)
Expect(err).NotTo(HaveOccurred())
// Expect it to be up and running in it's receiver namespace
Expect(Td.WaitForPodsRunningReady(destName, 90*time.Second, 1, nil)).To(Succeed())
srcPod := setupSource(sourceName, false /* no service for client */)
By("Creating SMI policies")
// Deploy allow rule client->server
httpRG, trafficTarget := Td.CreateSimpleAllowPolicy(
SimpleAllowPolicy{
RouteGroupName: "routes",
TrafficTargetName: "test-target",
SourceNamespace: sourceName,
SourceSVCAccountName: srcPod.Spec.ServiceAccountName,
DestinationNamespace: destName,
DestinationSvcAccountName: svcAccDef.Name,
})
// Configs have to be put into a monitored NS
_, err = Td.CreateHTTPRouteGroup(destName, httpRG)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateTrafficTarget(destName, trafficTarget)
Expect(err).NotTo(HaveOccurred())
// All ready. Expect client to reach server
clientToServer := HTTPRequestDef{
SourceNs: sourceName,
SourcePod: srcPod.Name,
SourceContainer: srcPod.Name,
Destination: fmt.Sprintf("%s.%s", dstSvc.Name, dstSvc.Namespace),
}
srcToDestStr := fmt.Sprintf("%s -> %s",
fmt.Sprintf("%s/%s", sourceName, srcPod.Name),
clientToServer.Destination)
cond := Td.WaitForRepeatedSuccess(func() bool {
result := Td.HTTPRequest(clientToServer)
if result.Err != nil || result.StatusCode != 200 {
Td.T.Logf("> (%s) HTTP Req failed %d %v",
srcToDestStr, result.StatusCode, result.Err)
return false
}
Td.T.Logf("> (%s) HTTP Req succeeded: %d", srcToDestStr, result.StatusCode)
return true
}, 5, 90*time.Second)
Expect(cond).To(BeTrue(), "Failed testing HTTP traffic for %s", srcToDestStr)
})
Td.ClusterVersion = "" // reset version so the default is used
}