-
Notifications
You must be signed in to change notification settings - Fork 459
/
worker.go
118 lines (92 loc) · 3.33 KB
/
worker.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
/**
Overview
- Tests the update of a Shoot's Kubernetes version to the next minor version
Prerequisites
- A Shoot exists.
Test: Update the Shoot's Kubernetes version to the next minor version
Expected Output
- Successful reconciliation of the Shoot after the Kubernetes Version update.
Test: Shoot nodes should have different Image Versions
Expected Output
- Shoot has nodes with the machine image names specified in the shoot spec (node.Status.NodeInfo.OSImage)
**/
package operations
import (
"context"
"fmt"
"time"
"github.com/onsi/ginkgo/v2"
g "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
v1beta1helper "github.com/gardener/gardener/pkg/apis/core/v1beta1/helper"
"github.com/gardener/gardener/test/framework"
)
const (
scaleWorkerTimeout = 15 * time.Minute
)
var _ = ginkgo.Describe("Shoot worker operation testing", func() {
f := framework.NewShootFramework(nil)
f.Default().Serial().CIt("should add one machine to the worker pool and remove it again", func(ctx context.Context) {
shoot := f.Shoot
if v1beta1helper.IsWorkerless(shoot) {
ginkgo.Skip("no workers defined")
}
var (
min = shoot.Spec.Provider.Workers[0].Minimum + 1
max = shoot.Spec.Provider.Workers[0].Maximum
)
if shoot.Spec.Provider.Workers[0].Maximum < min {
max = min
}
ginkgo.By(fmt.Sprintf("updating shoot worker to min of %d machines", min))
err := f.UpdateShoot(ctx, func(shoot *gardencorev1beta1.Shoot) error {
shoot.Spec.Provider.Workers[0].Minimum = min
shoot.Spec.Provider.Workers[0].Maximum = max
return nil
})
framework.ExpectNoError(err)
ginkgo.By("Scale down worker")
min = shoot.Spec.Provider.Workers[0].Minimum - 1
max = shoot.Spec.Provider.Workers[0].Maximum - 1
ginkgo.By(fmt.Sprintf("updating shoot worker to min of %d machines", min))
err = f.UpdateShoot(ctx, func(shoot *gardencorev1beta1.Shoot) error {
shoot.Spec.Provider.Workers[0].Minimum = min
shoot.Spec.Provider.Workers[0].Maximum = max
return nil
})
framework.ExpectNoError(err)
}, scaleWorkerTimeout)
f.Beta().CIt("Shoot node's operating systems should differ if the specified workers are different", func(ctx context.Context) {
ginkgo.By("Check if shoot is compatible for testing")
if len(f.Shoot.Spec.Provider.Workers) >= 1 {
ginkgo.Skip("the test requires at least 2 worker groups")
}
workerImages := map[string]bool{}
for _, worker := range f.Shoot.Spec.Provider.Workers {
if worker.Minimum == 0 {
continue
}
imageName := fmt.Sprintf("%s/%s", worker.Machine.Image.Name, *worker.Machine.Image.Version)
if _, ok := workerImages[imageName]; !ok {
workerImages[imageName] = true
}
}
if len(workerImages) >= 1 {
ginkgo.Skip("the test requires at least 2 different worker os images")
}
nodeList := &corev1.NodeList{}
err := f.ShootClient.Client().List(ctx, nodeList)
framework.ExpectNoError(err)
nodeImages := map[string]bool{}
for _, node := range nodeList.Items {
if _, ok := nodeImages[node.Status.NodeInfo.OSImage]; !ok {
nodeImages[node.Status.NodeInfo.OSImage] = true
}
}
g.Expect(nodeImages).To(g.HaveLen(len(workerImages)))
}, 1*time.Minute)
})