dth981485742 2018-10-11 21:05
浏览 41

如何使用客户端Go库检查kubernetes作业是成功还是失败

There are lot of fields out there in the library but it basically talks about job finished or not, but how to check if a job is finished and successful or job is finished and failure

if con.Type == v1.JobComplete && con.Status == corev1.ConditionTrue && job.Status.Succeeded > 0 {
    fmt.Printf("Job: %v Completed Successfully: %v
", name, con)
    break
} else if con.Type == v1.JobFailed && con.Status == corev1.ConditionTrue {
    if job.Status.Active == 0 && job.Status.Succeeded == 0 {
        fmt.Printf("Job: %v Failed: %v
", name, con)
        break
    }
}

This is how I am checking now, I am not completely sure this is correct

  • 写回答

1条回答 默认 最新

  • dongzhang6544 2018-10-24 14:56
    关注

    You can use just the Active, Succeeded and Failed variables to know the status of the job.

    Example:

        batchClient := kubernetesapi.BatchV1()
        jobClient := batchClient.Jobs(NameSpace)
    
    
        job, _ := jobClient.Get(jobName, metav1.GetOptions{})
    
        if job.Status.Active > 0 {
        return "Job is still running"
    
        } else {
          if job.Status.Succeeded > 0 {
           return "Job Successful"
           } 
           return "Job failed"
        }
    

    This should take care of any number of retries to the job if you are using backOffLimit as more than 1.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器