Skip to content

Commit

Permalink
Merge pull request #207 from Danil-Grigorev/init-logs-suite
Browse files Browse the repository at this point in the history
🌱 Refactor tests to be more readable and have better logging
  • Loading branch information
k8s-ci-robot authored Aug 7, 2023
2 parents 46be1c4 + 7132e62 commit d9e33a9
Show file tree
Hide file tree
Showing 12 changed files with 7,350 additions and 749 deletions.
199 changes: 58 additions & 141 deletions test/e2e/air_gapped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1"
. "sigs.k8s.io/cluster-api-operator/test/framework"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"
)

var _ = Describe("Install Core Provider in an air-gapped environment", func() {
It("should successfully create config maps with Core Provider manifests", func() {
k8sclient := bootstrapClusterProxy.GetClient()

bootstrapCluster := bootstrapClusterProxy.GetClient()
configMaps := []corev1.ConfigMap{}

for _, fileName := range []string{"core-cluster-api-v1.4.2.yaml", "core-cluster-api-v1.4.3.yaml"} {
Expand All @@ -51,12 +53,12 @@ var _ = Describe("Install Core Provider in an air-gapped environment", func() {

By("Applying core provider manifests to the cluster")
for _, cm := range configMaps {
Expect(k8sclient.Create(ctx, &cm)).To(Succeed())
Expect(bootstrapCluster.Create(ctx, &cm)).To(Succeed())
}
})

It("should successfully create a CoreProvider from a config map", func() {
k8sclient := bootstrapClusterProxy.GetClient()
bootstrapCluster := bootstrapClusterProxy.GetClient()
coreProvider := &operatorv1.CoreProvider{
ObjectMeta: metav1.ObjectMeta{
Name: coreProviderName,
Expand All @@ -76,187 +78,102 @@ var _ = Describe("Install Core Provider in an air-gapped environment", func() {
},
}

Expect(k8sclient.Create(ctx, coreProvider)).To(Succeed())
Expect(bootstrapCluster.Create(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))
framework.WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{
Getter: bootstrapClusterProxy.GetClient(),
Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: coreProviderDeploymentName, Namespace: operatorNamespace}},
}, e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)

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))
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition),
), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)

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 == coreProvider.Spec.Version {
return true
}
return false
}, timeout).Should(Equal(true))
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(func() bool {
return ptr.Equal(coreProvider.Status.InstalledVersion, ptr.To(coreProvider.Spec.Version))
}), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
})

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

coreProvider.Spec.Version = previousCAPIVersion

Expect(k8sclient.Update(ctx, coreProvider)).To(Succeed())
Expect(bootstrapCluster.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))
framework.WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{
Getter: bootstrapClusterProxy.GetClient(),
Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: coreProviderDeploymentName, Namespace: operatorNamespace}},
}, e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)

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))
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition),
), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)

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))
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(func() bool {
return ptr.Equal(coreProvider.Status.InstalledVersion, ptr.To(previousCAPIVersion))
}), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
})

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

coreProvider.Spec.Version = ""

Expect(k8sclient.Update(ctx, coreProvider)).To(Succeed())
Expect(bootstrapCluster.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))
framework.WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{
Getter: bootstrapClusterProxy.GetClient(),
Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: coreProviderDeploymentName, Namespace: operatorNamespace}},
}, e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)

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))
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(
HaveStatusCondition(&coreProvider.Status.Conditions, operatorv1.ProviderInstalledCondition),
), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)

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 == coreProvider.Spec.Version {
return true
}
return false
}, timeout).Should(Equal(true))
WaitFor(ctx, For(coreProvider).In(bootstrapCluster).ToSatisfy(func() bool {
return ptr.Equal(coreProvider.Status.InstalledVersion, ptr.To(coreProvider.Spec.Version))
}), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
})

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{},
},
}
bootstrapCluster := bootstrapClusterProxy.GetClient()
coreProvider := &operatorv1.CoreProvider{ObjectMeta: metav1.ObjectMeta{
Name: coreProviderName,
Namespace: operatorNamespace,
}}

Expect(k8sclient.Delete(ctx, coreProvider)).To(Succeed())
Expect(bootstrapCluster.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))
WaitForDelete(ctx, For(&appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{
Name: coreProviderDeploymentName,
Namespace: operatorNamespace,
}}).In(bootstrapCluster), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)

By("Waiting for the core provider object to be deleted")
Eventually(func() bool {
key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName}
isReady, err := waitForObjectToBeDeleted(k8sclient, ctx, key, coreProvider)
if err != nil {
return false
}
return isReady
}, timeout).Should(Equal(true))
WaitForDelete(
ctx, For(coreProvider).In(bootstrapCluster),
e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-controllers")...)
})

It("should successfully delete config maps with Core Provider manifests", func() {
k8sclient := bootstrapClusterProxy.GetClient()

bootstrapCluster := bootstrapClusterProxy.GetClient()
configMaps := []corev1.ConfigMap{}

for _, fileName := range []string{"core-cluster-api-v1.4.2.yaml", "core-cluster-api-v1.4.3.yaml"} {
Expand All @@ -272,7 +189,7 @@ var _ = Describe("Install Core Provider in an air-gapped environment", func() {

By("Deleting config maps with core provider manifests")
for _, cm := range configMaps {
Expect(k8sclient.Delete(ctx, &cm)).To(Succeed())
Expect(bootstrapCluster.Delete(ctx, &cm)).To(Succeed())
}
})
})
Loading

0 comments on commit d9e33a9

Please sign in to comment.