简体   繁体   English

删除作业并等待作业在 client-go 中删除

[英]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?如何使用 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.这就是 cron 调度程序在 k8s 中的工作方式——它每次都会创建唯一命名的作业。

To find and manage the jobs, you can use labels instead of the job name.要查找和管理作业,您可以使用标签代替作业名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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