Skip to content

brokkr-broker::utils::matching

Rust

Template-to-stack matching utilities.

This module provides functions for validating that a template’s labels and annotations are compatible with a target stack before instantiation.

pub

Derives: Debug, Default, Serialize

Result of a template-to-stack matching operation.

Name Type Description
matches bool Whether the template matches the stack.
missing_labels Vec<String> Labels required by the template that are missing from the stack.
missing_annotations Vec<(String, String)> Annotations required by the template that are missing from the stack.

pub

fn template_matches_stack(
template_labels: &[String],
template_annotations: &[(String, String)],
stack_labels: &[String],
stack_annotations: &[(String, String)],
) -> MatchResult

Check if a template can be instantiated into a stack.

Matching Rules

  • Template with NO labels/annotations = matches ANY stack (permissive)
  • Template WITH labels = ALL labels must exist on stack
  • Template WITH annotations = ALL annotations (key-value pairs) must exist on stack

Parameters:

Name Type Description
template_labels &[String] Labels attached to the template
template_annotations &[(String, String)] Annotations attached to the template (key-value pairs)
stack_labels &[String] Labels attached to the target stack
stack_annotations &[(String, String)] Annotations attached to the target stack (key-value pairs)

Returns:

A MatchResult indicating whether the template matches and details about any missing labels or annotations.

Source
pub fn template_matches_stack(
template_labels: &[String],
template_annotations: &[(String, String)],
stack_labels: &[String],
stack_annotations: &[(String, String)],
) -> MatchResult {
// If template has no labels/annotations, it matches everything (go anywhere)
if template_labels.is_empty() && template_annotations.is_empty() {
return MatchResult {
matches: true,
missing_labels: Vec::new(),
missing_annotations: Vec::new(),
};
}
// Check all template labels exist on stack
let missing_labels: Vec<String> = template_labels
.iter()
.filter(|tl| !stack_labels.contains(tl))
.cloned()
.collect();
// Check all template annotations exist on stack (exact key-value match)
let missing_annotations: Vec<(String, String)> = template_annotations
.iter()
.filter(|ta| !stack_annotations.contains(ta))
.cloned()
.collect();
MatchResult {
matches: missing_labels.is_empty() && missing_annotations.is_empty(),
missing_labels,
missing_annotations,
}
}