labels := map[string]string{ "app": "my-app", "env": "prod", "component": "web", } selector := labels.SelectorFromSet(labels.Set(labels)) matches := selector.Matches(map[string]string{ "app": "my-app", "env": "prod", "component": "web", })
selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{ MatchLabels: map[string]string{ "app": "my-app", }, }) if err != nil { panic(err) } matches := selector.Matches(map[string]string{ "app": "my-app", "env": "prod", })This example shows how to create a Selector from a `metav1.LabelSelector` object, which is a common way of specifying selectors in Kubernetes API objects. In this case, the selector only matches labels with the "app" key set to "my-app", so `matches` will be `true` only if that label is present in the set of labels being matched.