I have created a job in kubernetes through client-go api. Now I want to get the log of the job, but I can't find the log api of job in client-go. Therefore, I want to obtain the name of all the pods in a job to obtain the POD logs by name, and then obtain the logs of the job.
So,how to get the name of pod in a job in kubernetes through client-go?
Thanks so much.
I create a pod with label, and then I get it through LabelSelector. Like it :
config, err := clientcmd.BuildConfigFromFlags("", "~/.kube/config")
if err != nil {
println("config build error")
}
client, err := kubernetes.NewForConfig(config)
pods, err := client.CoreV1().Pods("test").List(context.TODO(),
v1.ListOptions{LabelSelector: "name=label_name"})
for _, v := range pods.Items {
log := client.CoreV1().Pods("test").GetLogs(v.Name, &v12.PodLogOptions{})
}