Abhishek Kumar
Abhishek Kumar

Reputation: 900

find batch-job by label client-go

How to list Batch-Job by label-selector. I want to list out the job with a certain label like: type: upgrade or something else. Looking out for label selector fields while querying job from client-go.

Upvotes: 0

Views: 900

Answers (1)

Abhishek Kumar
Abhishek Kumar

Reputation: 900

I was making mistake worrying about the .Get() method to find job by labelSelector, and thus working hard in the wrong direction.

Here is how you can list out all job with the label-selector
To get job by label-selector, We have to use .List() method.

label := "type=upgrade,name=jiva-upgrade"; 
jobs, err := k.K8sCS.BatchV1().Jobs(namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: label})

Upvotes: 1

Related Questions