3

I have an image of java code that does database validation and the job uses that image. I want the job to intentionally fail when the database validation fails. Is there any way to do the same?

Darshil Shah
  • 447
  • 1
  • 11
  • 21

1 Answers1

4

A Kubernetes job is just a contrainer running. As with any container, the final exit code determines if the run was successful or not. So, to make your job fail you need to exit with a code other than 0.

How would you do this in Java?

System.exit(1)

How would you do this in Bash scripting?

exit 1

How would you do this in Node.js?

process.exit(1)

How would you do this in Python/PHP?

exit(1)

How would you do this in Go?

os.Exit(1)
george.yord
  • 3,002
  • 2
  • 15
  • 7
  • I tried both `process.exit(0)` and `node index.js ; exit $?`, but the job keeps running until `activeDeadlineSeconds` was hit and terminated as a failure... – paulz Mar 03 '23 at 00:10