pub struct SubnetPolicy { /* private fields */ }Expand description
Policy for assigning nodes to subnets based on capability tags.
Rules are evaluated in order. Each rule maps a tag prefix to a hierarchy level and provides a value map for the tag’s value.
Example: a node with tags ["region:us-west", "fleet:alpha"] and rules:
SubnetRule { tag_prefix: "region:", level: 0, values: {"us-west": 1} }SubnetRule { tag_prefix: "fleet:", level: 1, values: {"alpha": 2} }
Would get SubnetId::new(&[1, 2]).
§Semantics (rule precedence and matching contract)
Pinned by unit tests in this module — changes here are behavioral breaks for operators configuring subnets:
- Rule order is declaration order.
assign()walksrulesin the order passed toadd_rule(). Two rules targeting the samelevelwith overlapping values resolve as later-rule-wins: the earlier rule may write the level byte first, but a subsequent match at the same level overwrites it. - First tag wins per rule. Inside one rule, the first
capability tag whose stripped suffix is present in
valueswins — subsequent tags matching the same rule are ignored. - No partial-prefix match on values.
tag_prefixis stripped bystr::strip_prefix; the remaining value is then looked up by exact string equality againstvalues. A ruleregion:matching on"us"will not match the tagregion:us:extra(the stripped suffix"us:extra"is not in the values map). - Unmatched levels stay zero. Levels with no rule (or a
rule that failed to match) remain
0, whichSubnetIdinterprets as “no restriction at this level”.
Implementations§
Source§impl SubnetPolicy
impl SubnetPolicy
Sourcepub fn add_rule(self, rule: SubnetRule) -> Self
pub fn add_rule(self, rule: SubnetRule) -> Self
Add a rule to the policy.
§Panics
Panics if the rule’s level is >= 4. For untrusted input
(config files, FFI, JSON) prefer Self::try_add_rule,
which returns a SubnetError instead of panicking.
Sourcepub fn try_add_rule(self, rule: SubnetRule) -> Result<Self, SubnetError>
pub fn try_add_rule(self, rule: SubnetRule) -> Result<Self, SubnetError>
Fallible variant of Self::add_rule.
Pre-existing add_rule panics on rule.level >= 4.
Subnet policies typically come from config / FFI / JSON and
a malformed entry should surface as a recoverable error
rather than crashing the daemon loader.
Sourcepub fn assign(&self, caps: &CapabilitySet) -> SubnetId
pub fn assign(&self, caps: &CapabilitySet) -> SubnetId
Assign a subnet ID to a node based on its capability tags.
Evaluates all rules against the node’s tags. Unmatched levels remain zero (meaning “no restriction at that level”).
Trait Implementations§
Source§impl Clone for SubnetPolicy
impl Clone for SubnetPolicy
Source§fn clone(&self) -> SubnetPolicy
fn clone(&self) -> SubnetPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more