kubernetes / client-go

Go client for Kubernetes.
Apache License 2.0
8.78k stars 2.9k forks source link

FieldSelector doesn't appear to be filtering properly #1350

Open jacobwolfaws opened 2 months ago

jacobwolfaws commented 2 months ago

I'm trying to filter a list of pods based on the node they're on:

podList, err := clientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{
FieldSelector: fmt.Sprintf("spec.nodeName=%s", nodeName),
})

but the FieldSelector doesn't appear to be filtering them properly. I'm currently working around this by doing:

for _, pod := range podList.Items {
        if pod.Spec.NodeName == nodeName {
         # Take action here
         }
}

slack thread: https://kubernetes.slack.com/archives/C0EG7JC6T/p1713547391787689?thread_ts=1713212213.662529&cid=C0EG7JC6T