matches_selector

Function matches_selector 

Source
pub fn matches_selector(
    selector: &LabelSelector,
    labels: &BTreeMap<String, String>,
) -> bool
Expand description

Check if a set of labels matches a label selector.

This function implements the Kubernetes label selector matching logic:

  • All matchLabels entries must be present with exact values
  • All matchExpressions requirements must be satisfied
  • An empty selector matches everything
  • A selector with no matchLabels and no matchExpressions matches everything

§Arguments

  • selector - The label selector to evaluate
  • labels - 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));