stern / stern

⎈ Multi pod and container log tailing for Kubernetes -- Friendly fork of https://github.com/wercker/stern
Apache License 2.0
3.41k stars 122 forks source link

When watching a batch job, automatically stop when it's finished #308

Open nogweii opened 5 months ago

nogweii commented 5 months ago

What would you like to be added: A variation of #37 , I would like stern to shut down when a job has finished running, either successful or not.

Why is this needed: I'd like to use stern as part of a sequence of commands for a script meant for manual observation - it would launch a new Job via kubectl apply and then have the logs tailed until it's finished, then clean up after itself.

superbrothers commented 3 months ago

As it is difficult to support the conditions of individual resources, it is practical to use scripts such as the following

stern my-job &
pid="$1"

// Wait for the job to finish

kill "$pid"