Skip to content

Commit a21c7cc

Browse files
authored
Merge pull request #121 from Fedosin/e2e_tests
🌱 add more e2e tests
2 parents 5f58c3b + d8bcf83 commit a21c7cc

File tree

2 files changed

+188
-6
lines changed

2 files changed

+188
-6
lines changed

test/e2e/helpers.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
appsv1 "k8s.io/api/apps/v1"
2727
corev1 "k8s.io/api/core/v1"
28+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2829
"sigs.k8s.io/controller-runtime/pkg/client"
2930
)
3031

@@ -36,7 +37,8 @@ const (
3637
timeout = 5 * time.Minute
3738
operatorNamespace = "capi-operator-system"
3839

39-
capiVersion = "v1.4.2"
40+
capiVersion = "v1.4.2"
41+
previousCAPIVersion = "v1.4.0"
4042

4143
coreProviderName = "cluster-api"
4244
coreProviderDeploymentName = "capi-controller-manager"
@@ -66,3 +68,15 @@ func waitForDeployment(cl client.Client, ctx context.Context, name string) (bool
6668

6769
return false, nil
6870
}
71+
72+
func waitForObjectToBeDeleted(cl client.Client, ctx context.Context, key client.ObjectKey, obj client.Object) (bool, error) {
73+
if err := cl.Get(ctx, key, obj); err != nil {
74+
if apierrors.IsNotFound(err) {
75+
return true, nil
76+
}
77+
78+
return false, err
79+
}
80+
81+
return false, nil
82+
}

test/e2e/minimal_configuration.go

Lines changed: 173 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ package e2e
2222
import (
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

Comments
 (0)