david
david

Reputation: 825

Wait for kubernetes jobs to finish

Here is a list of jobs that i´m running:

>kubectl get jobs 
NAME                 COMPLETIONS   DURATION   AGE
create-samplenames   1/1           32s        25h
download-db          1/1           20s        26h
download-fastq       1/1           20s        26h
download-scripts     1/1           22s        32m
trimming-fasta-1     0/1           63s        63s
trimming-fasta-2     0/1           63s        63s
trimming-fasta-3     0/1           63s        63s
trimming-fasta-4     0/1           62s        62s

I´m trying to wait until the trimming-fasta-* jobs are finished. I have found this post here but it will return TRUE for some jobs that are finised. I really want to wait for all the trimming-fasta-* jobs are finisihed ??

until kubectl  get jobs   -o jsonpath='{.items[*].status.conditions[?(@.type=="Complete")].status}' ; do sleep 1 ; done
True True True True(base) [david@archlinux otustaxonomy]$ 

Any idea to only check for trimming jobs. By the way they all belong to the same jobgrooup but havn´t found anything to check for jobgroup completion

apiVersion: batch/v1
kind: Job
metadata:
  name: trimming-fasta-$idx
  namespace: namespace-test
  labels:
    jobgroup: trimming
spec:....

Any idea ??

Upvotes: 1

Views: 726

Answers (1)

Eduardo Baitello
Eduardo Baitello

Reputation: 11346

As per kubectl wait usage:

$ wait ([-f FILENAME] | resource.group/resource.name | resource.group [(-l label | --all)]) [--for=delete|--for condition=available]

You can use labels with kubectl wait, so just do the following to wait for all trimming jobs:

kubectl wait jobs -l jobgroup=trimming --for=condition=complete

Upvotes: 1

Related Questions