forked from openservicemesh/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_upgrade_test.go
231 lines (199 loc) · 7.57 KB
/
e2e_upgrade_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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package e2e
import (
"fmt"
"os/exec"
"path/filepath"
"strconv"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/cli"
corev1 "k8s.io/api/core/v1"
. "github.com/openservicemesh/osm/tests/framework"
)
var _ = OSMDescribe("Upgrade from latest",
OSMDescribeInfo{
Tier: 2,
Bucket: 10,
},
func() {
const ns = "upgrade-test"
It("Tests upgrading the control plane", func() {
if Td.InstType == NoInstall {
Skip("test requires fresh OSM install")
}
if _, err := exec.LookPath("kubectl"); err != nil {
Td.T.Fatal("\"kubectl\" command required and not found on PATH")
}
helmCfg := &action.Configuration{}
Expect(helmCfg.Init(Td.Env.RESTClientGetter(), Td.OsmNamespace, "secret", Td.T.Logf)).To(Succeed())
helmEnv := cli.New()
// Install OSM with Helm vs. CLI so the test isn't dependent on
// multiple versions of the CLI at once.
Expect(Td.CreateNs(Td.OsmNamespace, nil)).To(Succeed())
const releaseName = "osm"
i := action.NewInstall(helmCfg)
i.ChartPathOptions.RepoURL = "https://openservicemesh.github.io/osm"
// On the main branch, this should refer to the latest release. On
// release branches, it should specify the most recent patch of the
// previous minor release. e.g. on the release-v1.0 branch, this
// should be "0.11".
i.Version = ">0.0.0-0"
i.Namespace = Td.OsmNamespace
i.Wait = true
i.ReleaseName = releaseName
i.Timeout = 120 * time.Second
vals := map[string]interface{}{
"osm": map[string]interface{}{
"deployPrometheus": true,
// Init container must be privileged if an OpenShift cluster is being used
"enablePrivilegedInitContainer": Td.DeployOnOpenShift,
// Reduce CPU so CI (capped at 2 CPU) can handle standing
// up the new control plane before tearing the old one
// down.
"osmController": map[string]interface{}{
"resource": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "0.3",
},
},
},
"injector": map[string]interface{}{
"resource": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "0.1",
},
},
},
"prometheus": map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "0.1",
"memory": "256M",
},
},
},
},
}
chartPath, err := i.LocateChart("osm", helmEnv)
Expect(err).NotTo(HaveOccurred())
ch, err := loader.Load(chartPath)
Expect(err).NotTo(HaveOccurred())
Td.T.Log("testing upgrade from chart version", ch.Metadata.Version)
_, err = i.Run(ch, vals)
Expect(err).NotTo(HaveOccurred())
// Create Test NS
Expect(Td.CreateNs(ns, nil)).To(Succeed())
Expect(Td.AddNsToMesh(true, ns)).To(Succeed())
// Get simple pod definitions for the HTTP server
serverSvcAccDef, serverPodDef, serverSvcDef, err := Td.GetOSSpecificHTTPBinPod("server", ns)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateServiceAccount(ns, &serverSvcAccDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreatePod(ns, serverPodDef)
Expect(err).NotTo(HaveOccurred())
dstSvc, err := Td.CreateService(ns, serverSvcDef)
Expect(err).NotTo(HaveOccurred())
// Get simple Pod definitions for the client
svcAccDef, srcPodDef, svcDef, err := Td.SimplePodApp(SimplePodAppDef{
PodName: "client",
Namespace: ns,
Command: []string{"sleep", "365d"},
Image: "curlimages/curl",
Ports: []int{80},
OS: Td.ClusterOS,
})
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateServiceAccount(ns, &svcAccDef)
Expect(err).NotTo(HaveOccurred())
srcPod, err := Td.CreatePod(ns, srcPodDef)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateService(ns, svcDef)
Expect(err).NotTo(HaveOccurred())
Expect(Td.WaitForPodsRunningReady(ns, 90*time.Second, 2, nil)).To(Succeed())
// Deploy allow rule client->server
httpRG, trafficTarget := Td.CreateSimpleAllowPolicy(
SimpleAllowPolicy{
RouteGroupName: "routes",
TrafficTargetName: "test-target",
SourceNamespace: ns,
SourceSVCAccountName: svcAccDef.Name,
DestinationNamespace: ns,
DestinationSvcAccountName: serverSvcAccDef.Name,
},
)
_, err = Td.CreateHTTPRouteGroup(ns, httpRG)
Expect(err).NotTo(HaveOccurred())
_, err = Td.CreateTrafficTarget(ns, trafficTarget)
Expect(err).NotTo(HaveOccurred())
// All ready. Expect client to reach server
checkClientToServerOK := func() {
By("Checking client can make requests to server")
cond := Td.WaitForRepeatedSuccess(func() bool {
result :=
Td.HTTPRequest(HTTPRequestDef{
SourceNs: srcPod.Namespace,
SourcePod: srcPod.Name,
SourceContainer: srcPod.Name,
Destination: fmt.Sprintf("%s.%s.svc.cluster.local", dstSvc.Name, dstSvc.Namespace) + "/status/200",
})
if result.Err != nil || result.StatusCode != 200 {
Td.T.Logf("> REST req failed (status: %d) %v", result.StatusCode, result.Err)
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())
}
checkProxiesConnected := func() {
By("Checking all proxies are connected")
prometheus, err := Td.GetOSMPrometheusHandle()
Expect(err).NotTo(HaveOccurred())
defer prometheus.Stop()
cond := Td.WaitForRepeatedSuccess(func() bool {
expectedProxyCount := float64(2)
proxies, err := prometheus.VectorQuery("osm_proxy_connect_count", time.Now())
if err != nil {
Td.T.Log("error querying prometheus:", err)
return false
}
if proxies != expectedProxyCount {
Td.T.Logf("expected query result %v, got %v", expectedProxyCount, proxies)
return false
}
Td.T.Log("All proxies connected")
return true
}, 5 /*success threshold*/, 30*time.Second /*timeout*/)
Expect(cond).To(BeTrue())
}
checkProxiesConnected()
checkClientToServerOK()
By("Upgrading OSM")
pullPolicy := corev1.PullAlways
if Td.InstType == KindCluster {
pullPolicy = corev1.PullIfNotPresent
Expect(Td.LoadOSMImagesIntoKind()).To(Succeed())
}
setArgs := "--set=osm.image.tag=" + Td.OsmImageTag + ",osm.image.registry=" + Td.CtrRegistryServer + ",osm.image.pullPolicy=" + string(pullPolicy) + ",osm.deployPrometheus=true,osm.enablePrivilegedInitContainer=" + strconv.FormatBool(Td.DeployOnOpenShift) + ",osm.osmController.resource.requests.cpu=0.3,osm.injector.resource.requests.cpu=0.1,osm.prometheus.resources.requests.cpu=0.1,osm.prometheus.resources.requests.memory=256M"
stdout, stderr, err := Td.RunOsmCli("mesh", "upgrade", "--osm-namespace="+Td.OsmNamespace, setArgs)
Td.T.Log(stdout.String())
if err != nil {
Td.T.Log("stderr:\n" + stderr.String())
}
Expect(err).NotTo(HaveOccurred())
// Verify that all the CRD's required by OSM are present in the cluster post an upgrade
// TODO: Find a decent way to do this without relying on the kubectl binary
// TODO: In the future when we bump the version on a CRD, we need to update this check to ensure that the version is the latest required version
stdout, stderr, err = Td.RunLocal("kubectl", "get", "-f", filepath.FromSlash("../../cmd/osm-bootstrap/crds"))
Td.T.Log(stdout.String())
if err != nil {
Td.T.Log("stderr:\n" + stderr.String())
}
Expect(err).NotTo(HaveOccurred())
checkClientToServerOK()
checkProxiesConnected()
})
})