Skip to content

Commit

Permalink
test: add more e2e tests
Browse files Browse the repository at this point in the history
This PR adds several e2e tests to verify deletion, upgrading and
downgrading providers.
  • Loading branch information
Fedosin committed May 30, 2023
1 parent 3e56fc9 commit 394ce1e
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 5 deletions.
16 changes: 15 additions & 1 deletion test/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
)

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

capiVersion = "v1.4.2"
capiVersion = "v1.4.2"
previousCAPIVersion = "v1.4.0"

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

return false, nil
}

func waitForObjectToBeDeleted(cl client.Client, ctx context.Context, key client.ObjectKey, obj client.Object) (bool, error) {
if err := cl.Get(ctx, key, obj); err != nil {
if apierrors.IsNotFound(err) {
return true, nil
}

return false, err
}

return false, nil
}
176 changes: 172 additions & 4 deletions test/e2e/minimal_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ package e2e
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var _ = Describe("Create providers with minimal specified configuration", func() {
It("should succefully create a CoreProvider", func() {
var _ = Describe("Create, upgrade, downgrade and delete providers with minimal specified configuration", func() {
It("should successfully create a CoreProvider", func() {
k8sclient := bootstrapClusterProxy.GetClient()
coreProvider := &operatorv1.CoreProvider{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -139,9 +140,22 @@ var _ = Describe("Create providers with minimal specified configuration", func()
}
return false
}, timeout).Should(Equal(true))

Expect(k8sclient.Delete(ctx, bootstrapProvider)).To(Succeed())

By("Waiting for the bootstrap provider deployment to be deleted")
Eventually(func() bool {
deployment := &appsv1.Deployment{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: bootstrapProviderDeploymentName}
isReady, err := waitForObjectToBeDeleted(k8sclient, ctx, key, deployment)
if err != nil {
return false
}
return isReady
}, timeout).Should(Equal(true))
})

It("should succefully create a ControlPlaneProvider", func() {
It("should successfully create and delete a ControlPlaneProvider", func() {
k8sclient := bootstrapClusterProxy.GetClient()
cpProvider := &operatorv1.ControlPlaneProvider{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -195,9 +209,22 @@ var _ = Describe("Create providers with minimal specified configuration", func()
}
return false
}, timeout).Should(Equal(true))

Expect(k8sclient.Delete(ctx, cpProvider)).To(Succeed())

By("Waiting for the control plane provider deployment to be deleted")
Eventually(func() bool {
deployment := &appsv1.Deployment{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: cpProviderDeploymentName}
isReady, err := waitForObjectToBeDeleted(k8sclient, ctx, key, deployment)
if err != nil {
return false
}
return isReady
}, timeout).Should(Equal(true))
})

It("should succefully create a InfrastructureProvider", func() {
It("should successfully create and delete an InfrastructureProvider", func() {
k8sclient := bootstrapClusterProxy.GetClient()
infraProvider := &operatorv1.InfrastructureProvider{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -251,5 +278,146 @@ var _ = Describe("Create providers with minimal specified configuration", func()
}
return false
}, timeout).Should(Equal(true))

Expect(k8sclient.Delete(ctx, infraProvider)).To(Succeed())

By("Waiting for the infrastructure provider deployment to be deleted")
Eventually(func() bool {
deployment := &appsv1.Deployment{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: infraProviderDeploymentName}
isReady, err := waitForObjectToBeDeleted(k8sclient, ctx, key, deployment)
if err != nil {
return false
}
return isReady
}, timeout).Should(Equal(true))
})

It("should successfully downgrade a CoreProvider (v1.4.2 -> v1.4.0)", func() {
k8sclient := bootstrapClusterProxy.GetClient()
coreProvider := &operatorv1.CoreProvider{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName}
Expect(k8sclient.Get(ctx, key, coreProvider)).To(Succeed())

coreProvider.Spec.Version = previousCAPIVersion

Expect(k8sclient.Update(ctx, coreProvider)).To(Succeed())

By("Waiting for the core provider deployment to be ready")
Eventually(func() bool {
isReady, err := waitForDeployment(k8sclient, ctx, coreProviderDeploymentName)
if err != nil {
return false
}
return isReady
}, timeout).Should(Equal(true))

By("Waiting for core provider to be ready")
Eventually(func() bool {
coreProvider := &operatorv1.CoreProvider{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName}
if err := k8sclient.Get(ctx, key, coreProvider); err != nil {
return false
}

for _, c := range coreProvider.Status.Conditions {
if c.Type == operatorv1.ProviderInstalledCondition && c.Status == corev1.ConditionTrue {
return true
}
}
return false
}, timeout).Should(Equal(true))

By("Waiting for status.IntalledVersion to be set")
Eventually(func() bool {
coreProvider := &operatorv1.CoreProvider{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName}
if err := k8sclient.Get(ctx, key, coreProvider); err != nil {
return false
}

if coreProvider.Status.InstalledVersion != nil && *coreProvider.Status.InstalledVersion == previousCAPIVersion {
return true
}
return false
}, timeout).Should(Equal(true))
})

It("should successfully upgrade a CoreProvider (v1.4.0 -> v1.4.2)", func() {
k8sclient := bootstrapClusterProxy.GetClient()
coreProvider := &operatorv1.CoreProvider{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName}
Expect(k8sclient.Get(ctx, key, coreProvider)).To(Succeed())

coreProvider.Spec.Version = capiVersion

Expect(k8sclient.Update(ctx, coreProvider)).To(Succeed())

By("Waiting for the core provider deployment to be ready")
Eventually(func() bool {
isReady, err := waitForDeployment(k8sclient, ctx, coreProviderDeploymentName)
if err != nil {
return false
}
return isReady
}, timeout).Should(Equal(true))

By("Waiting for core provider to be ready")
Eventually(func() bool {
coreProvider := &operatorv1.CoreProvider{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName}
if err := k8sclient.Get(ctx, key, coreProvider); err != nil {
return false
}

for _, c := range coreProvider.Status.Conditions {
if c.Type == operatorv1.ProviderInstalledCondition && c.Status == corev1.ConditionTrue {
return true
}
}
return false
}, timeout).Should(Equal(true))

By("Waiting for status.IntalledVersion to be set")
Eventually(func() bool {
coreProvider := &operatorv1.CoreProvider{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName}
if err := k8sclient.Get(ctx, key, coreProvider); err != nil {
return false
}

if coreProvider.Status.InstalledVersion != nil && *coreProvider.Status.InstalledVersion == capiVersion {
return true
}
return false
}, timeout).Should(Equal(true))
})

It("should successfully delete a CoreProvider", func() {
k8sclient := bootstrapClusterProxy.GetClient()
coreProvider := &operatorv1.CoreProvider{
ObjectMeta: metav1.ObjectMeta{
Name: coreProviderName,
Namespace: operatorNamespace,
},
Spec: operatorv1.CoreProviderSpec{
ProviderSpec: operatorv1.ProviderSpec{
Version: capiVersion,
},
},
}

Expect(k8sclient.Delete(ctx, coreProvider)).To(Succeed())

By("Waiting for the core provider deployment to be deleted")
Eventually(func() bool {
deployment := &appsv1.Deployment{}
key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderDeploymentName}
isReady, err := waitForObjectToBeDeleted(k8sclient, ctx, key, deployment)
if err != nil {
return false
}
return isReady
}, timeout).Should(Equal(true))
})
})

0 comments on commit 394ce1e

Please sign in to comment.