Skip to content

Commit 5cfb089

Browse files
committed
refactor: split machineset migration testing into multiple files
1 parent 368d475 commit 5cfb089

File tree

5 files changed

+1008
-385
lines changed

5 files changed

+1008
-385
lines changed
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
package e2e
2+
3+
import (
4+
"fmt"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
9+
configv1 "github.com/openshift/api/config/v1"
10+
mapiv1beta1 "github.com/openshift/api/machine/v1beta1"
11+
mapiframework "github.com/openshift/cluster-api-actuator-pkg/pkg/framework"
12+
capiframework "github.com/openshift/cluster-capi-operator/e2e/framework"
13+
awsv1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
14+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
15+
)
16+
17+
var _ = Describe("[sig-cluster-lifecycle][OCPFeatureGate:MachineAPIMigration] MachineSet Migration CAPI Authoritative Tests", Ordered, func() {
18+
BeforeAll(func() {
19+
if platform != configv1.AWSPlatformType {
20+
Skip(fmt.Sprintf("Skipping tests on %s, this is only supported on AWS", platform))
21+
}
22+
23+
if !capiframework.IsMachineAPIMigrationEnabled(ctx, cl) {
24+
Skip("Skipping, this feature is only supported on MachineAPIMigration enabled clusters")
25+
}
26+
})
27+
28+
var _ = Describe("Create MAPI MachineSets", Ordered, func() {
29+
var mapiMSAuthCAPIName = "ms-authoritativeapi-capi"
30+
var existingCAPIMSAuthorityCAPIName = "capi-machineset-authoritativeapi-capi"
31+
32+
var awsMachineTemplate *awsv1.AWSMachineTemplate
33+
var capiMachineSet *clusterv1.MachineSet
34+
var mapiMachineSet *mapiv1beta1.MachineSet
35+
var instanceType = "m5.large"
36+
37+
Context("with spec.authoritativeAPI: ClusterAPI and existing CAPI MachineSet with same name", func() {
38+
BeforeAll(func() {
39+
capiMachineSet = createCAPIMachineSet(ctx, cl, 0, existingCAPIMSAuthorityCAPIName, instanceType)
40+
41+
By("Creating a same name MAPI MachineSet")
42+
mapiMachineSet = createMAPIMachineSetWithAuthoritativeAPI(ctx, cl, 0, existingCAPIMSAuthorityCAPIName, mapiv1beta1.MachineAuthorityClusterAPI, mapiv1beta1.MachineAuthorityClusterAPI)
43+
awsMachineTemplate = waitForAWSMachineTemplate(cl, existingCAPIMSAuthorityCAPIName)
44+
45+
DeferCleanup(func() {
46+
By("Cleaning up Context 'with spec.authoritativeAPI: ClusterAPI and existing CAPI MachineSet with same name' resources")
47+
cleanupMachineSetTestResources(
48+
ctx,
49+
cl,
50+
[]*clusterv1.MachineSet{capiMachineSet},
51+
[]*awsv1.AWSMachineTemplate{awsMachineTemplate},
52+
[]*mapiv1beta1.MachineSet{mapiMachineSet},
53+
)
54+
})
55+
})
56+
57+
It("should verify that MAPI MachineSet has Paused condition True", func() {
58+
verifyMachineSetPausedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
59+
})
60+
61+
// bug https://issues.redhat.com/browse/OCPBUGS-55337
62+
PIt("should verify that the non-authoritative MAPI MachineSet providerSpec has been updated to reflect the authoritative CAPI MachineSet mirror values", func() {
63+
verifyMAPIMachineSetProviderSpec(mapiMachineSet, HaveField("InstanceType", Equal(instanceType)))
64+
})
65+
})
66+
67+
Context("with spec.authoritativeAPI: ClusterAPI and no existing CAPI MachineSet with same name", func() {
68+
BeforeAll(func() {
69+
mapiMachineSet = createMAPIMachineSetWithAuthoritativeAPI(ctx, cl, 0, mapiMSAuthCAPIName, mapiv1beta1.MachineAuthorityClusterAPI, mapiv1beta1.MachineAuthorityClusterAPI)
70+
capiMachineSet = waitForCAPIMachineSetMirror(cl, mapiMSAuthCAPIName)
71+
awsMachineTemplate = waitForAWSMachineTemplate(cl, mapiMSAuthCAPIName)
72+
73+
DeferCleanup(func() {
74+
By("Cleaning up Context 'with spec.authoritativeAPI: ClusterAPI and no existing CAPI MachineSet with same name' resources")
75+
cleanupMachineSetTestResources(
76+
ctx,
77+
cl,
78+
[]*clusterv1.MachineSet{capiMachineSet},
79+
[]*awsv1.AWSMachineTemplate{awsMachineTemplate},
80+
[]*mapiv1beta1.MachineSet{mapiMachineSet},
81+
)
82+
})
83+
})
84+
85+
It("should find MAPI MachineSet .status.authoritativeAPI to equal CAPI", func() {
86+
verifyMachineSetAuthoritative(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
87+
})
88+
89+
It("should verify that MAPI MachineSet Paused condition is True", func() {
90+
verifyMachineSetPausedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
91+
})
92+
93+
It("should verify that MAPI MachineSet Synchronized condition is True", func() {
94+
verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
95+
})
96+
97+
It("should verify that the non-authoritative MAPI MachineSet has an authoritative CAPI MachineSet mirror", func() {
98+
waitForCAPIMachineSetMirror(cl, mapiMSAuthCAPIName)
99+
})
100+
101+
It("should verify that CAPI MachineSet has Paused condition False", func() {
102+
verifyMachineSetPausedCondition(capiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
103+
})
104+
})
105+
})
106+
107+
var _ = Describe("Scale MAPI MachineSets", Ordered, func() {
108+
var mapiMSAuthCAPIName = "ms-authoritativeapi-capi"
109+
110+
var awsMachineTemplate *awsv1.AWSMachineTemplate
111+
var capiMachineSet *clusterv1.MachineSet
112+
var mapiMachineSet *mapiv1beta1.MachineSet
113+
var firstMAPIMachine *mapiv1beta1.Machine
114+
var secondMAPIMachine *mapiv1beta1.Machine
115+
116+
Context("with spec.authoritativeAPI: ClusterAPI", Ordered, func() {
117+
BeforeAll(func() {
118+
mapiMachineSet = createMAPIMachineSetWithAuthoritativeAPI(ctx, cl, 1, mapiMSAuthCAPIName, mapiv1beta1.MachineAuthorityClusterAPI, mapiv1beta1.MachineAuthorityClusterAPI)
119+
capiMachineSet, awsMachineTemplate = waitForMAPIMachineSetMirrors(cl, mapiMSAuthCAPIName)
120+
121+
mapiMachines, err := mapiframework.GetMachinesFromMachineSet(ctx, cl, mapiMachineSet)
122+
Expect(err).ToNot(HaveOccurred(), "failed to get MAPI Machines from MachineSet")
123+
Expect(mapiMachines).ToNot(BeEmpty(), "no MAPI Machines found")
124+
125+
capiMachines := capiframework.GetMachinesFromMachineSet(cl, capiMachineSet)
126+
Expect(capiMachines).ToNot(BeEmpty(), "no CAPI Machines found")
127+
Expect(capiMachines[0].Name).To(Equal(mapiMachines[0].Name))
128+
firstMAPIMachine = mapiMachines[0]
129+
130+
DeferCleanup(func() {
131+
By("Cleaning up Context 'with spec.authoritativeAPI: ClusterAPI' resources")
132+
cleanupMachineSetTestResources(
133+
ctx,
134+
cl,
135+
[]*clusterv1.MachineSet{capiMachineSet},
136+
[]*awsv1.AWSMachineTemplate{awsMachineTemplate},
137+
[]*mapiv1beta1.MachineSet{mapiMachineSet},
138+
)
139+
})
140+
})
141+
142+
It("should succeed scaling CAPI MachineSet to 2 replicas", func() {
143+
By("Scaling up CAPI MachineSet to 2 replicas")
144+
capiframework.ScaleCAPIMachineSet(mapiMSAuthCAPIName, 2, capiframework.CAPINamespace)
145+
146+
By("Verifying a new CAPI Machine is created and Paused condition is False")
147+
capiMachineSet := capiframework.GetMachineSet(cl, mapiMSAuthCAPIName, capiframework.CAPINamespace)
148+
capiMachine := capiframework.GetNewestMachineFromMachineSet(cl, capiMachineSet)
149+
verifyMachineRunning(cl, capiMachine)
150+
verifyMachinePausedCondition(capiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
151+
152+
By("Verifying MAPI MachineSet status.replicas is set to 2")
153+
verifyMachinesetReplicas(mapiMachineSet, 2)
154+
155+
By("Verifying there is a non-authoritative, paused MAPI Machine mirror for the new CAPI Machine")
156+
var err error
157+
secondMAPIMachine, err = mapiframework.GetLatestMachineFromMachineSet(ctx, cl, mapiMachineSet)
158+
Expect(err).ToNot(HaveOccurred(), "failed to get MAPI Machines from MachineSet")
159+
verifyMachineAuthoritative(secondMAPIMachine, mapiv1beta1.MachineAuthorityClusterAPI)
160+
verifyMachinePausedCondition(secondMAPIMachine, mapiv1beta1.MachineAuthorityClusterAPI)
161+
})
162+
163+
It("should succeed switching MachineSet's AuthoritativeAPI to MachineAPI", func() {
164+
switchMachineSetAuthoritativeAPI(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI, mapiv1beta1.MachineAuthorityMachineAPI)
165+
verifyMachineSetPausedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
166+
verifyMachineSetPausedCondition(capiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
167+
verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityMachineAPI)
168+
})
169+
170+
It("should succeed scaling up MAPI MachineSet to 3, after switching AuthoritativeAPI to MachineAPI", func() {
171+
By("Scaling up MAPI MachineSet to 3 replicas")
172+
Expect(mapiframework.ScaleMachineSet(mapiMSAuthCAPIName, 3)).To(Succeed(), "should be able to scale up MAPI MachineSet")
173+
174+
By("Verifying the newly requested MAPI Machine has been created and its status.authoritativeAPI is MachineAPI and its Paused condition is False")
175+
mapiMachine, err := mapiframework.GetLatestMachineFromMachineSet(ctx, cl, mapiMachineSet)
176+
Expect(err).ToNot(HaveOccurred(), "failed to get MAPI Machines from MachineSet")
177+
verifyMachineRunning(cl, mapiMachine)
178+
verifyMachineAuthoritative(mapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
179+
verifyMachinePausedCondition(mapiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
180+
181+
By("Verifying MachineSet status.replicas is set to 3")
182+
verifyMachinesetReplicas(mapiMachineSet, 3)
183+
verifyMachinesetReplicas(capiMachineSet, 3)
184+
185+
By("Verifying there is a non-authoritative, paused CAPI Machine mirror for the new MAPI Machine")
186+
capiMachine := capiframework.GetNewestMachineFromMachineSet(cl, capiMachineSet)
187+
verifyMachinePausedCondition(capiMachine, mapiv1beta1.MachineAuthorityMachineAPI)
188+
189+
By("Verifying old Machines still exist and authority on them is still ClusterAPI")
190+
verifyMachineAuthoritative(firstMAPIMachine, mapiv1beta1.MachineAuthorityClusterAPI)
191+
verifyMachineAuthoritative(secondMAPIMachine, mapiv1beta1.MachineAuthorityClusterAPI)
192+
})
193+
194+
It("should succeed scaling down MAPI MachineSet to 1, after the switch of AuthoritativeAPI to MachineAPI", func() {
195+
By("Scaling down MAPI MachineSet to 1 replicas")
196+
Expect(mapiframework.ScaleMachineSet(mapiMSAuthCAPIName, 1)).To(Succeed(), "should be able to scale down MAPI MachineSet")
197+
})
198+
199+
It("should succeed switching back MachineSet's AuthoritativeAPI to ClusterAPI, after the initial switch to AuthoritativeAPI: MachineAPI", func() {
200+
switchMachineSetAuthoritativeAPI(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI, mapiv1beta1.MachineAuthorityClusterAPI)
201+
verifyMachineSetPausedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
202+
verifyMachineSetPausedCondition(capiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
203+
verifyMAPIMachineSetSynchronizedCondition(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI)
204+
})
205+
206+
It("should delete both MAPI and CAPI MachineSets/Machines and InfraMachineTemplate when deleting CAPI MachineSet", func() {
207+
capiframework.DeleteMachineSets(ctx, cl, capiMachineSet)
208+
mapiframework.WaitForMachineSetsDeleted(ctx, cl, mapiMachineSet)
209+
capiframework.WaitForMachineSetsDeleted(cl, capiMachineSet)
210+
verifyResourceRemoved(awsMachineTemplate)
211+
})
212+
})
213+
})
214+
215+
var _ = Describe("Delete MachineSets", Ordered, func() {
216+
var mapiMSAuthMAPIName = "ms-authoritativeapi-mapi"
217+
var mapiMachineSet *mapiv1beta1.MachineSet
218+
var capiMachineSet *clusterv1.MachineSet
219+
var awsMachineTemplate *awsv1.AWSMachineTemplate
220+
221+
Context("when removing non-authoritative MAPI MachineSet", Ordered, func() {
222+
BeforeAll(func() {
223+
mapiMachineSet = createMAPIMachineSetWithAuthoritativeAPI(ctx, cl, 1, mapiMSAuthMAPIName, mapiv1beta1.MachineAuthorityMachineAPI, mapiv1beta1.MachineAuthorityMachineAPI)
224+
capiMachineSet, awsMachineTemplate = waitForMAPIMachineSetMirrors(cl, mapiMSAuthMAPIName)
225+
226+
mapiMachines, err := mapiframework.GetMachinesFromMachineSet(ctx, cl, mapiMachineSet)
227+
Expect(mapiMachines).ToNot(BeEmpty(), "no MAPI Machines found")
228+
Expect(err).ToNot(HaveOccurred(), "failed to get MAPI Machines from MachineSet")
229+
230+
capiMachines := capiframework.GetMachinesFromMachineSet(cl, capiMachineSet)
231+
Expect(capiMachines).ToNot(BeEmpty(), "no CAPI Machines found")
232+
Expect(capiMachines[0].Name).To(Equal(mapiMachines[0].Name))
233+
234+
DeferCleanup(func() {
235+
By("Cleaning up Context 'when removing non-authoritative MAPI MachineSet' resources")
236+
cleanupMachineSetTestResources(
237+
ctx,
238+
cl,
239+
[]*clusterv1.MachineSet{capiMachineSet},
240+
[]*awsv1.AWSMachineTemplate{awsMachineTemplate},
241+
[]*mapiv1beta1.MachineSet{mapiMachineSet},
242+
)
243+
})
244+
})
245+
246+
It("shouldn't delete its authoritative CAPI MachineSet", func() {
247+
By("Switching AuthoritativeAPI to ClusterAPI")
248+
switchMachineSetAuthoritativeAPI(mapiMachineSet, mapiv1beta1.MachineAuthorityClusterAPI, mapiv1beta1.MachineAuthorityClusterAPI)
249+
250+
By("Scaling up CAPI MachineSet to 2 replicas")
251+
capiframework.ScaleCAPIMachineSet(mapiMachineSet.GetName(), 2, capiframework.CAPINamespace)
252+
253+
By("Verifying new CAPI Machine is running")
254+
capiMachine := capiframework.GetNewestMachineFromMachineSet(cl, capiMachineSet)
255+
verifyMachineRunning(cl, capiMachine)
256+
verifyMachinePausedCondition(capiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
257+
258+
By("Verifying MAPI MachineSet status.replicas is set to 2")
259+
verifyMachinesetReplicas(mapiMachineSet, 2)
260+
261+
By("Verifying there is a non-authoritative, paused MAPI Machine mirror for the new CAPI Machine")
262+
mapiMachine, err := mapiframework.GetLatestMachineFromMachineSet(ctx, cl, mapiMachineSet)
263+
Expect(err).ToNot(HaveOccurred(), "failed to get MAPI Machines from MachineSet")
264+
verifyMachineAuthoritative(mapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
265+
verifyMachinePausedCondition(mapiMachine, mapiv1beta1.MachineAuthorityClusterAPI)
266+
267+
By("Deleting non-authoritative MAPI MachineSet")
268+
mapiMachineSet, err = mapiframework.GetMachineSet(ctx, cl, mapiMSAuthMAPIName)
269+
Expect(err).ToNot(HaveOccurred(), "failed to get mapiMachineSet")
270+
mapiframework.DeleteMachineSets(cl, mapiMachineSet)
271+
272+
By("Verifying CAPI MachineSet not removed, both MAPI Machines and Mirrors remain")
273+
// TODO: Add full verification once OCPBUGS-56897 is fixed
274+
capiMS := capiframework.GetMachineSet(cl, mapiMSAuthMAPIName, capiframework.CAPINamespace)
275+
Expect(capiMS).ToNot(BeNil(), "CAPI MachineSet should still exist after deleting non-authoritative MAPI MachineSet")
276+
})
277+
})
278+
})
279+
})

0 commit comments

Comments
 (0)