Skip to content

(HOLD) OPRUN-3941: Add webhook tests with enhancements and fixes #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServiceCA][Skipped:Disconnected][Serial] OLMv1 operator with webhooks should be tolerant to openshift-service-ca certificate rotation",
"labels": {},
"resources": {
"isolation": {}
},
"source": "openshift:payload:olmv1",
"lifecycle": "blocking",
"environmentSelector": {}
},
{
"name": "[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServiceCA][Skipped:Disconnected][Serial] OLMv1 operator with webhooks should be tolerant to tls secret deletion",
"labels": {},
Expand Down
49 changes: 44 additions & 5 deletions openshift/tests-extension/test/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import (
)

const (
webhookCatalogName = "webhook-operator-catalog"
webhookOperatorPackageName = "webhook-operator"
webhookOperatorCRDName = "webhooktests.webhook.operators.coreos.io"
webhookServiceCert = "webhook-operator-webhook-service-cert"
openshiftServiceCANamespace = "openshift-service-ca"
openshiftServiceCASigningKeySecretName = "signing-key"
webhookCatalogName = "webhook-operator-catalog"
webhookOperatorPackageName = "webhook-operator"
webhookOperatorCRDName = "webhooktests.webhook.operators.coreos.io"
webhookServiceCert = "webhook-operator-webhook-service-cert"
)

var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServiceCA][Skipped:Disconnected][Serial] OLMv1 operator with webhooks",
Expand Down Expand Up @@ -84,7 +86,6 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServi
helpers.DescribeAllClusterCatalogs(ctx)
helpers.DescribeAllClusterExtensions(ctx, webhookOperatorInstallNamespace)
By("dumping webhook diagnostics")
// Additional diagnostics specific for this test
helpers.RunAndPrint(ctx, "get", "mutatingwebhookconfigurations.admissionregistration.k8s.io", "-oyaml")
helpers.RunAndPrint(ctx, "get", "validatingwebhookconfigurations.admissionregistration.k8s.io", "-oyaml")
}
Expand Down Expand Up @@ -167,6 +168,44 @@ var _ = Describe("[sig-olmv1][OCPFeatureGate:NewOLMWebhookProviderOpenshiftServi
}))
})

It("should be tolerant to openshift-service-ca certificate rotation", func(ctx SpecContext) {
By("deleting the openshift-service-ca signing-key secret")
signingKeySecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: openshiftServiceCASigningKeySecretName,
Namespace: openshiftServiceCANamespace,
},
}
err := k8sClient.Delete(ctx, signingKeySecret, client.PropagationPolicy(metav1.DeletePropagationBackground))
Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred())

By("waiting for the webhook operator's service certificate secret to be recreated and populated")
certificateSecretName := webhookServiceCert
Eventually(func(g Gomega) {
secret := &corev1.Secret{}
err := k8sClient.Get(ctx, client.ObjectKey{Name: certificateSecretName, Namespace: webhookOperatorInstallNamespace}, secret)
if apierrors.IsNotFound(err) {
GinkgoLogr.Info(fmt.Sprintf("Secret %s/%s not found yet (still polling for recreation)", webhookOperatorInstallNamespace, certificateSecretName))
return
}

g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to get webhook service certificate secret %s/%s: %v", webhookOperatorInstallNamespace, certificateSecretName, err))
g.Expect(secret.Data).ToNot(BeEmpty(), "expected webhook service certificate secret data to not be empty after recreation")
}).WithTimeout(5*time.Minute).WithPolling(10*time.Second).Should(Succeed(), "webhook service certificate secret did not get recreated and populated within timeout")

By("checking webhook is responsive through cert rotation")
Eventually(func(g Gomega) {
resourceName := fmt.Sprintf("cert-rotation-test-%s", rand.String(5))
resource := newWebhookTest(resourceName, webhookOperatorInstallNamespace, true)

_, err := dynamicClient.Resource(webhookTestV1).Namespace(webhookOperatorInstallNamespace).Create(ctx, resource, metav1.CreateOptions{})
g.Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("failed to create test resource %s: %v", resourceName, err))

err = dynamicClient.Resource(webhookTestV1).Namespace(webhookOperatorInstallNamespace).Delete(ctx, resource.GetName(), metav1.DeleteOptions{})
g.Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred(), fmt.Sprintf("failed to delete test resource %s: %v", resourceName, err))
}).WithTimeout(5 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())
})

It("should be tolerant to tls secret deletion", func(ctx SpecContext) {
certificateSecretName := webhookServiceCert
By("ensuring secret exists before deletion attempt")
Expand Down