import ( fields "k8s.io/kubernetes/pkg/fields" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) listOptions := metav1.ListOptions{ FieldSelector: fields.SelectorFromSet(fields.Set{"metadata.labels.app": "nginx"}).String(), } pods, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), listOptions)
import ( fields "k8s.io/kubernetes/pkg/fields" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) listOptions := metav1.ListOptions{ FieldSelector: fields.Everything().String(), ResourceVersion: "0", } nodes, err := clientset.CoreV1().Nodes().List(context.TODO(), listOptions)This code example selects all the Nodes in the cluster and returns them in their initial state, as indicated by the ResourceVersion "0". The selection is performed using the Everything() selector, which matches all resources. The k8s.io/kubernetes/pkg/fields Selector library is part of the official Kubernetes Go client library. Its purpose is to provide a powerful and flexible mechanism for selecting Kubernetes resources based on their fields, which can be used in a wide range of applications, from automation tools to monitoring systems.