-
Notifications
You must be signed in to change notification settings - Fork 89
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
🌱 add more e2e tests #121
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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{ | ||
|
@@ -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{ | ||
|
@@ -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()) | ||
Fedosin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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{ | ||
|
@@ -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{ | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
}) | ||
}) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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