From a0bd9e02ca765e20e4ff2cadf562e620863c4bd2 Mon Sep 17 00:00:00 2001 From: Dan Mihai Date: Sun, 2 Nov 2025 18:43:49 +0000 Subject: [PATCH] tests: policy-job: detect create container errors early During the ${wait_time} for an expected condition, if CreateContainerRequest was NOT expected to fail: detect possible CreateContainerRequest failures early and abort the wait. For example, before this change: not ok 1 Successful job with auto-generated policy in 107111ms ok 2 Policy failure: unexpected environment variable in 7920ms ok 3 Policy failure: unexpected command line argument in 7874ms ok 4 Policy failure: unexpected emptyDir volume in 7823ms ok 5 Policy failure: unexpected projected volume in 7812ms ok 6 Policy failure: unexpected readOnlyRootFilesystem in 7903ms ok 7 Policy failure: unexpected UID = 222 in 7720ms After this change: not ok 1 Successful job with auto-generated policy in 10271ms ok 2 Policy failure: unexpected environment variable in 8018ms ok 3 Policy failure: unexpected command line argument in 7886ms ok 4 Policy failure: unexpected emptyDir volume in 7621ms ok 5 Policy failure: unexpected projected volume in 7843ms ok 6 Policy failure: unexpected readOnlyRootFilesystem in 7632ms ok 7 Policy failure: unexpected UID = 222 in 7619ms Signed-off-by: Dan Mihai --- tests/integration/kubernetes/k8s-policy-job.bats | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/integration/kubernetes/k8s-policy-job.bats b/tests/integration/kubernetes/k8s-policy-job.bats index e3b7070fac..c388304291 100644 --- a/tests/integration/kubernetes/k8s-policy-job.bats +++ b/tests/integration/kubernetes/k8s-policy-job.bats @@ -38,13 +38,14 @@ setup() { # Wait for the job to be created cmd="kubectl describe job ${job_name} | grep SuccessfulCreate" - info "Waiting for: ${cmd}" - waitForProcess "${wait_time}" "${sleep_time}" "${cmd}" + abort_cmd="kubectl describe pod ${job_name} | grep \"CreateContainerRequest is blocked by policy\"" + info "Waiting ${wait_time}s with sleep ${sleep_time}s for: ${cmd}. Abort if: ${abort_cmd}." + waitForCmdWithAbortCmd "${wait_time}" "${sleep_time}" "${cmd}" "${abort_cmd}" # Wait for the job to complete cmd="kubectl get pods -o jsonpath='{.items[*].status.phase}' | grep Succeeded" - info "Waiting for: ${cmd}" - waitForProcess "${wait_time}" "${sleep_time}" "${cmd}" + info "Waiting ${wait_time}s with sleep ${sleep_time}s for: ${cmd}. Abort if: ${abort_cmd}." + waitForCmdWithAbortCmd "${wait_time}" "${sleep_time}" "${cmd}" "${abort_cmd}" } # Common function for all test cases that expect CreateContainer to be blocked by policy.