Skip to content

Commit c55432d

Browse files
committed
tests: Wait for webhook to serve new cert after recovery
The certificate recovery tests (certificates_test.go) verify that a deleted secret/caBundle gets regenerated, but do not wait for the webhook server to actually reload and serve the new certificate. Due to kubelet secret volume propagation delay (~60s), subsequent tests can hit "x509: certificate signed by unknown authority" if they call the webhook before the new cert is in place. Add a probe in checkCertLibraryRecovery that creates a VM via the webhook and retries until it succeeds, ensuring the new certificate is fully operational before the test completes. Assisted-by: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Ram Lavi <ralavi@redhat.com>
1 parent a5e4c50 commit c55432d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/certificates_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
v1 "k8s.io/api/core/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
"k8s.io/client-go/util/retry"
12+
kubevirtv1 "kubevirt.io/api/core/v1"
13+
"sigs.k8s.io/controller-runtime/pkg/client"
1214

1315
"github.com/k8snetworkplumbingwg/kubemacpool/pkg/names"
1416
)
@@ -79,6 +81,9 @@ func checkCertLibraryRecovery(oldCABundle []byte, oldSecret *v1.Secret) {
7981

8082
By("checking that the caBundle is regenerated")
8183
checkCaBundleRecovery(oldCABundle)
84+
85+
By("waiting for webhook to serve the new certificate")
86+
waitForWebhookWithNewCert()
8287
}
8388

8489
func GetCurrentSecret(secretName string) (*v1.Secret, error) {
@@ -120,3 +125,13 @@ func checkCaBundleRecovery(oldCABundle []byte) {
120125
return caBundles, nil
121126
}, timeout, pollingInterval).ShouldNot(ContainElement(oldCABundle), "should successfully renew all webhook's caBundles")
122127
}
128+
129+
func waitForWebhookWithNewCert() {
130+
Eventually(func(g Gomega) {
131+
vm := CreateVMObject(TestNamespace,
132+
[]kubevirtv1.Interface{newInterface("br", "")},
133+
[]kubevirtv1.Network{newNetwork("br")})
134+
g.Expect(testClient.CRClient.Create(context.TODO(), vm, client.DryRunAll)).To(Succeed(),
135+
"webhook should accept requests with the new certificate")
136+
}, webhookPropagationTimeout, webhookPropagationInterval).Should(Succeed())
137+
}

0 commit comments

Comments
 (0)