1

I have a test that launches a Pod to check that certain functionality exists within the cluster.

I want to launch the Pod with kubectl create then kubectl wait to get the container's exit code to determine the test's successfulness, with a fail-fast approach. I'm interested in pure kubectl solutions, as this is the portable unit between the test environments (shell scripts vary).

Other similar posts' answers assume that the Pod will succeed, so either use wait with:

  • --for jsonpath to check {.status.phase}=Succeeded
  • --for condition=Completed and wrap the Pod in a Job

The problem is that, if the test fails it waits for the full --timeout, which in my case can be a long time - time, resources and energy that are wasted if the Pod fails early.

I've explored using:

  • Any or conditionals, wait accepts multiple --for arguments, but only considers the final one
  • --for jsonpath='{.status.conditions[...].reason}'=PodCompleted, which doesn't work in a variety of formulations tried because can't filter to an individual .reason, or .reason doesn't exist immediately and results in an early error.
  • --for jsonpath='{.status.containerStatuses[0].state.terminated} as there's no field here that has an exact value to check against; there's no way to test for the presence of keys

Thanks

  • Check these answers https://stackoverflow.com/questions/55073453/wait-for-kubernetes-job-to-complete-on-either-failure-success-using-command-line – Rudy S Apr 18 '23 at 16:02
  • Thanks @RudyS, I had not seen this relevant post. Most of the answers rely on shell scripting and I'm looking for something that works inherently across platforms. I had tried the one that doesn't, https://stackoverflow.com/a/72900831/14693713, and it didn't work for my case in the end but I can't remember why not, so I'll give it another go :) – Dan McGreal Apr 26 '23 at 11:39

0 Answers0