@@ -25,11 +25,13 @@ import (
25
25
26
26
machinev1 "github.com/openshift/api/machine/v1beta1"
27
27
machinev1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/machine/v1beta1"
28
- testutils "github.com/openshift/machine-api-operator/pkg/util/testing"
29
28
29
+ "github.com/openshift/cluster-control-plane-machine-set-operator/test/e2e/framework"
30
+ testutils "github.com/openshift/machine-api-operator/pkg/util/testing"
30
31
corev1 "k8s.io/api/core/v1"
31
32
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32
33
"sigs.k8s.io/controller-runtime/pkg/client"
34
+ "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
33
35
"sigs.k8s.io/controller-runtime/pkg/manager"
34
36
35
37
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
@@ -38,6 +40,7 @@ import (
38
40
var _ = Describe ("MachineSet Reconciler" , func () {
39
41
var mgrCtxCancel context.CancelFunc
40
42
var mgrStopped chan struct {}
43
+ var k komega.Komega
41
44
var namespace * corev1.Namespace
42
45
var machineSetBuilder machinev1resourcebuilder.MachineSetBuilder
43
46
var replicas int32 = int32 (2 )
@@ -52,6 +55,7 @@ var _ = Describe("MachineSet Reconciler", func() {
52
55
Expect (err ).NotTo (HaveOccurred ())
53
56
54
57
k8sClient = mgr .GetClient ()
58
+ k = komega .New (k8sClient )
55
59
56
60
By ("Setting up feature gates" )
57
61
gate , err := testutils .NewDefaultMutableFeatureGate ()
@@ -105,6 +109,11 @@ var _ = Describe("MachineSet Reconciler", func() {
105
109
By ("Creating the MachineSet" )
106
110
Expect (k8sClient .Create (ctx , instance )).To (Succeed ())
107
111
112
+ By ("Setting the AuthoritativeAPI to MachineAPI" )
113
+ Eventually (k .UpdateStatus (instance , func () {
114
+ instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityMachineAPI
115
+ })).Should (Succeed ())
116
+
108
117
machines := & machinev1.MachineList {}
109
118
By ("Verifying that we have 2 replicas" )
110
119
Eventually (func () (int , error ) {
@@ -133,6 +142,96 @@ var _ = Describe("MachineSet Reconciler", func() {
133
142
return ready , nil
134
143
}, timeout * 3 ).Should (BeEquivalentTo (replicas ))
135
144
})
145
+
146
+ It ("Should set the Paused condition appropriately" , func () {
147
+ instance := machineSetBuilder .
148
+ WithName ("baz" ).
149
+ WithLabels (map [string ]string {"baz" : "bar" }).
150
+ Build ()
151
+
152
+ By ("Creating the MachineSet" )
153
+ Expect (k8sClient .Create (ctx , instance )).To (Succeed ())
154
+
155
+ By ("Setting the AuthoritativeAPI to ClusterAPI" )
156
+ Eventually (k .UpdateStatus (instance , func () {
157
+ instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityClusterAPI
158
+ })).Should (Succeed ())
159
+
160
+ By ("Verifying that the AuthoritativeAPI is set to Cluster API" )
161
+ Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.AuthoritativeAPI" , Equal (machinev1 .MachineAuthorityClusterAPI )))
162
+
163
+ By ("Verifying the paused condition is approproately set to true" )
164
+ Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
165
+ HaveField ("Type" , Equal (PausedCondition )),
166
+ HaveField ("Status" , Equal (corev1 .ConditionTrue )),
167
+ ))))
168
+
169
+ // The condition should remain true whilst transitioning through 'Migrating'
170
+ // Run this in a goroutine so we don't block
171
+
172
+ // Copy the instance before starting the goroutine, to avoid data races
173
+ instanceCopy := instance .DeepCopy ()
174
+ go func () {
175
+ defer GinkgoRecover ()
176
+ framework .RunCheckUntil (
177
+ ctx ,
178
+ // Check that we consistently have the Paused condition true
179
+ func (_ context.Context , g framework.GomegaAssertions ) bool {
180
+ By ("Checking that the paused condition is consistently true whilst migrating to MachineAPI" )
181
+
182
+ localInstance := instanceCopy .DeepCopy ()
183
+ if err := k8sClient .Get (ctx , client .ObjectKeyFromObject (localInstance ), localInstance ); err != nil {
184
+ return g .Expect (err ).Should (WithTransform (testutils .IsRetryableAPIError , BeTrue ()), "expected temporary error while getting machine: %v" , err )
185
+ }
186
+
187
+ return g .Expect (localInstance .Status .Conditions ).Should (ContainElement (SatisfyAll (
188
+ HaveField ("Type" , Equal (PausedCondition )),
189
+ HaveField ("Status" , Equal (corev1 .ConditionTrue )),
190
+ )))
191
+
192
+ },
193
+ // Condition / until function: until we observe the MachineAuthority being MAPI
194
+ func (_ context.Context , g framework.GomegaAssertions ) bool {
195
+ By ("Checking that the AuthoritativeAPI is not MachineAPI" )
196
+
197
+ localInstance := instanceCopy .DeepCopy ()
198
+ if err := k8sClient .Get (ctx , client .ObjectKeyFromObject (localInstance ), localInstance ); err != nil {
199
+ return g .Expect (err ).Should (WithTransform (testutils .IsRetryableAPIError , BeTrue ()), "expected temporary error while getting machine: %v" , err )
200
+ }
201
+
202
+ return g .Expect (localInstance .Status .AuthoritativeAPI ).To (Equal (machinev1 .MachineAuthorityMachineAPI ))
203
+ })
204
+ }()
205
+
206
+ By ("Transitioning the AuthoritativeAPI though Migrating" )
207
+ Eventually (k .UpdateStatus (instance , func () {
208
+ instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityMigrating
209
+ })).Should (Succeed ())
210
+
211
+ By ("Updating the AuthoritativeAPI from Migrating to MachineAPI" )
212
+ Eventually (k .UpdateStatus (instance , func () {
213
+ instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityMachineAPI
214
+ })).Should (Succeed ())
215
+
216
+ Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.AuthoritativeAPI" , Equal (machinev1 .MachineAuthorityMachineAPI )))
217
+
218
+ By ("Verifying the paused condition is approproately set to false" )
219
+ Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
220
+ HaveField ("Type" , Equal (PausedCondition )),
221
+ HaveField ("Status" , Equal (corev1 .ConditionFalse )),
222
+ ))))
223
+
224
+ By ("Unsetting the AuthoritativeAPI field in the status" )
225
+ Eventually (k .UpdateStatus (instance , func () {
226
+ instance .Status .AuthoritativeAPI = ""
227
+ })).Should (Succeed ())
228
+
229
+ By ("Verifying the paused condition is still approproately set to false" )
230
+ Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
231
+ HaveField ("Type" , Equal (PausedCondition )),
232
+ HaveField ("Status" , Equal (corev1 .ConditionFalse )),
233
+ ))))
234
+ })
136
235
})
137
236
138
237
func cleanResources (namespace string ) error {
0 commit comments