Skip to content

Commit 8a516df

Browse files
authored
e2etests, allow camo CSV checks to tolerate 1 transient failed request. (#451)
1 parent d8f3e8f commit 8a516df

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

test/e2e/configure_alertmanager_operator_tests.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package osde2etests
66

77
import (
88
"context"
9+
"fmt"
910
"time"
1011

1112
"github.com/onsi/ginkgo/v2"
@@ -33,6 +34,7 @@ var _ = Describe("Configure AlertManager Operator", Ordered, func() {
3334
serviceAccounts = []string{"configure-alertmanager-operator"}
3435
)
3536
const (
37+
maxCSVFailures = 1 //number of csv request failures before exiting
3638
timeoutDuration = 300 * time.Second
3739
pollingDuration = 30 * time.Second
3840
configMapLockFile = "configure-alertmanager-operator-lock"
@@ -50,21 +52,45 @@ var _ = Describe("Configure AlertManager Operator", Ordered, func() {
5052
dynamicClient, err = dynamic.NewForConfig(cfg)
5153
Expect(err).ShouldNot(HaveOccurred(), "failed to configure Dynamic client")
5254
})
53-
55+
// Allow for one CSV request failure before exiting Eventually() loop...
56+
csvErrCounter := 0
57+
startCSVCheck := time.Now()
5458
It("cluster service version exists", func(ctx context.Context) {
5559
Eventually(func(ctx context.Context) bool {
60+
elapsed := fmt.Sprintf("%f", time.Since(startCSVCheck).Seconds())
61+
GinkgoLogr.Info("CAMO CSV check", "secondsElapsed", elapsed)
5662
csvList, err := dynamicClient.Resource(
5763
schema.GroupVersionResource{
5864
Group: "operators.coreos.com",
5965
Version: "v1alpha1",
6066
Resource: "clusterserviceversions",
6167
},
6268
).Namespace(namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector})
63-
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve CSV from namespace %s", namespace)
64-
Expect(csvList.Items).Should(HaveLen(1))
65-
69+
if csvErrCounter >= maxCSVFailures {
70+
// If maxCSVFailures has been exceeded, handle errors with Expect()...
71+
csvErrCounter++
72+
GinkgoLogr.Error(err, fmt.Sprintf("CSV error counter: %d, tolerated errors: %d", csvErrCounter, maxCSVFailures))
73+
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve CSV from namespace %s", namespace)
74+
Expect(csvList.Items).Should(HaveLen(1))
75+
}
76+
if err != nil {
77+
GinkgoLogr.Error(err, fmt.Sprintf("Err, fetching CSV for NS:'%s' LABEL:'%s'", namespace, labelSelector))
78+
csvErrCounter++
79+
return false
80+
}
81+
if csvList == nil {
82+
GinkgoLogr.Error(nil, fmt.Sprintf("Err, nil CSV list fetching CSV for NS:'%s' LABEL:'%s'", namespace, labelSelector))
83+
csvErrCounter++
84+
return false
85+
}
86+
if len(csvList.Items) != 1 {
87+
GinkgoLogr.Error(nil, fmt.Sprintf("Err, expected 1 CSV for NS:'%s' LABEL:'%s'. Got %d", namespace, labelSelector, len(csvList.Items)))
88+
csvErrCounter++
89+
return false
90+
}
6691
statusPhase, _, _ := unstructured.NestedFieldCopy(csvList.Items[0].Object, "status", "phase")
6792
if statusPhase == "Succeeded" {
93+
GinkgoLogr.Info("csv phase", "phase", statusPhase)
6894
return true
6995
}
7096
GinkgoLogr.Info("csv phase", "phase", statusPhase)

0 commit comments

Comments
 (0)