pub fn matches_selector(
selector: &LabelSelector,
labels: &BTreeMap<String, String>,
) -> boolExpand description
Check if a set of labels matches a label selector.
This function implements the Kubernetes label selector matching logic:
- All
matchLabelsentries must be present with exact values - All
matchExpressionsrequirements must be satisfied - An empty selector matches everything
- A selector with no matchLabels and no matchExpressions matches everything
§Arguments
selector- The label selector to evaluatelabels- The labels to match against
§Returns
true if the labels match the selector, false otherwise
§Examples
use std::collections::BTreeMap;
use bindy::crd::LabelSelector;
use bindy::selector::matches_selector;
let mut labels = BTreeMap::new();
labels.insert("app".to_string(), "web".to_string());
labels.insert("env".to_string(), "prod".to_string());
let mut match_labels = BTreeMap::new();
match_labels.insert("app".to_string(), "web".to_string());
let selector = LabelSelector {
match_labels: Some(match_labels),
match_expressions: None,
};
assert!(matches_selector(&selector, &labels));