-
Notifications
You must be signed in to change notification settings - Fork 451
/
upgrade.go
269 lines (228 loc) · 9.66 KB
/
upgrade.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Copyright 2022 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package upgrade
import (
"context"
"os"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
e2e "github.com/gardener/gardener/test/e2e/gardener"
"github.com/gardener/gardener/test/framework"
shootupdatesuite "github.com/gardener/gardener/test/utils/shoots/update"
"github.com/gardener/gardener/test/utils/shoots/update/highavailability"
)
var _ = Describe("Gardener upgrade Tests for", func() {
var (
gardenerPreviousVersion = os.Getenv("GARDENER_PREVIOUS_VERSION")
gardenerPreviousGitVersion = os.Getenv("GARDENER_PREVIOUS_RELEASE")
gardenerCurrentVersion = os.Getenv("GARDENER_NEXT_VERSION")
gardenerCurrentGitVersion = os.Getenv("GARDENER_NEXT_RELEASE")
projectNamespace = "garden-local"
)
test_e2e_upgrade := func(shoot *gardencorev1beta1.Shoot) {
var (
parentCtx = context.Background()
job *batchv1.Job
err error
f = framework.NewShootCreationFramework(&framework.ShootCreationConfig{GardenerConfig: e2e.DefaultGardenConfig(projectNamespace)})
)
f.Shoot = shoot
f.Shoot.Namespace = projectNamespace
When("Pre-Upgrade (Gardener version:'"+gardenerPreviousVersion+"', Git version:'"+gardenerPreviousGitVersion+"')", Ordered, Offset(1), Label("pre-upgrade"), func() {
var (
ctx context.Context
cancel context.CancelFunc
)
BeforeAll(func() {
ctx, cancel = context.WithTimeout(parentCtx, 30*time.Minute)
DeferCleanup(cancel)
})
It("should create a shoot", func() {
Expect(f.CreateShootAndWaitForCreation(ctx, false)).To(Succeed())
f.Verify()
})
It("deploying zero-downtime validator job to ensure no downtime while after upgrading gardener", func() {
shootSeedNamespace := f.Shoot.Status.TechnicalID
job, err = highavailability.DeployZeroDownTimeValidatorJob(
ctx,
f.ShootFramework.SeedClient.Client(), "update", shootSeedNamespace,
shootupdatesuite.GetKubeAPIServerAuthToken(
ctx,
f.ShootFramework.SeedClient,
shootSeedNamespace,
),
)
Expect(err).NotTo(HaveOccurred())
shootupdatesuite.WaitForJobToBeReady(ctx, f.ShootFramework.SeedClient.Client(), job)
})
})
When("Post-Upgrade (Gardener version:'"+gardenerCurrentVersion+"', Git version:'"+gardenerCurrentGitVersion+"')", Ordered, Offset(1), Label("post-upgrade"), func() {
var (
ctx context.Context
cancel context.CancelFunc
seedClient client.Client
)
BeforeAll(func() {
ctx, cancel = context.WithTimeout(parentCtx, 20*time.Minute)
DeferCleanup(cancel)
Expect(f.GetShoot(ctx, f.Shoot)).To(Succeed())
f.ShootFramework, err = f.NewShootFramework(ctx, f.Shoot)
Expect(err).NotTo(HaveOccurred())
seedClient = f.ShootFramework.SeedClient.Client()
})
It("verifying no downtime while upgrading gardener", func() {
job = &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "zero-down-time-validator-update",
Namespace: f.Shoot.Status.TechnicalID,
}}
Expect(seedClient.Get(ctx, client.ObjectKeyFromObject(job), job)).To(Succeed())
Expect(job.Status.Failed).Should(BeZero())
Expect(seedClient.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationForeground))).To(Succeed())
})
It("should able to delete a shoot which was created in previous release", func() {
Expect(f.Shoot.Status.Gardener.Version).Should(Equal(gardenerPreviousVersion))
Expect(f.GardenerFramework.DeleteShootAndWaitForDeletion(ctx, f.Shoot)).To(Succeed())
})
})
}
Context("Shoot with workers::e2e-upgrade", func() {
test_e2e_upgrade(e2e.DefaultShoot("e2e-upgrade"))
})
Context("Workerless Shoot::e2e-upgrade", Label("workerless"), func() {
test_e2e_upgrade(e2e.DefaultWorkerlessShoot("e2e-upgrade"))
})
// This test will create a non-HA control plane shoot in Gardener version vX.X.X
// and then upgrades shoot's control plane to HA once successfully upgraded Gardener version to vY.Y.Y.
test_e2e_upgrade_ha := func(shoot *gardencorev1beta1.Shoot) {
var (
parentCtx = context.Background()
err error
f = framework.NewShootCreationFramework(&framework.ShootCreationConfig{GardenerConfig: e2e.DefaultGardenConfig(projectNamespace)})
)
f.Shoot = shoot
f.Shoot.Namespace = projectNamespace
f.Shoot.Spec.ControlPlane = nil
When("(Gardener version:'"+gardenerPreviousVersion+"', Git version:'"+gardenerPreviousGitVersion+"')", Ordered, Offset(1), Label("pre-upgrade"), func() {
var (
ctx context.Context
cancel context.CancelFunc
)
BeforeAll(func() {
ctx, cancel = context.WithTimeout(parentCtx, 30*time.Minute)
DeferCleanup(cancel)
})
It("should create a shoot", func() {
Expect(f.CreateShootAndWaitForCreation(ctx, false)).To(Succeed())
f.Verify()
})
})
When("Post-Upgrade (Gardener version:'"+gardenerCurrentVersion+"', Git version:'"+gardenerCurrentGitVersion+"')", Ordered, Offset(1), Label("post-upgrade"), func() {
var (
ctx context.Context
cancel context.CancelFunc
)
BeforeAll(func() {
ctx, cancel = context.WithTimeout(parentCtx, 60*time.Minute)
DeferCleanup(cancel)
Expect(f.GetShoot(ctx, f.Shoot)).To(Succeed())
f.ShootFramework, err = f.NewShootFramework(ctx, f.Shoot)
Expect(err).NotTo(HaveOccurred())
})
It("should be able to upgrade a non-HA shoot which was created in previous gardener release to HA with failure tolerance type '"+os.Getenv("SHOOT_FAILURE_TOLERANCE_TYPE")+"'", func() {
highavailability.UpgradeAndVerify(ctx, f.ShootFramework, getFailureToleranceType())
})
It("should be able to delete a shoot which was created in previous gardener release", func() {
Expect(f.Shoot.Status.Gardener.Version).Should(Equal(gardenerPreviousVersion))
Expect(f.GardenerFramework.DeleteShootAndWaitForDeletion(ctx, f.Shoot)).To(Succeed())
})
})
}
Context("Shoot with workers::e2e-upg-ha", Label("high-availability"), func() {
test_e2e_upgrade_ha(e2e.DefaultShoot("e2e-upg-ha"))
})
Context("Workerless Shoot::e2e-upg-ha", Label("high-availability", "workerless"), func() {
test_e2e_upgrade_ha(e2e.DefaultWorkerlessShoot("e2e-upg-ha"))
})
test_e2e_upgrade_hib := func(shoot *gardencorev1beta1.Shoot) {
var (
parentCtx = context.Background()
err error
f = framework.NewShootCreationFramework(&framework.ShootCreationConfig{GardenerConfig: e2e.DefaultGardenConfig(projectNamespace)})
)
f.Shoot = shoot
f.Shoot.Namespace = projectNamespace
When("Pre-upgrade (Gardener version:'"+gardenerCurrentVersion+"', Git version:'"+gardenerCurrentGitVersion+"')", Ordered, Offset(1), Label("pre-upgrade"), func() {
var (
ctx context.Context
cancel context.CancelFunc
)
BeforeAll(func() {
ctx, cancel = context.WithTimeout(parentCtx, 20*time.Minute)
DeferCleanup(cancel)
})
It("should create a shoot", func() {
Expect(f.CreateShootAndWaitForCreation(ctx, false)).To(Succeed())
f.Verify()
})
It("should hibernate a shoot", func() {
Expect(f.GetShoot(ctx, f.Shoot)).To(Succeed())
f.ShootFramework, err = f.NewShootFramework(ctx, f.Shoot)
Expect(err).NotTo(HaveOccurred())
Expect(f.HibernateShoot(ctx, f.Shoot)).To(Succeed())
})
})
When("Post-upgrade (Gardener version:'"+gardenerCurrentVersion+"', Git version:'"+gardenerCurrentGitVersion+"')", Ordered, Offset(1), Label("post-upgrade"), func() {
var (
ctx context.Context
cancel context.CancelFunc
)
BeforeAll(func() {
ctx, cancel = context.WithTimeout(parentCtx, 20*time.Minute)
DeferCleanup(cancel)
Expect(f.GetShoot(ctx, f.Shoot)).To(Succeed())
})
It("should be able to wake up a shoot which was hibernated in previous gardener release", func() {
Expect(f.Shoot.Status.Gardener.Version).Should(Equal(gardenerPreviousVersion))
Expect(f.WakeUpShoot(ctx, f.Shoot)).To(Succeed())
})
It("should delete a shoot which was created in previous gardener release", func() {
Expect(f.Shoot.Status.Gardener.Version).Should(Equal(gardenerCurrentVersion))
Expect(f.DeleteShootAndWaitForDeletion(ctx, f.Shoot)).To(Succeed())
})
})
}
Context("Shoot with workers::e2e-upg-hib", func() {
test_e2e_upgrade_hib(e2e.DefaultShoot("e2e-upg-hib"))
})
Context("Workerless Shoot::e2e-upg-hib", Label("workerless"), func() {
test_e2e_upgrade_hib(e2e.DefaultWorkerlessShoot("e2e-upg-hib"))
})
})
// getFailureToleranceType returns a failureToleranceType based on env variable SHOOT_FAILURE_TOLERANCE_TYPE value
func getFailureToleranceType() gardencorev1beta1.FailureToleranceType {
var failureToleranceType gardencorev1beta1.FailureToleranceType
switch os.Getenv("SHOOT_FAILURE_TOLERANCE_TYPE") {
case "zone":
failureToleranceType = gardencorev1beta1.FailureToleranceTypeZone
case "node":
failureToleranceType = gardencorev1beta1.FailureToleranceTypeNode
}
return failureToleranceType
}