简体   繁体   中英

Delete a Job and wait until job is deleting in client-go

// Delete a Batch Job by name
func (k K8sClient) DeleteBatchJob(name string, namespace string) error {
    return k.K8sCS.BatchV1().Jobs(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
}

I am deleting a job if already exists and then starting a new Job, but the operation here is asynchronous and job creation phase started when the job is being deleted, which I don't want. I want to successfully delete a job before creation of new one.

How can I implement this functionality using go?

If you give every job a unique name, you won't have to wait for the asynchronous deletion to make a new one. This is how the cron scheduler works in k8s - it creates uniquely named jobs every time.

To find and manage the jobs, you can use labels instead of the job name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM