githubEdit

Ensuring Kubernetes Jobs Show Correct Failure Status When Using Wrapper Scripts

When running Kubernetes Jobs or CronJobs that use wrapper scripts to execute the main application, it's important to properly propagate exit codes to ensure job status is reported correctly in DuploCloud. Common Issue If your Job is using a wrapper script (such as one that sets up environment variables or fetches secrets) before running the main application, the wrapper script may not be propagating the exit code from the main application. This can cause Jobs to show as "Completed" in DuploCloud even when the main application fails. Solution When using subprocess to run the main application in your wrapper script, make sure to: Capture the return code from the subprocess.run() call Exit the wrapper script with the same return code Example Instead of: if args.command: subprocess.run(args.command, env=env) else: print("Error: No command provided", file=sys.stderr) sys.exit(1) Use: if args.command: result = subprocess.run(args.command, env=env) sys.exit(result.returncode) else: print("Error: No command provided", file=sys.stderr) sys.exit(1) Verification When properly configured, any non-zero exit code from your main application will be reflected in DuploCloud, showing the Job as "Failed" rather than "Completed". A Job that exits with code 0 will show as "Completed" in DuploCloud, while any non-zero exit code will show as "Failed".

Last updated

Was this helpful?