Fix container_restart_test AfterEach failing when CRI Proxy is undefined

Two test contexts were failing because their AfterEach blocks run even
when BeforeEach skips the test (standard Ginkgo behavior). This caused
resetCRIProxyInjector to fail with "CRI Proxy is undefined".

Switched to using DeferCleanup inside BeforeEach instead, which only
runs if BeforeEach succeeds. This is the same pattern the other test
contexts in this file already use.

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2026-01-23 17:47:17 -05:00
parent c7416f744e
commit 03e6622c92
No known key found for this signature in database
GPG key ID: 6DEA177048756885

View file

@ -100,11 +100,9 @@ var _ = SIGDescribe("Container Restart", feature.CriProxy, framework.WithSerial(
if err := resetCRIProxyInjector(e2eCriProxy); err != nil {
ginkgo.Skip("Skip the test since the CRI Proxy is undefined.")
}
})
ginkgo.AfterEach(func() {
err := resetCRIProxyInjector(e2eCriProxy)
framework.ExpectNoError(err)
ginkgo.DeferCleanup(func() error {
return resetCRIProxyInjector(e2eCriProxy)
})
})
ginkgo.It("Reduced default restart backs off.", func(ctx context.Context) {
@ -128,11 +126,9 @@ var _ = SIGDescribe("Container Restart", feature.CriProxy, framework.WithSerial(
if err := resetCRIProxyInjector(e2eCriProxy); err != nil {
ginkgo.Skip("Skip the test since the CRI Proxy is undefined.")
}
})
ginkgo.AfterEach(func() {
err := resetCRIProxyInjector(e2eCriProxy)
framework.ExpectNoError(err)
ginkgo.DeferCleanup(func() error {
return resetCRIProxyInjector(e2eCriProxy)
})
})
ginkgo.It("Reduced default restart backs off.", func(ctx context.Context) {