Skip to content

Commit 38b521a

Browse files
UPSTREAM: <carry>: Adds ResourceVersion checks to the tls secret deletion test, mirroring the logic used in the certificate rotation test. This makes the test more robust by ensuring a new secret is created, not just that an existing one is still present.
1 parent dbad83e commit 38b521a

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

openshift/tests-extension/test/webhooks.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,16 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServi
240240

241241
It("should be tolerant to tls secret deletion", func(ctx SpecContext) {
242242
certificateSecretName := webhookServiceCert
243-
By("ensuring secret exists before deletion attempt")
243+
var oldSecretResourceVersion string
244+
245+
By("ensuring secret exists before deletion attempt and getting its ResourceVersion")
244246
Eventually(func(g Gomega) {
245247
secret := &corev1.Secret{}
246248
err := k8sClient.Get(ctx, client.ObjectKey{Name: certificateSecretName, Namespace: webhookOperatorInstallNamespace}, secret)
247249
g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get secret %s/%s", webhookOperatorInstallNamespace, certificateSecretName))
248-
}).WithTimeout(1 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
250+
oldSecretResourceVersion = secret.ResourceVersion
251+
g.Expect(oldSecretResourceVersion).ToNot(BeEmpty(), "expected secret ResourceVersion to not be empty")
252+
}).WithTimeout(5 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
249253

250254
By("checking webhook is responsive through secret recreation after manual deletion")
251255
tlsSecret := &corev1.Secret{
@@ -286,6 +290,7 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServi
286290
return
287291
}
288292
g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get webhook service certificate secret %s/%s: %v", webhookOperatorInstallNamespace, certificateSecretName, err))
293+
g.Expect(secret.ResourceVersion).ToNot(Equal(oldSecretResourceVersion), "expected secret ResourceVersion to be different from the old one")
289294
g.Expect(secret.Data).ToNot(BeEmpty(), "expected webhook service certificate secret data to not be empty after recreation")
290295
}).WithTimeout(5*time.Minute).WithPolling(10*time.Second).Should(Succeed(), "webhook service certificate secret did not get recreated and populated within timeout")
291296

@@ -396,6 +401,38 @@ func setupWebhookOperator(ctx SpecContext, k8sClient client.Client, webhookOpera
396401
g.Expect(secret.Data).ToNot(BeEmpty(), "expected webhook service certificate secret data to not be empty")
397402
}).WithTimeout(5*time.Minute).WithPolling(5*time.Second).Should(Succeed(), "webhook service certificate secret did not become available within timeout")
398403

404+
By("waiting for the webhook operator's pod to be running and ready")
405+
Eventually(func(g Gomega) {
406+
podList := &corev1.PodList{}
407+
listOpts := []client.ListOption{
408+
client.InNamespace(webhookOperatorInstallNamespace),
409+
// Assuming the webhook operator pod has a label like app.kubernetes.io/name=webhook-operator
410+
// You might need to adjust this label selector based on your actual operator's labels.
411+
client.MatchingLabels{"app.kubernetes.io/name": webhookOperatorPackageName},
412+
}
413+
err := k8sClient.List(ctx, podList, listOpts...)
414+
g.Expect(err).ToNot(HaveOccurred(), "failed to list pods in namespace")
415+
g.Expect(podList.Items).ToNot(BeEmpty(), "expected to find at least one webhook operator pod")
416+
417+
// Check the first pod in the list. In a typical operator setup, there should be only one pod
418+
// or multiple pods if it's a deployment with multiple replicas.
419+
// For simplicity, we check the first one, but a more robust check might iterate through all
420+
// pods if multiple are expected.
421+
pod := podList.Items[0]
422+
g.Expect(pod.Status.Phase).To(Equal(corev1.PodRunning), fmt.Sprintf("expected pod %s to be running, but got %s", pod.Name, pod.Status.Phase))
423+
424+
// Check all container statuses within the pod to ensure they are ready
425+
allContainersReady := true
426+
for _, condition := range pod.Status.Conditions {
427+
if condition.Type == corev1.PodReady && condition.Status != corev1.ConditionTrue {
428+
allContainersReady = false
429+
break
430+
}
431+
}
432+
g.Expect(allContainersReady).To(BeTrue(), fmt.Sprintf("expected all containers in pod %s to be ready", pod.Name))
433+
434+
}).WithTimeout(5*time.Minute).WithPolling(10*time.Second).Should(Succeed(), "webhook operator pod did not become running and ready within timeout")
435+
399436
return func(ctx context.Context) {
400437
By(fmt.Sprintf("cleanup: deleting ClusterExtension %s", ce.Name))
401438
_ = k8sClient.Delete(ctx, ce, client.PropagationPolicy(metav1.DeletePropagationBackground))

0 commit comments

Comments
 (0)