useRenokiCo\PhpK8s\K8s;$container =K8s::container()->setName('pi')->setImage('perl')->setCommand(['perl','-Mbignum=bpi','-wle','print bpi(2000)']);$pod =K8s::pod()->setName('pi')->setLabels(['job-name'=>'pi'])// needs job-name: pi so that ->getPods() can work->setContainers([$container])->restartOnFailure();$job =$this->cluster->job()->setName('pi')->setSelectors(['matchLabels'=> ['tier'=>'backend']])->setTemplate($pod)->create();
Pod Template Retrieval
Jobs rely on pods, so you can get the pod template as K8sPod class:
To get the pods, the Pod template must have the job-name label set. This way, the labelSelector API parameter is issued and you may retrieve the associated pods:
metadata:name: [here it goes the job name]spec:template:metadata:labels:job-name: [here it goes the job name]
You can retrieve the pods as resources controlled by the Job by issuing ->getPods():
If you cannot declare the job-name label or simply want to use something else, you may call selectPods from the resource:
useRenokiCo\PhpK8s\Kinds\K8sJob;K8sJob::selectPods(function (K8sJob $job) {// $job is the current Jobreturn ['some-label'=>'some-label-value','some-other-label'=>"{$job->getName()}-custom-name", ];});
Job's Restart Policy
You might want to use OnFailure or Never as restart policies. These can be applied to the pod before passing it to the job creation chain: