Skip to content

Commit 7488790

Browse files
committed
Add E2E test for SynchronizedAPI
1 parent 2548087 commit 7488790

6 files changed

+123
-0
lines changed

e2e/machine_migration_capi_authoritative_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
198198
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
199199
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
200200
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
201+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.ClusterAPISynchronized)
201202
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
202203
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
203204
})
@@ -209,6 +210,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
209210
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
210211
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
211212
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
213+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.MachineAPISynchronized)
212214
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
213215
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
214216
})
@@ -220,6 +222,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
220222
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
221223
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
222224
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
225+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.ClusterAPISynchronized)
223226
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
224227
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
225228
})

e2e/machine_migration_helpers.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ func verifyMachineAuthoritative(mapiMachine *mapiv1beta1.Machine, authority mapi
160160
)
161161
}
162162

163+
// verifyMachineMigrating verifies that the MAPI Machine is in Migrating state with the expected synchronizedAPI.
164+
// The synchronizedAPI indicates the source API that the migration is coming from.
165+
func verifyMachineMigrating(mapiMachine *mapiv1beta1.Machine, expectedSynchronizedAPI mapiv1beta1.SynchronizedAPI) {
166+
By(fmt.Sprintf("Verify the Machine is in Migrating state with SynchronizedAPI: %s", expectedSynchronizedAPI))
167+
Eventually(komega.Object(mapiMachine), capiframework.WaitMedium, capiframework.RetryMedium).Should(SatisfyAll(
168+
HaveField("Status.AuthoritativeAPI", Equal(mapiv1beta1.MachineAuthorityMigrating)),
169+
HaveField("Status.SynchronizedAPI", Equal(expectedSynchronizedAPI)),
170+
), fmt.Sprintf("Should have found Machine with status.AuthoritativeAPI:Migrating and status.SynchronizedAPI:%s", expectedSynchronizedAPI))
171+
}
172+
163173
func verifyMAPIMachineSynchronizedCondition(mapiMachine *mapiv1beta1.Machine, authority mapiv1beta1.MachineAuthority) {
164174
By("Verify the MAPI Machine synchronized condition is True")
165175
var expectedMessage string
@@ -324,3 +334,12 @@ func verifyMachineSynchronizedGeneration(cl client.Client, mapiMachine *mapiv1be
324334
fmt.Sprintf("MAPI Machine SynchronizedGeneration should equal %s Machine Generation (%d)", authoritativeMachineType, expectedGeneration),
325335
)
326336
}
337+
338+
// verifyMachineSynchronizedAPI verifies that the MAPI Machine's status.synchronizedAPI matches the expected value.
339+
func verifyMachineSynchronizedAPI(mapiMachine *mapiv1beta1.Machine, expectedSynchronizedAPI mapiv1beta1.SynchronizedAPI) {
340+
By(fmt.Sprintf("Verifying MAPI Machine SynchronizedAPI is %s", expectedSynchronizedAPI))
341+
Eventually(komega.Object(mapiMachine), capiframework.WaitMedium, capiframework.RetryMedium).Should(
342+
HaveField("Status.SynchronizedAPI", Equal(expectedSynchronizedAPI)),
343+
fmt.Sprintf("MAPI Machine SynchronizedAPI should be %s", expectedSynchronizedAPI),
344+
)
345+
}

e2e/machine_migration_mapi_authoritative_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
163163
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
164164
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
165165
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
166+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.MachineAPISynchronized)
166167
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
167168
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
168169
})
@@ -174,6 +175,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
174175
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
175176
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
176177
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
178+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.ClusterAPISynchronized)
177179
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
178180
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
179181
})
@@ -185,6 +187,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
185187
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
186188
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
187189
verifyMachineSynchronizedGeneration(cl, newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
190+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.MachineAPISynchronized)
188191
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
189192
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
190193
})
@@ -201,5 +204,86 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
201204
})
202205
})
203206
})
207+
208+
var _ = Describe("Machine Migration Rollback Tests", Ordered, func() {
209+
var machineRollbackName = "machine-migration-rollback"
210+
var newMapiMachine *mapiv1beta1.Machine
211+
var newCapiMachine *clusterv1beta1.Machine
212+
213+
Context("MAPI -> Migrating -> MAPI rollback", func() {
214+
BeforeAll(func() {
215+
By("Creating a MAPI machine with spec.authoritativeAPI: MachineAPI")
216+
newMapiMachine = createMAPIMachineWithAuthority(ctx, cl, machineRollbackName, mapiv1beta1.MachineAuthorityMachineAPI)
217+
verifyMachineRunning(cl, newMapiMachine)
218+
219+
DeferCleanup(func() {
220+
By("Cleaning up machine resources")
221+
cleanupMachineResources(
222+
ctx,
223+
cl,
224+
[]*clusterv1beta1.Machine{newCapiMachine},
225+
[]*mapiv1beta1.Machine{newMapiMachine},
226+
)
227+
})
228+
})
229+
230+
It("should create a CAPI mirror machine and verify initial state", func() {
231+
newCapiMachine = capiframework.GetMachine(cl, machineRollbackName, capiframework.CAPINamespace)
232+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
233+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.MachineAPISynchronized)
234+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
235+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
236+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
237+
})
238+
239+
It("should rollback to MachineAPI when migration is cancelled during Migrating state", func() {
240+
By("Updating spec.authoritativeAPI: ClusterAPI to initiate migration")
241+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
242+
243+
By("Waiting for the machine to enter Migrating state with SynchronizedAPI showing the source (MachineAPI)")
244+
verifyMachineMigrating(newMapiMachine, mapiv1beta1.MachineAPISynchronized)
245+
246+
By("Cancelling migration by setting spec.authoritativeAPI back to MachineAPI")
247+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
248+
249+
By("Verifying the machine returns to MachineAPI authority")
250+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
251+
252+
By("Verifying SynchronizedAPI is preserved as MachineAPI after rollback")
253+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.MachineAPISynchronized)
254+
255+
By("Verifying the machine continues to run normally after rollback")
256+
verifyMachineRunning(cl, newMapiMachine)
257+
258+
By("Verifying paused conditions are correct after rollback")
259+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
260+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
261+
})
262+
263+
It("should complete a full migration to ClusterAPI after a previous rollback", func() {
264+
By("Updating spec.authoritativeAPI: ClusterAPI again")
265+
updateMachineAuthoritativeAPI(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
266+
267+
By("Verifying migration completes successfully this time")
268+
verifyMachineRunning(cl, newCapiMachine)
269+
verifyMachineAuthoritative(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
270+
verifyMachineSynchronizedAPI(newMapiMachine, mapiv1beta1.ClusterAPISynchronized)
271+
verifyMAPIMachineSynchronizedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
272+
verifyMachinePausedCondition(newMapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
273+
verifyMachinePausedCondition(newCapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
274+
})
275+
276+
It("should verify mirror machines are deleted when deleting CAPI machine", func() {
277+
By("Deleting CAPI machine")
278+
capiframework.DeleteMachines(ctx, cl, capiframework.CAPINamespace, newCapiMachine)
279+
verifyResourceRemoved(newMapiMachine)
280+
verifyResourceRemoved(newCapiMachine)
281+
verifyResourceRemoved(&awsv1.AWSMachine{
282+
TypeMeta: metav1.TypeMeta{Kind: "AWSMachine", APIVersion: awsv1.GroupVersion.String()},
283+
ObjectMeta: metav1.ObjectMeta{Name: machineRollbackName, Namespace: capiframework.CAPINamespace},
284+
})
285+
})
286+
})
287+
})
204288
})
205289
})

e2e/machineset_migration_capi_authoritative_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
166166
verifyMachineSetPausedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
167167
verifyMachineSetPausedCondition(capiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
168168
verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
169+
verifyMachineSetSynchronizedAPI(mapiMachineSet, mapiv1beta1.MachineAPISynchronized)
169170
})
170171

171172
It("should succeed scaling up MAPI MachineSet to 3, after switching AuthoritativeAPI to MachineAPI", func() {
@@ -204,6 +205,7 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
204205
verifyMachineSetPausedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
205206
verifyMachineSetPausedCondition(capiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
206207
verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
208+
verifyMachineSetSynchronizedAPI(mapiMachineSet, mapiv1beta1.ClusterAPISynchronized)
207209
})
208210

209211
It("should delete both MAPI and CAPI MachineSets/Machines and InfraMachineTemplate when deleting CAPI MachineSet", func() {

e2e/machineset_migration_helpers.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ func verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet *mapiv1beta1.Machi
218218
)
219219
}
220220

221+
// verifyMachineSetSynchronizedAPI verifies that the MAPI MachineSet's status.synchronizedAPI matches the expected value.
222+
func verifyMachineSetSynchronizedAPI(mapiMachineSet *mapiv1beta1.MachineSet, expectedSynchronizedAPI mapiv1beta1.SynchronizedAPI) {
223+
By(fmt.Sprintf("Verifying MAPI MachineSet SynchronizedAPI is %s", expectedSynchronizedAPI))
224+
Eventually(komega.Object(mapiMachineSet), capiframework.WaitMedium, capiframework.RetryMedium).Should(
225+
HaveField("Status.SynchronizedAPI", Equal(expectedSynchronizedAPI)),
226+
fmt.Sprintf("MAPI MachineSet SynchronizedAPI should be %s", expectedSynchronizedAPI),
227+
)
228+
}
229+
221230
// verifyMAPIMachineSetProviderSpec verifies that a MAPI MachineSet's providerSpec matches the given Gomega matcher.
222231
func verifyMAPIMachineSetProviderSpec(mapiMachineSet *mapiv1beta1.MachineSet, matcher types.GomegaMatcher) {
223232
By(fmt.Sprintf("Verifying MAPI MachineSet %s ProviderSpec", mapiMachineSet.Name))

e2e/machineset_migration_mapi_authoritative_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
166166
verifyMachineSetPausedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
167167
verifyMachineSetPausedCondition(capiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
168168
verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
169+
verifyMachineSetAuthoritative(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
170+
verifyMachineSetSynchronizedAPI(mapiMachineSet, mapiv1beta1.ClusterAPISynchronized)
169171
})
170172

171173
It("should succeed scaling up CAPI MachineSet to 3, after the switch of AuthoritativeAPI to ClusterAPI", func() {
@@ -204,6 +206,8 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
204206

205207
It("should succeed in switching back the AuthoritativeAPI to MachineAPI after the initial switch to ClusterAPI", func() {
206208
switchMachineSetAuthoritativeAPI(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI, mapiv1beta1.MachineAuthorityMachineAPI)
209+
verifyMachineSetAuthoritative(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
210+
verifyMachineSetSynchronizedAPI(mapiMachineSet, mapiv1beta1.MachineAPISynchronized)
207211
verifyMachineSetPausedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
208212
verifyMachineSetPausedCondition(capiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
209213
verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
@@ -331,6 +335,8 @@ var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] Ma
331335
BeforeAll(func() {
332336
switchMachineSetAuthoritativeAPI(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI, mapiv1beta1.MachineAuthorityClusterAPI)
333337
verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
338+
verifyMachineSetAuthoritative(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
339+
verifyMachineSetSynchronizedAPI(mapiMachineSet, mapiv1beta1.ClusterAPISynchronized)
334340
})
335341

336342
It("should be rejected when scaling MAPI MachineSet", func() {

0 commit comments

Comments
 (0)