@@ -28,9 +28,10 @@ import (
28
28
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
29
"k8s.io/utils/ptr"
30
30
31
+ testutils "github.com/openshift/cluster-api-actuator-pkg/testutils"
31
32
machinev1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/machine/v1beta1"
32
33
"github.com/openshift/cluster-control-plane-machine-set-operator/test/e2e/framework"
33
- testutils "github.com/openshift/machine-api-operator/pkg/util/testing"
34
+ "github.com/openshift/machine-api-operator/pkg/util/testing"
34
35
35
36
"sigs.k8s.io/controller-runtime/pkg/client"
36
37
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -55,11 +56,10 @@ var _ = Describe("Machine Reconciler", func() {
55
56
})
56
57
Expect (err ).NotTo (HaveOccurred ())
57
58
58
- k8sClient = mgr .GetClient ()
59
59
k = komega .New (k8sClient )
60
60
61
61
By ("Setting up feature gates" )
62
- gate , err := testutils .NewDefaultMutableFeatureGate ()
62
+ gate , err := testing .NewDefaultMutableFeatureGate ()
63
63
Expect (err ).NotTo (HaveOccurred ())
64
64
65
65
By ("Setting up a new reconciler" )
@@ -96,15 +96,15 @@ var _ = Describe("Machine Reconciler", func() {
96
96
})
97
97
98
98
AfterEach (func () {
99
- By ("Deleting the machines" )
100
- Expect (cleanResources (namespace .Name )).To (Succeed ())
101
-
102
- By ("Deleting the namespace" )
103
- Expect (k8sClient .Delete (ctx , namespace )).To (Succeed ())
104
-
105
99
By ("Closing the manager" )
106
100
mgrCtxCancel ()
107
101
Eventually (mgrStopped , timeout ).WithTimeout (20 * time .Second ).Should (BeClosed ())
102
+
103
+ By ("Cleaning up test resources" )
104
+ testutils .CleanupResources (Default , ctx , cfg , k8sClient , namespace .GetName (),
105
+ & machinev1.Machine {},
106
+ )
107
+
108
108
})
109
109
110
110
It ("Should reconcile a Machine" , func () {
@@ -127,99 +127,98 @@ var _ = Describe("Machine Reconciler", func() {
127
127
128
128
})
129
129
130
- It ("Should set the Paused condition appropriately" , func () {
131
- instance := machineBuilder .Build ()
132
-
133
- By ("Creating the Machine" )
134
- Expect (k8sClient .Create (ctx , instance )).To (Succeed ())
135
-
136
- By ("Setting the AuthoritativeAPI to ClusterAPI" )
137
- Eventually (k .UpdateStatus (instance , func () {
138
- instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityClusterAPI
139
- })).Should (Succeed ())
140
-
141
- By ("Verifying that the AuthoritativeAPI is set to Cluster API" )
142
- Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.AuthoritativeAPI" , Equal (machinev1 .MachineAuthorityClusterAPI )))
143
-
144
- By ("Verifying the paused condition is approproately set to true" )
145
- Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
146
- HaveField ("Type" , Equal (PausedCondition )),
147
- HaveField ("Status" , Equal (corev1 .ConditionTrue )),
148
- ))))
149
-
150
- // The condition should remain true whilst transitioning through 'Migrating'
151
- // Run this in a goroutine so we don't block
152
-
153
- // Copy the instance before starting the goroutine, to avoid data races
154
- instanceCopy := instance .DeepCopy ()
155
- go func () {
156
- defer GinkgoRecover ()
157
- framework .RunCheckUntil (
158
- ctx ,
159
- // Check that we consistently have the Paused condition true
160
- func (_ context.Context , g framework.GomegaAssertions ) bool {
161
- By ("Checking that the paused condition is consistently true whilst migrating to MachineAPI" )
162
-
163
- localInstance := instanceCopy .DeepCopy ()
164
- if err := k8sClient .Get (ctx , client .ObjectKeyFromObject (localInstance ), localInstance ); err != nil {
165
- return g .Expect (err ).Should (WithTransform (testutils .IsRetryableAPIError , BeTrue ()), "expected temporary error while getting machine: %v" , err )
166
- }
167
-
168
- return g .Expect (localInstance .Status .Conditions ).Should (ContainElement (SatisfyAll (
169
- HaveField ("Type" , Equal (PausedCondition )),
170
- HaveField ("Status" , Equal (corev1 .ConditionTrue )),
171
- )))
172
-
173
- },
174
- // Condition / until function: until we observe the MachineAuthority being MAPI
175
- func (_ context.Context , g framework.GomegaAssertions ) bool {
176
- By ("Checking that the AuthoritativeAPI is not MachineAPI" )
177
-
178
- localInstance := instanceCopy .DeepCopy ()
179
- if err := k8sClient .Get (ctx , client .ObjectKeyFromObject (localInstance ), localInstance ); err != nil {
180
- return g .Expect (err ).Should (WithTransform (testutils .IsRetryableAPIError , BeTrue ()), "expected temporary error while getting machine: %v" , err )
181
- }
182
-
183
- return g .Expect (localInstance .Status .AuthoritativeAPI ).To (Equal (machinev1 .MachineAuthorityMachineAPI ))
184
- })
185
- }()
186
-
187
- By ("Transitioning the AuthoritativeAPI though 'Migrating' to MachineAPI" )
188
- Eventually (k .UpdateStatus (instance , func () {
189
- instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityMigrating
190
- })).Should (Succeed ())
191
-
192
- By ("Updating the AuthoritativeAPI from Migrating to MachineAPI" )
193
- Eventually (k .UpdateStatus (instance , func () {
194
- instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityMachineAPI
195
- })).Should (Succeed ())
196
-
197
- Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.AuthoritativeAPI" , Equal (machinev1 .MachineAuthorityMachineAPI )))
198
-
199
- By ("Verifying the paused condition is approproately set to false" )
200
- Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
201
- HaveField ("Type" , Equal (PausedCondition )),
202
- HaveField ("Status" , Equal (corev1 .ConditionFalse )),
203
- ))))
204
-
205
- By ("Unsetting the AuthoritativeAPI field in the status" )
206
- Eventually (k .UpdateStatus (instance , func () {
207
- instance .Status .AuthoritativeAPI = ""
208
- })).Should (Succeed ())
130
+ Describe ("Paused condition" , func () {
131
+ var instance * machinev1.Machine
132
+ BeforeEach (func () {
133
+ instance = machineBuilder .Build ()
134
+ })
209
135
210
- By ("Verifying the paused condition is still approproately set to false" )
211
- Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
212
- HaveField ("Type" , Equal (PausedCondition )),
213
- HaveField ("Status" , Equal (corev1 .ConditionFalse )),
214
- ))))
136
+ It ("Should set the Paused condition appropriately" , func () {
137
+
138
+ By ("Creating the Machine" )
139
+ Expect (k8sClient .Create (ctx , instance )).To (Succeed ())
140
+
141
+ By ("Setting the AuthoritativeAPI to ClusterAPI" )
142
+ Eventually (k .UpdateStatus (instance , func () {
143
+ instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityClusterAPI
144
+ })).Should (Succeed ())
145
+
146
+ By ("Verifying the paused condition is approproately set to true" )
147
+ Eventually (k .Object (instance ), timeout ).Should (SatisfyAll (
148
+ HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
149
+ HaveField ("Type" , Equal (PausedCondition )),
150
+ HaveField ("Status" , Equal (corev1 .ConditionTrue )),
151
+ ))),
152
+ HaveField ("Status.AuthoritativeAPI" , Equal (machinev1 .MachineAuthorityClusterAPI )),
153
+ ))
154
+
155
+ // The condition should remain true whilst transitioning through 'Migrating'
156
+ // Run this in a goroutine so we don't block
157
+
158
+ // Copy the instance before starting the goroutine, to avoid data races
159
+ instanceCopy := instance .DeepCopy ()
160
+ go func () {
161
+ defer GinkgoRecover ()
162
+ framework .RunCheckUntil (
163
+ ctx ,
164
+ // Check that we consistently have the Paused condition true
165
+ func (_ context.Context , g framework.GomegaAssertions ) bool {
166
+ By ("Checking that the paused condition is consistently true whilst migrating to MachineAPI" )
167
+
168
+ localInstance := instanceCopy .DeepCopy ()
169
+ if err := k8sClient .Get (ctx , client .ObjectKeyFromObject (localInstance ), localInstance ); err != nil {
170
+ return g .Expect (err ).Should (WithTransform (testing .IsRetryableAPIError , BeTrue ()), "expected temporary error while getting machine: %v" , err )
171
+ }
172
+
173
+ return g .Expect (localInstance .Status .Conditions ).Should (ContainElement (SatisfyAll (
174
+ HaveField ("Type" , Equal (PausedCondition )),
175
+ HaveField ("Status" , Equal (corev1 .ConditionTrue )),
176
+ )))
177
+
178
+ },
179
+ // Condition / until function: until we observe the MachineAuthority being MAPI
180
+ func (_ context.Context , g framework.GomegaAssertions ) bool {
181
+ By ("Checking that the AuthoritativeAPI is not MachineAPI" )
182
+
183
+ localInstance := instanceCopy .DeepCopy ()
184
+ if err := k8sClient .Get (ctx , client .ObjectKeyFromObject (localInstance ), localInstance ); err != nil {
185
+ return g .Expect (err ).Should (WithTransform (testing .IsRetryableAPIError , BeTrue ()), "expected temporary error while getting machine: %v" , err )
186
+ }
187
+
188
+ return g .Expect (localInstance .Status .AuthoritativeAPI ).To (Equal (machinev1 .MachineAuthorityMachineAPI ))
189
+ })
190
+ }()
191
+
192
+ By ("Transitioning the AuthoritativeAPI though 'Migrating' to MachineAPI" )
193
+ Eventually (k .UpdateStatus (instance , func () {
194
+ instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityMigrating
195
+ })).Should (Succeed ())
196
+
197
+ By ("Updating the AuthoritativeAPI from Migrating to MachineAPI" )
198
+ Eventually (k .UpdateStatus (instance , func () {
199
+ instance .Status .AuthoritativeAPI = machinev1 .MachineAuthorityMachineAPI
200
+ })).Should (Succeed ())
201
+
202
+ By ("Verifying the paused condition is approproately set to false" )
203
+ Eventually (k .Object (instance ), timeout ).Should (SatisfyAll (
204
+ HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
205
+ HaveField ("Type" , Equal (PausedCondition )),
206
+ HaveField ("Status" , Equal (corev1 .ConditionFalse )),
207
+ ))),
208
+ HaveField ("Status.AuthoritativeAPI" , Equal (machinev1 .MachineAuthorityMachineAPI )),
209
+ ))
210
+
211
+ By ("Unsetting the AuthoritativeAPI field in the status" )
212
+ Eventually (k .UpdateStatus (instance , func () {
213
+ instance .Status .AuthoritativeAPI = ""
214
+ })).Should (Succeed ())
215
+
216
+ By ("Verifying the paused condition is still approproately set to false" )
217
+ Eventually (k .Object (instance ), timeout ).Should (HaveField ("Status.Conditions" , ContainElement (SatisfyAll (
218
+ HaveField ("Type" , Equal (PausedCondition )),
219
+ HaveField ("Status" , Equal (corev1 .ConditionFalse )),
220
+ HaveField ("Message" , Equal ("The AuthoritativeAPI is not set" )),
221
+ ))))
222
+ })
215
223
})
216
224
})
217
-
218
- func cleanResources (namespace string ) error {
219
- machine := & machinev1.Machine {}
220
- if err := k8sClient .DeleteAllOf (ctx , machine , client .InNamespace (namespace )); err != nil {
221
- return err
222
- }
223
-
224
- return nil
225
- }
0 commit comments