reqs := []fields.Requirement{ {Key: "metadata.name", Operator: "In", Values: []string{"my-pod"}}, {Key: "metadata.namespace", Operator: "In", Values: []string{"my-namespace"}}, } sel := fields.SelectorFromSet(fields.SetFromRequirements(reqs))
pod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "my-pod", Namespace: "my-namespace", Labels: map[string]string{"app": "my-app"}, }, Spec: v1.PodSpec{ Containers: []v1.Container{ {Name: "my-container", Image: "nginx:latest"}, }, }, } matches := sel.Matches(fields.Set{pod})The Matches method returns true if the set of requirements match the given set of field values. These examples demonstrate the use of the Selector Matches method in the Kubernetes package library k8s.io/kubernetes/pkg/fields.