Skip to content

Commit 3ffbd2e

Browse files
authored
ci(e2e): harden release gate setup (#462)
Signed-off-by: Roel de Cort <roel.decort@adfinis.com>
1 parent 244084e commit 3ffbd2e

2 files changed

Lines changed: 92 additions & 11 deletions

File tree

.github/actions/prepare-e2e-lane/action.yml

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,39 @@ runs:
9595
run: |
9696
set -euo pipefail
9797
98-
docker pull "${MANAGER_IMAGE}"
99-
docker pull "${CONFIG_INIT_IMAGE}"
98+
pull_image() {
99+
local image="$1"
100+
local max_attempts=5
101+
local delay_seconds=5
102+
local attempt
103+
104+
for (( attempt = 1; attempt <= max_attempts; attempt++ )); do
105+
if docker pull "${image}"; then
106+
return 0
107+
fi
108+
109+
if (( attempt == max_attempts )); then
110+
echo "docker pull failed for ${image} after ${max_attempts} attempts" >&2
111+
return 1
112+
fi
113+
114+
echo "docker pull failed for ${image} (attempt ${attempt}/${max_attempts}); retrying in ${delay_seconds}s" >&2
115+
sleep "${delay_seconds}"
116+
delay_seconds=$(( delay_seconds * 2 ))
117+
done
118+
}
119+
120+
pull_image "${MANAGER_IMAGE}"
121+
pull_image "${CONFIG_INIT_IMAGE}"
100122
101123
if [[ "${LOAD_BACKUP_EXECUTOR_IMAGE}" == "true" ]]; then
102-
docker pull "${BACKUP_EXECUTOR_IMAGE}"
124+
pull_image "${BACKUP_EXECUTOR_IMAGE}"
103125
fi
104126
105127
if [[ "${LOAD_UPGRADE_EXECUTOR_IMAGE}" == "true" ]] && [[ -n "${HARDENED_UPGRADE_EXECUTOR_IMAGE}" ]]; then
106-
docker pull "${HARDENED_UPGRADE_EXECUTOR_IMAGE}"
128+
pull_image "${HARDENED_UPGRADE_EXECUTOR_IMAGE}"
107129
elif [[ "${LOAD_UPGRADE_EXECUTOR_IMAGE}" == "true" ]]; then
108-
docker pull "${UPGRADE_EXECUTOR_IMAGE}"
130+
pull_image "${UPGRADE_EXECUTOR_IMAGE}"
109131
fi
110132
111133
- name: Create Kind cluster
@@ -135,6 +157,28 @@ runs:
135157
run: |
136158
set -euo pipefail
137159
160+
pull_image() {
161+
local image="$1"
162+
local max_attempts=5
163+
local delay_seconds=5
164+
local attempt
165+
166+
for (( attempt = 1; attempt <= max_attempts; attempt++ )); do
167+
if docker pull "${image}"; then
168+
return 0
169+
fi
170+
171+
if (( attempt == max_attempts )); then
172+
echo "docker pull failed for ${image} after ${max_attempts} attempts" >&2
173+
return 1
174+
fi
175+
176+
echo "docker pull failed for ${image} (attempt ${attempt}/${max_attempts}); retrying in ${delay_seconds}s" >&2
177+
sleep "${delay_seconds}"
178+
delay_seconds=$(( delay_seconds * 2 ))
179+
done
180+
}
181+
138182
resolve_image() {
139183
local output_name="$1"
140184
local preload="$2"
@@ -147,7 +191,7 @@ runs:
147191
fi
148192
149193
if [[ "${PRELOAD_STORAGE_EMULATORS}" == "true" ]] && [[ "${preload}" == "true" ]]; then
150-
docker pull "${source_image}"
194+
pull_image "${source_image}"
151195
docker tag "${source_image}" "${loaded_image}"
152196
kind load docker-image "${loaded_image}" --name "${KIND_CLUSTER}"
153197
echo "${output_name}=${loaded_image}" >> "${GITHUB_OUTPUT}"

test/e2e/Cluster_Profile_Hardened_test.go

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,42 @@ var _ = Describe("Hardened profile (External TLS + Transit auto-unseal + SelfIni
7676
}, framework.DefaultWaitTimeout, framework.DefaultPollInterval).Should(Succeed())
7777
}
7878

79+
waitForNetworkPolicy := func(name types.NamespacedName, timeout, pollInterval time.Duration) error {
80+
deadline := time.Now().Add(timeout)
81+
var lastErr error
82+
83+
for {
84+
np := &networkingv1.NetworkPolicy{}
85+
err := c.Get(ctx, name, np)
86+
if err == nil {
87+
return nil
88+
}
89+
if !apierrors.IsNotFound(err) {
90+
return err
91+
}
92+
lastErr = err
93+
94+
if time.Now().After(deadline) {
95+
return fmt.Errorf("timed out waiting for NetworkPolicy %s/%s: %w", name.Namespace, name.Name, lastErr)
96+
}
97+
98+
select {
99+
case <-ctx.Done():
100+
return ctx.Err()
101+
case <-time.After(pollInterval):
102+
}
103+
}
104+
}
105+
106+
dumpNetworkPolicyDiagnostics := func(namespace, clusterName string) {
107+
_, _ = fmt.Fprintf(GinkgoWriter, "\n========== NetworkPolicy Diagnostics (%s/%s) ==========\n", namespace, clusterName)
108+
dumpKubectlOutput("get", "openbaocluster", clusterName, "-n", namespace, "-o", "yaml")
109+
dumpKubectlOutput("get", "networkpolicies", "-n", namespace, "-o", "wide")
110+
dumpKubectlOutput("get", "pods", "-n", namespace, "-l", fmt.Sprintf("%s=%s", constants.LabelOpenBaoCluster, clusterName), "-o", "wide")
111+
dumpKubectlOutput("get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
112+
dumpKubectlOutput("logs", "deployment/openbao-operator-controller", "-n", operatorNamespace, "--tail=400")
113+
}
114+
79115
ensureTransitTokenSecret := func() {
80116
By("creating transit token secret with CA certificate for TLS verification")
81117
infraBaoCACert, err := e2ehelpers.ReadInfraBaoTLSCACert(ctx, c, f.Namespace, infraBaoName)
@@ -409,11 +445,12 @@ var _ = Describe("Hardened profile (External TLS + Transit auto-unseal + SelfIni
409445
_, _ = fmt.Fprintf(GinkgoWriter, "OpenBaoCluster %q observed by API server\n", clusterName)
410446

411447
By("verifying NetworkPolicy was created")
412-
Eventually(func(g Gomega) {
413-
np := &networkingv1.NetworkPolicy{}
414-
npName := types.NamespacedName{Name: clusterName + "-network-policy", Namespace: f.Namespace}
415-
g.Expect(c.Get(ctx, npName, np)).To(Succeed())
416-
}, 30*time.Second, 2*time.Second).Should(Succeed())
448+
npName := types.NamespacedName{Name: clusterName + "-network-policy", Namespace: f.Namespace}
449+
err = waitForNetworkPolicy(npName, framework.DefaultWaitTimeout, framework.DefaultPollInterval)
450+
if err != nil {
451+
dumpNetworkPolicyDiagnostics(f.Namespace, clusterName)
452+
}
453+
Expect(err).NotTo(HaveOccurred())
417454
_, _ = fmt.Fprintf(GinkgoWriter, "NetworkPolicy created successfully\n")
418455

419456
By("checking for prerequisite resources (ConfigMap and TLS Secrets)")

0 commit comments

Comments
 (0)