Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 add more e2e tests #121

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
178 changes: 173 additions & 5 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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a delete test for CoreProvider as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wrote a test for that (line 396). The thing is that in order to install other providers, we need Core Provider to be Ready. It means we can't delete it immediately and have to postpone this action.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, was thinking the same initially, thanks for clarification

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fedosin feel free to resolve the conversation

k8sclient := bootstrapClusterProxy.GetClient()
coreProvider := &operatorv1.CoreProvider{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -85,7 +86,7 @@ var _ = Describe("Create providers with minimal specified configuration", func()
}, timeout).Should(Equal(true))
})

It("should succefully create a BootstrapProvider", func() {
It("should successfully create and delete a BootstrapProvider", func() {
k8sclient := bootstrapClusterProxy.GetClient()
bootstrapProvider := &operatorv1.BootstrapProvider{
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}
isBootstrapProviderReady, err := waitForObjectToBeDeleted(k8sclient, ctx, key, deployment)
if err != nil {
return false
}
return isBootstrapProviderReady
}, 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}
isCPProviderDeleted, err := waitForObjectToBeDeleted(k8sclient, ctx, key, deployment)
if err != nil {
return false
}
return isCPProviderDeleted
}, 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}
isInfraProviderDeleted, err := waitForObjectToBeDeleted(k8sclient, ctx, key, deployment)
if err != nil {
return false
}
return isInfraProviderDeleted
}, 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))
Comment on lines +410 to +421
Copy link
Member

@furkatgofurov7 furkatgofurov7 May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps it is better if we will move this code to the end of core provider tests at the beginning of the file (see this commment) and drop the dedicated "It" test case to shorten the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we can't delete it earlier, because other providers will fail a preflight check that tests that Core Provider is Ready: https://github.com/kubernetes-sigs/cluster-api-operator/blob/main/internal/controller/preflight_checks.go#L130-L131

})
})