@@ -22,14 +22,15 @@ package e2e
2222import (
2323 . "github.com/onsi/ginkgo/v2"
2424 . "github.com/onsi/gomega"
25+ appsv1 "k8s.io/api/apps/v1"
2526 corev1 "k8s.io/api/core/v1"
2627 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728 operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1"
2829 "sigs.k8s.io/controller-runtime/pkg/client"
2930)
3031
31- var _ = Describe ("Create providers with minimal specified configuration" , func () {
32- It ("should succefully create a CoreProvider" , func () {
32+ var _ = Describe ("Create, upgrade, downgrade and delete providers with minimal specified configuration" , func () {
33+ It ("should successfully create a CoreProvider" , func () {
3334 k8sclient := bootstrapClusterProxy .GetClient ()
3435 coreProvider := & operatorv1.CoreProvider {
3536 ObjectMeta : metav1.ObjectMeta {
@@ -85,7 +86,7 @@ var _ = Describe("Create providers with minimal specified configuration", func()
8586 }, timeout ).Should (Equal (true ))
8687 })
8788
88- It ("should succefully create a BootstrapProvider" , func () {
89+ It ("should successfully create and delete a BootstrapProvider" , func () {
8990 k8sclient := bootstrapClusterProxy .GetClient ()
9091 bootstrapProvider := & operatorv1.BootstrapProvider {
9192 ObjectMeta : metav1.ObjectMeta {
@@ -139,9 +140,22 @@ var _ = Describe("Create providers with minimal specified configuration", func()
139140 }
140141 return false
141142 }, timeout ).Should (Equal (true ))
143+
144+ Expect (k8sclient .Delete (ctx , bootstrapProvider )).To (Succeed ())
145+
146+ By ("Waiting for the bootstrap provider deployment to be deleted" )
147+ Eventually (func () bool {
148+ deployment := & appsv1.Deployment {}
149+ key := client.ObjectKey {Namespace : operatorNamespace , Name : bootstrapProviderDeploymentName }
150+ isBootstrapProviderReady , err := waitForObjectToBeDeleted (k8sclient , ctx , key , deployment )
151+ if err != nil {
152+ return false
153+ }
154+ return isBootstrapProviderReady
155+ }, timeout ).Should (Equal (true ))
142156 })
143157
144- It ("should succefully create a ControlPlaneProvider" , func () {
158+ It ("should successfully create and delete a ControlPlaneProvider" , func () {
145159 k8sclient := bootstrapClusterProxy .GetClient ()
146160 cpProvider := & operatorv1.ControlPlaneProvider {
147161 ObjectMeta : metav1.ObjectMeta {
@@ -195,9 +209,22 @@ var _ = Describe("Create providers with minimal specified configuration", func()
195209 }
196210 return false
197211 }, timeout ).Should (Equal (true ))
212+
213+ Expect (k8sclient .Delete (ctx , cpProvider )).To (Succeed ())
214+
215+ By ("Waiting for the control plane provider deployment to be deleted" )
216+ Eventually (func () bool {
217+ deployment := & appsv1.Deployment {}
218+ key := client.ObjectKey {Namespace : operatorNamespace , Name : cpProviderDeploymentName }
219+ isCPProviderDeleted , err := waitForObjectToBeDeleted (k8sclient , ctx , key , deployment )
220+ if err != nil {
221+ return false
222+ }
223+ return isCPProviderDeleted
224+ }, timeout ).Should (Equal (true ))
198225 })
199226
200- It ("should succefully create a InfrastructureProvider" , func () {
227+ It ("should successfully create and delete an InfrastructureProvider" , func () {
201228 k8sclient := bootstrapClusterProxy .GetClient ()
202229 infraProvider := & operatorv1.InfrastructureProvider {
203230 ObjectMeta : metav1.ObjectMeta {
@@ -251,5 +278,146 @@ var _ = Describe("Create providers with minimal specified configuration", func()
251278 }
252279 return false
253280 }, timeout ).Should (Equal (true ))
281+
282+ Expect (k8sclient .Delete (ctx , infraProvider )).To (Succeed ())
283+
284+ By ("Waiting for the infrastructure provider deployment to be deleted" )
285+ Eventually (func () bool {
286+ deployment := & appsv1.Deployment {}
287+ key := client.ObjectKey {Namespace : operatorNamespace , Name : infraProviderDeploymentName }
288+ isInfraProviderDeleted , err := waitForObjectToBeDeleted (k8sclient , ctx , key , deployment )
289+ if err != nil {
290+ return false
291+ }
292+ return isInfraProviderDeleted
293+ }, timeout ).Should (Equal (true ))
294+ })
295+
296+ It ("should successfully downgrade a CoreProvider (v1.4.2 -> v1.4.0)" , func () {
297+ k8sclient := bootstrapClusterProxy .GetClient ()
298+ coreProvider := & operatorv1.CoreProvider {}
299+ key := client.ObjectKey {Namespace : operatorNamespace , Name : coreProviderName }
300+ Expect (k8sclient .Get (ctx , key , coreProvider )).To (Succeed ())
301+
302+ coreProvider .Spec .Version = previousCAPIVersion
303+
304+ Expect (k8sclient .Update (ctx , coreProvider )).To (Succeed ())
305+
306+ By ("Waiting for the core provider deployment to be ready" )
307+ Eventually (func () bool {
308+ isReady , err := waitForDeployment (k8sclient , ctx , coreProviderDeploymentName )
309+ if err != nil {
310+ return false
311+ }
312+ return isReady
313+ }, timeout ).Should (Equal (true ))
314+
315+ By ("Waiting for core provider to be ready" )
316+ Eventually (func () bool {
317+ coreProvider := & operatorv1.CoreProvider {}
318+ key := client.ObjectKey {Namespace : operatorNamespace , Name : coreProviderName }
319+ if err := k8sclient .Get (ctx , key , coreProvider ); err != nil {
320+ return false
321+ }
322+
323+ for _ , c := range coreProvider .Status .Conditions {
324+ if c .Type == operatorv1 .ProviderInstalledCondition && c .Status == corev1 .ConditionTrue {
325+ return true
326+ }
327+ }
328+ return false
329+ }, timeout ).Should (Equal (true ))
330+
331+ By ("Waiting for status.IntalledVersion to be set" )
332+ Eventually (func () bool {
333+ coreProvider := & operatorv1.CoreProvider {}
334+ key := client.ObjectKey {Namespace : operatorNamespace , Name : coreProviderName }
335+ if err := k8sclient .Get (ctx , key , coreProvider ); err != nil {
336+ return false
337+ }
338+
339+ if coreProvider .Status .InstalledVersion != nil && * coreProvider .Status .InstalledVersion == previousCAPIVersion {
340+ return true
341+ }
342+ return false
343+ }, timeout ).Should (Equal (true ))
344+ })
345+
346+ It ("should successfully upgrade a CoreProvider (v1.4.0 -> v1.4.2)" , func () {
347+ k8sclient := bootstrapClusterProxy .GetClient ()
348+ coreProvider := & operatorv1.CoreProvider {}
349+ key := client.ObjectKey {Namespace : operatorNamespace , Name : coreProviderName }
350+ Expect (k8sclient .Get (ctx , key , coreProvider )).To (Succeed ())
351+
352+ coreProvider .Spec .Version = capiVersion
353+
354+ Expect (k8sclient .Update (ctx , coreProvider )).To (Succeed ())
355+
356+ By ("Waiting for the core provider deployment to be ready" )
357+ Eventually (func () bool {
358+ isReady , err := waitForDeployment (k8sclient , ctx , coreProviderDeploymentName )
359+ if err != nil {
360+ return false
361+ }
362+ return isReady
363+ }, timeout ).Should (Equal (true ))
364+
365+ By ("Waiting for core provider to be ready" )
366+ Eventually (func () bool {
367+ coreProvider := & operatorv1.CoreProvider {}
368+ key := client.ObjectKey {Namespace : operatorNamespace , Name : coreProviderName }
369+ if err := k8sclient .Get (ctx , key , coreProvider ); err != nil {
370+ return false
371+ }
372+
373+ for _ , c := range coreProvider .Status .Conditions {
374+ if c .Type == operatorv1 .ProviderInstalledCondition && c .Status == corev1 .ConditionTrue {
375+ return true
376+ }
377+ }
378+ return false
379+ }, timeout ).Should (Equal (true ))
380+
381+ By ("Waiting for status.IntalledVersion to be set" )
382+ Eventually (func () bool {
383+ coreProvider := & operatorv1.CoreProvider {}
384+ key := client.ObjectKey {Namespace : operatorNamespace , Name : coreProviderName }
385+ if err := k8sclient .Get (ctx , key , coreProvider ); err != nil {
386+ return false
387+ }
388+
389+ if coreProvider .Status .InstalledVersion != nil && * coreProvider .Status .InstalledVersion == capiVersion {
390+ return true
391+ }
392+ return false
393+ }, timeout ).Should (Equal (true ))
394+ })
395+
396+ It ("should successfully delete a CoreProvider" , func () {
397+ k8sclient := bootstrapClusterProxy .GetClient ()
398+ coreProvider := & operatorv1.CoreProvider {
399+ ObjectMeta : metav1.ObjectMeta {
400+ Name : coreProviderName ,
401+ Namespace : operatorNamespace ,
402+ },
403+ Spec : operatorv1.CoreProviderSpec {
404+ ProviderSpec : operatorv1.ProviderSpec {
405+ Version : capiVersion ,
406+ },
407+ },
408+ }
409+
410+ Expect (k8sclient .Delete (ctx , coreProvider )).To (Succeed ())
411+
412+ By ("Waiting for the core provider deployment to be deleted" )
413+ Eventually (func () bool {
414+ deployment := & appsv1.Deployment {}
415+ key := client.ObjectKey {Namespace : operatorNamespace , Name : coreProviderDeploymentName }
416+ isReady , err := waitForObjectToBeDeleted (k8sclient , ctx , key , deployment )
417+ if err != nil {
418+ return false
419+ }
420+ return isReady
421+ }, timeout ).Should (Equal (true ))
254422 })
255423})
0 commit comments