/
rollingupdate.go
98 lines (78 loc) · 3.49 KB
/
rollingupdate.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
/*
Copyright 2022 Red Hat, Inc.
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 helpers
import (
"context"
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
machinev1 "github.com/openshift/api/machine/v1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/cluster-control-plane-machine-set-operator/test/e2e/framework"
)
// CheckRolloutForIndex first checks that a new machine is created in the correct index,
// and then checks that the new machine in the index is replaced correctly.
func CheckRolloutForIndex(testFramework framework.Framework, ctx context.Context, idx int, strategy machinev1.ControlPlaneMachineSetStrategyType) bool {
By(fmt.Sprintf("Waiting for the index %d to be replaced", idx))
// Don't provide additional timeouts here, the default should be enough.
if ok := EventuallyIndexIsBeingReplaced(ctx, testFramework, idx); !ok {
return false
}
By(fmt.Sprintf("Index %d replacement created", idx))
By(fmt.Sprintf("Checking the replacement machine for index %d", idx))
switch strategy {
case machinev1.RollingUpdate:
if ok := CheckControlPlaneMachineRollingReplacement(testFramework, idx, ctx); !ok {
return false
}
case machinev1.OnDelete:
if ok := CheckControlPlaneMachineOnDeleteReplacement(testFramework, idx, ctx); !ok {
return false
}
case machinev1.Recreate:
Fail("Recreate strategy not supported")
return false
default:
// Panic here as the test suite should never reach this point.
panic(fmt.Sprintf("unknown strategy %q", strategy))
}
By(fmt.Sprintf("Replacement for index %d is complete", idx))
return true
}
// CheckReplicasDoesNotExceedSurgeCapacity checks that, during a rolling update,
// the number of replicas within the control plane machine set never
// exceeds the desired number of replicas plus 1 additional machine for surge.
func CheckReplicasDoesNotExceedSurgeCapacity(ctx context.Context) bool {
By("Checking the number of control plane machines never goes above 4 replicas")
machineSelector := runtimeclient.MatchingLabels(framework.ControlPlaneMachineSetSelectorLabels())
// For now, we are checking that the surge is limited to just 1 instance. So 3 + 1 = 4 maximum replicas.
return Consistently(komega.ObjectList(&machinev1beta1.MachineList{}, machineSelector), ctx).Should(HaveField("Items", SatisfyAny(
HaveLen(3),
HaveLen(4),
)), "control plane machines should never go above 4 replicas, or below 3 replicas")
}
// checkRolloutProgress monitors the progress of each index in the rollout in turn.
func checkRolloutProgress(testFramework framework.Framework, ctx context.Context) bool {
if ok := CheckRolloutForIndex(testFramework, ctx, 0, machinev1.RollingUpdate); !ok {
return false
}
if ok := CheckRolloutForIndex(testFramework, ctx, 1, machinev1.RollingUpdate); !ok {
return false
}
if ok := CheckRolloutForIndex(testFramework, ctx, 2, machinev1.RollingUpdate); !ok {
return false
}
return true
}