Skip to content

Commit

Permalink
test/e2e: improve waits, logs, etc
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Sep 21, 2023
1 parent 530ca9c commit 44935f1
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 216 deletions.
3 changes: 2 additions & 1 deletion scripts/build_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
# This is used to start and build services for running e2e tests

set -e
set -o xtrace

[ -x "$(command -v kind)" ] && [[ "$(kubectl config current-context)" =~ ^kind-? ]] && KIND=1 NO_MINIKUBE=1

if [ -z "$NO_MINIKUBE" ]; then
pgrep -f "[m]inikube" >/dev/null || minikube start --extra-config=apiserver.v=4 || { echo 'Cannot start minikube.'; exit 1; }
pgrep -f "[m]inikube" >/dev/null || minikube start "${MINIKUBE_ARGS}" --extra-config=apiserver.v=4 || { echo 'Cannot start minikube.'; exit 1; }
eval "$(minikube docker-env)" || { echo 'Cannot switch to minikube docker'; exit 1; }
kubectl config use-context minikube
fi
Expand Down
5 changes: 3 additions & 2 deletions scripts/lib/olm_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ olm::util::await_csv_success() {
echo "awaiting ${namespace}/${csv} csv installation success"
until [[ "${retries}" -le "0" || "${phase:=$(kubectl get csv -n "${namespace}" "${csv}" -o jsonpath='{.status.phase}' 2>/dev/null || echo "missing")}" == "Succeeded" ]]; do
retries=$((retries - 1))
kubectl get csv -n "${namespace}" "${csv}" -o yaml
echo "current phase: ${phase}, remaining attempts: ${retries}"
unset phase
sleep 1
Expand All @@ -29,7 +30,7 @@ olm::util::await_csv_success() {
olm::util::await_olm_ready() {
local namespace="$1"

kubectl rollout status -w deployment/olm-operator --namespace="${namespace}" || return
kubectl rollout status -w deployment/catalog-operator --namespace="${namespace}" || return
kubectl rollout status -w deployment/olm-operator --namespace="${namespace}" || kubectl get deployment olm-operator --namespace="${namespace}" -o yaml && return
kubectl rollout status -w deployment/catalog-operator --namespace="${namespace}" || kubectl get deployment catalog-operator --namespace="${namespace}" -o yaml && return
olm::util::await_csv_success "${namespace}" "packageserver" 32 || return
}
4 changes: 2 additions & 2 deletions test/e2e/bundle_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ var _ = Describe("Installing bundles with new object types", func() {
}).Should(Succeed())

// Wait for the CatalogSource to be ready
_, err = fetchCatalogSourceOnStatus(operatorClient, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced)
_, err = fetchCatalogSourceOnStatus(operatorClient, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred(), "catalog source did not become ready")

// Create a Subscription for package
_ = createSubscriptionForCatalog(operatorClient, source.GetNamespace(), subName, source.GetName(), packageName, channelName, "", v1alpha1.ApprovalAutomatic)

// Wait for the Subscription to succeed
sub, err := fetchSubscription(operatorClient, generatedNamespace.GetName(), subName, subscriptionStateAtLatestChecker)
sub, err := fetchSubscription(operatorClient, generatedNamespace.GetName(), subName, subscriptionStateAtLatestChecker())
Expect(err).ToNot(HaveOccurred(), "could not get subscription at latest status")

installPlanRef := sub.Status.InstallPlanRef
Expand Down
38 changes: 19 additions & 19 deletions test/e2e/catalog_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
defer cleanupSource()

// ensure the mock catalog exists and has been synced by the catalog operator
catalogSource, err := fetchCatalogSourceOnStatus(crc, catalogSourceName, ns.GetName(), catalogSourceRegistryPodSynced)
catalogSource, err := fetchCatalogSourceOnStatus(crc, catalogSourceName, ns.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ShouldNot(HaveOccurred())

// get catalog operator deployment
Expand Down Expand Up @@ -180,7 +180,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
defer cleanup()

// Attempt to get the catalog source before creating install plan
_, err := fetchCatalogSourceOnStatus(crc, cs.GetName(), cs.GetNamespace(), catalogSourceRegistryPodSynced)
_, err := fetchCatalogSourceOnStatus(crc, cs.GetName(), cs.GetNamespace(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred())

subscriptionSpec := &v1alpha1.SubscriptionSpec{
Expand All @@ -196,7 +196,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
subscriptionName := genName("sub-")
createSubscriptionForCatalogWithSpec(GinkgoT(), crc, ns.GetName(), subscriptionName, subscriptionSpec)

subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker())
Expect(err).ShouldNot(HaveOccurred())
Expect(subscription).ToNot(BeNil())

Expand Down Expand Up @@ -232,10 +232,10 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
updateInternalCatalog(GinkgoT(), c, crc, cs.GetName(), cs.GetNamespace(), []apiextensions.CustomResourceDefinition{mainCRD}, []v1alpha1.ClusterServiceVersion{mainCSV, replacementCSV}, mainManifests)

// Get updated catalogsource
fetchedUpdatedCatalog, err := fetchCatalogSourceOnStatus(crc, cs.GetName(), cs.GetNamespace(), catalogSourceRegistryPodSynced)
fetchedUpdatedCatalog, err := fetchCatalogSourceOnStatus(crc, cs.GetName(), cs.GetNamespace(), catalogSourceRegistryPodSynced())
Expect(err).ShouldNot(HaveOccurred())

subscription, err = fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateUpgradePendingChecker)
subscription, err = fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateUpgradePendingChecker())
Expect(err).ShouldNot(HaveOccurred())
Expect(subscription).ShouldNot(BeNil())

Expand Down Expand Up @@ -298,7 +298,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
createInternalCatalogSource(c, crc, mainCatalogName, ns.GetName(), mainManifests, nil, []v1alpha1.ClusterServiceVersion{mainCSV})

// Attempt to get the catalog source before creating install plan
fetchedInitialCatalog, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
fetchedInitialCatalog, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ShouldNot(HaveOccurred())

// Get initial configmap
Expand Down Expand Up @@ -361,7 +361,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
subscriptionName := genName("sub-")
createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, fetchedUpdatedCatalog.GetName(), mainPackageName, stableChannel, "", v1alpha1.ApprovalAutomatic)

subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker())
Expect(err).ShouldNot(HaveOccurred())
Expect(subscription).ShouldNot(BeNil())
_, err = fetchCSV(crc, subscription.Status.CurrentCSV, ns.GetName(), buildCSVConditionChecker(v1alpha1.CSVPhaseSucceeded))
Expand Down Expand Up @@ -431,7 +431,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
_, cleanupSource := createInternalCatalogSource(c, crc, mainCatalogName, ns.GetName(), mainManifests, nil, []v1alpha1.ClusterServiceVersion{mainCSV})

// Attempt to get the catalog source before creating install plan
fetchedInitialCatalog, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
fetchedInitialCatalog, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ShouldNot(HaveOccurred())
// Get initial configmap
configMap, err := c.KubernetesInterface().CoreV1().ConfigMaps(ns.GetName()).Get(context.Background(), fetchedInitialCatalog.Spec.ConfigMap, metav1.GetOptions{})
Expand All @@ -452,7 +452,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
subscriptionName := genName("sub-")
createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", v1alpha1.ApprovalAutomatic)

subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker())
Expect(err).ShouldNot(HaveOccurred())
Expect(subscription).ToNot(BeNil())
_, err = fetchCSV(crc, subscription.Status.CurrentCSV, ns.GetName(), buildCSVConditionChecker(v1alpha1.CSVPhaseSucceeded))
Expand Down Expand Up @@ -540,9 +540,9 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
createInternalCatalogSource(c, crc, replacementSourceName, ns.GetName(), append(replacementManifests, dependentManifests...), []apiextensions.CustomResourceDefinition{dependentCRD}, []v1alpha1.ClusterServiceVersion{replacementCSV, mainCSV, dependentCSV})

// Wait for ConfigMap CatalogSources to be ready
mainSource, err := fetchCatalogSourceOnStatus(crc, mainSourceName, ns.GetName(), catalogSourceRegistryPodSynced)
mainSource, err := fetchCatalogSourceOnStatus(crc, mainSourceName, ns.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ShouldNot(HaveOccurred())
replacementSource, err := fetchCatalogSourceOnStatus(crc, replacementSourceName, ns.GetName(), catalogSourceRegistryPodSynced)
replacementSource, err := fetchCatalogSourceOnStatus(crc, replacementSourceName, ns.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ShouldNot(HaveOccurred())

// Replicate catalog pods with no OwnerReferences
Expand Down Expand Up @@ -580,7 +580,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
}()

// Wait for the CatalogSource to be ready
_, err = fetchCatalogSourceOnStatus(crc, addressSource.GetName(), addressSource.GetNamespace(), catalogSourceRegistryPodSynced)
_, err = fetchCatalogSourceOnStatus(crc, addressSource.GetName(), addressSource.GetNamespace(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred(), "catalog source did not become ready")

// Delete CatalogSources
Expand All @@ -594,7 +594,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
cleanupSubscription := createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, addressSourceName, mainPackageName, stableChannel, "", v1alpha1.ApprovalAutomatic)
defer cleanupSubscription()

subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker())
Expect(err).ShouldNot(HaveOccurred())
Expect(subscription).ShouldNot(BeNil())
_, err = fetchCSV(crc, subscription.Status.CurrentCSV, ns.GetName(), csvSucceededChecker)
Expand Down Expand Up @@ -783,7 +783,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
Expect(err).ShouldNot(HaveOccurred())

By("Wait for the CatalogSource to be ready")
source, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced)
source, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred(), "catalog source did not become ready")

// the gRPC endpoints are not exposed from the pod, and there's no simple way to get at them -
Expand Down Expand Up @@ -923,7 +923,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
defer cleanupSubscription()

// Wait for the Subscription to succeed
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker())
Expect(err).ShouldNot(HaveOccurred())
Expect(subscription).ShouldNot(BeNil())

Expand Down Expand Up @@ -1088,7 +1088,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
}()

By("waiting for the CatalogSource to be ready")
_, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced)
_, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred(), "catalog source did not become ready")

By("creating a Subscription for busybox")
Expand All @@ -1097,7 +1097,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
defer cleanupSubscription()

By("waiting for the Subscription to succeed")
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionStateAtLatestChecker())
Expect(err).ShouldNot(HaveOccurred())
Expect(subscription).ShouldNot(BeNil())
Expect(subscription.Status.InstalledCSV).To(Equal("busybox.v1.0.0"))
Expand All @@ -1114,7 +1114,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
Expect(dependencySubscriptionName).ToNot(BeEmpty())

By("waiting for the Subscription to succeed")
subscription, err = fetchSubscription(crc, ns.GetName(), dependencySubscriptionName, subscriptionStateAtLatestChecker)
subscription, err = fetchSubscription(crc, ns.GetName(), dependencySubscriptionName, subscriptionStateAtLatestChecker())
Expect(err).ShouldNot(HaveOccurred())
Expect(subscription).ShouldNot(BeNil())
Expect(subscription.Status.InstalledCSV).To(Equal("busybox-dependency.v1.0.0"))
Expand All @@ -1132,7 +1132,7 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
}).Should(Succeed())

By("waiting for the CatalogSource to be ready")
_, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced)
_, err = fetchCatalogSourceOnStatus(crc, source.GetName(), source.GetNamespace(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred(), "catalog source did not become ready")

By("waiting for the busybox v2 Subscription to succeed")
Expand Down
17 changes: 9 additions & 8 deletions test/e2e/crd_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ var _ = Describe("CRD Versions", func() {
}()

// Attempt to get the catalog source before creating install plan
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred())

subscriptionName := genName("sub-nginx-update2-")
subscriptionCleanup := createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
defer subscriptionCleanup()

subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker())
Expect(err).ToNot(HaveOccurred())
Expect(subscription).ToNot(Equal(nil))
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
Expand Down Expand Up @@ -231,14 +231,14 @@ var _ = Describe("CRD Versions", func() {
}()

// Attempt to get the catalog source before creating install plan
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
_, err := fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred())

subscriptionName := genName("sub-nginx-update2-")
subscriptionCleanup := createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)
defer subscriptionCleanup()

subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker())
Expect(err).ToNot(HaveOccurred())
Expect(subscription).ToNot(BeNil())
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
Expand All @@ -261,8 +261,9 @@ var _ = Describe("CRD Versions", func() {
})).Should(Succeed())
ctx.Ctx().Logf("updated subscription to point to alpha channel")

checker := subscriptionStateAtLatestChecker()
subscriptionAtLatestWithDifferentInstallPlan := func(v *operatorsv1alpha1.Subscription) bool {
return subscriptionStateAtLatestChecker(v) && v.Status.InstallPlanRef != nil && v.Status.InstallPlanRef.Name != fetchedInstallPlan.Name
return checker(v) && v.Status.InstallPlanRef != nil && v.Status.InstallPlanRef.Name != fetchedInstallPlan.Name
}

// fetch new subscription
Expand Down Expand Up @@ -421,13 +422,13 @@ var _ = Describe("CRD Versions", func() {
defer cleanupMainCatalogSource()

// Attempt to get the catalog source before creating install plan
_, err = fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced)
_, err = fetchCatalogSourceOnStatus(crc, mainCatalogName, ns.GetName(), catalogSourceRegistryPodSynced())
Expect(err).ToNot(HaveOccurred())

subscriptionName := genName("sub-nginx-update2-")
_ = createSubscriptionForCatalog(crc, ns.GetName(), subscriptionName, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)

subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker)
subscription, err := fetchSubscription(crc, ns.GetName(), subscriptionName, subscriptionHasInstallPlanChecker())
Expect(err).ToNot(HaveOccurred())
Expect(subscription).ToNot(BeNil())
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
Expand Down Expand Up @@ -467,7 +468,7 @@ var _ = Describe("CRD Versions", func() {
subscriptionNameNew := genName("sub-nginx-update2-new-")
_ = createSubscriptionForCatalog(crc, ns.GetName(), subscriptionNameNew, mainCatalogName, mainPackageName, stableChannel, "", operatorsv1alpha1.ApprovalAutomatic)

subscription, err = fetchSubscription(crc, ns.GetName(), subscriptionNameNew, subscriptionHasInstallPlanChecker)
subscription, err = fetchSubscription(crc, ns.GetName(), subscriptionNameNew, subscriptionHasInstallPlanChecker())
Expect(err).ToNot(HaveOccurred())
Expect(subscription).ToNot(BeNil())
Expect(subscription.Status.InstallPlanRef).ToNot(Equal(nil))
Expand Down
Loading

0 comments on commit 44935f1

Please sign in to comment.