Skip to content

Commit 6c01fc2

Browse files
neiswci-robot
authored andcommitted
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.
This reverts commit 0bb1953. UPSTREAM: <carry>: [OTE] Add webhook to validate openshift-service-ca certificate rotation This reverts commit e9e3220.
1 parent 90a5ca9 commit 6c01fc2

File tree

2 files changed

+7
-93
lines changed

2 files changed

+7
-93
lines changed

openshift/tests-extension/.openshift-tests-extension/openshift_payload_olmv1.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,6 @@
278278
"lifecycle": "blocking",
279279
"environmentSelector": {}
280280
},
281-
{
282-
"name": "[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServiceCA][Skipped:Disconnected][Serial] OLMv1 operator with webhooks should be tolerant to openshift-service-ca certificate rotation",
283-
"labels": {},
284-
"resources": {
285-
"isolation": {}
286-
},
287-
"source": "openshift:payload:olmv1",
288-
"lifecycle": "blocking",
289-
"environmentSelector": {}
290-
},
291281
{
292282
"name": "[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServiceCA][Skipped:Disconnected][Serial] OLMv1 operator with webhooks should be tolerant to tls secret deletion",
293283
"labels": {},

openshift/tests-extension/test/webhooks.go

Lines changed: 7 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ import (
2929
)
3030

3131
const (
32-
openshiftServiceCANamespace = "openshift-service-ca"
33-
openshiftServiceCASigningKeySecretName = "signing-key"
34-
webhookCatalogName = "webhook-operator-catalog"
35-
webhookOperatorPackageName = "webhook-operator"
36-
webhookOperatorCRDName = "webhooktests.webhook.operators.coreos.io"
37-
webhookServiceCert = "webhook-operator-webhook-service-cert"
32+
webhookCatalogName = "webhook-operator-catalog"
33+
webhookOperatorPackageName = "webhook-operator"
34+
webhookOperatorCRDName = "webhooktests.webhook.operators.coreos.io"
35+
webhookServiceCert = "webhook-operator-webhook-service-cert"
3836
)
3937

4038
var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServiceCA][Skipped:Disconnected][Serial] OLMv1 operator with webhooks",
@@ -86,6 +84,7 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServi
8684
helpers.DescribeAllClusterCatalogs(ctx)
8785
helpers.DescribeAllClusterExtensions(ctx, webhookOperatorInstallNamespace)
8886
By("dumping webhook diagnostics")
87+
// Additional diagnostics specific for this test
8988
helpers.RunAndPrint(ctx, "get", "mutatingwebhookconfigurations.admissionregistration.k8s.io", "-oyaml")
9089
helpers.RunAndPrint(ctx, "get", "validatingwebhookconfigurations.admissionregistration.k8s.io", "-oyaml")
9190
}
@@ -168,88 +167,14 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServi
168167
}))
169168
})
170169

171-
It("should be tolerant to openshift-service-ca certificate rotation", func(ctx SpecContext) {
172-
certificateSecretName := webhookServiceCert
173-
var oldSecretResourceVersion string
174-
175-
By("ensuring the webhook operator's service certificate secret exists and getting its ResourceVersion")
176-
Eventually(func(g Gomega) {
177-
secret := &corev1.Secret{}
178-
err := k8sClient.Get(ctx, client.ObjectKey{Name: certificateSecretName, Namespace: webhookOperatorInstallNamespace}, secret)
179-
g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get webhook service certificate secret %s/%s", webhookOperatorInstallNamespace, certificateSecretName))
180-
g.Expect(secret.Data).ToNot(BeEmpty(), "expected webhook service certificate secret data to not be empty")
181-
oldSecretResourceVersion = secret.ResourceVersion
182-
g.Expect(oldSecretResourceVersion).ToNot(BeEmpty(), "expected secret ResourceVersion to not be empty")
183-
}).WithTimeout(3 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
184-
185-
By("deleting the openshift-service-ca signing-key secret")
186-
signingKeySecret := &corev1.Secret{
187-
ObjectMeta: metav1.ObjectMeta{
188-
Name: openshiftServiceCASigningKeySecretName,
189-
Namespace: openshiftServiceCANamespace,
190-
},
191-
}
192-
err := k8sClient.Delete(ctx, signingKeySecret, client.PropagationPolicy(metav1.DeletePropagationBackground))
193-
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())
194-
195-
By("waiting for the webhook operator's service certificate secret to be recreated with a new ResourceVersion")
196-
Eventually(func(g Gomega) {
197-
secret := &corev1.Secret{}
198-
err := k8sClient.Get(ctx, client.ObjectKey{Name: certificateSecretName, Namespace: webhookOperatorInstallNamespace}, secret)
199-
if apierrors.IsNotFound(err) {
200-
GinkgoLogr.Info(fmt.Sprintf("Secret %s/%s not found yet (still polling for recreation)", webhookOperatorInstallNamespace, certificateSecretName))
201-
return
202-
}
203-
g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get webhook service certificate secret %s/%s: %v", webhookOperatorInstallNamespace, certificateSecretName, err))
204-
g.Expect(secret.ResourceVersion).ToNot(Equal(oldSecretResourceVersion), "expected secret ResourceVersion to be different from the old one")
205-
g.Expect(secret.Data).ToNot(BeEmpty(), "expected webhook service certificate secret data to not be empty after recreation")
206-
}).WithTimeout(5*time.Minute).WithPolling(10*time.Second).Should(Succeed(), "webhook service certificate secret did not get recreated with a new ResourceVersion and populated within timeout")
207-
208-
By("checking webhook is responsive through cert rotation")
209-
Eventually(func(g Gomega) {
210-
resourceName := fmt.Sprintf("cert-rotation-test-%s", rand.String(5))
211-
resource := newWebhookTest(resourceName, webhookOperatorInstallNamespace, true)
212-
213-
_, err := dynamicClient.Resource(webhookTestV1).Namespace(webhookOperatorInstallNamespace).Create(ctx, resource, metav1.CreateOptions{})
214-
g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to create test resource %s: %v", resourceName, err))
215-
216-
err = dynamicClient.Resource(webhookTestV1).Namespace(webhookOperatorInstallNamespace).Delete(ctx, resource.GetName(), metav1.DeleteOptions{})
217-
g.Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred(), fmt.Sprintf("failed to delete test resource %s: %v", resourceName, err))
218-
}).WithTimeout(5 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())
219-
220-
DeferCleanup(func() {
221-
// Specific check for this test
222-
if CurrentSpecReport().Failed() {
223-
By("dumping certificate details for debugging")
224-
secret := &corev1.Secret{}
225-
if err := k8sClient.Get(ctx, client.ObjectKey{
226-
Name: webhookServiceCert,
227-
Namespace: webhookOperatorInstallNamespace,
228-
}, secret); err == nil {
229-
if crt, ok := secret.Data["tls.crt"]; ok && len(crt) > 0 {
230-
printTLSCertInfo(crt)
231-
} else {
232-
_, _ = GinkgoWriter.Write([]byte("[diag] tls.crt key not found or empty in secret\n"))
233-
}
234-
} else {
235-
fmt.Fprintf(GinkgoWriter, "[diag] failed to get secret for cert dump: %v\n", err)
236-
}
237-
}
238-
})
239-
})
240-
241170
It("should be tolerant to tls secret deletion", func(ctx SpecContext) {
242171
certificateSecretName := webhookServiceCert
243-
var oldSecretResourceVersion string
244-
245-
By("ensuring secret exists before deletion attempt and getting its ResourceVersion")
172+
By("ensuring secret exists before deletion attempt")
246173
Eventually(func(g Gomega) {
247174
secret := &corev1.Secret{}
248175
err := k8sClient.Get(ctx, client.ObjectKey{Name: certificateSecretName, Namespace: webhookOperatorInstallNamespace}, secret)
249176
g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get secret %s/%s", webhookOperatorInstallNamespace, certificateSecretName))
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())
177+
}).WithTimeout(1 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
253178

254179
By("checking webhook is responsive through secret recreation after manual deletion")
255180
tlsSecret := &corev1.Secret{
@@ -290,7 +215,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServi
290215
return
291216
}
292217
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")
294218
g.Expect(secret.Data).ToNot(BeEmpty(), "expected webhook service certificate secret data to not be empty after recreation")
295219
}).WithTimeout(5*time.Minute).WithPolling(10*time.Second).Should(Succeed(), "webhook service certificate secret did not get recreated and populated within timeout")
296220

0 commit comments

Comments
 (0)