Skip to content

Commit c795991

Browse files
committed
Address some documentation errors
1 parent 082c354 commit c795991

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

overrides.example.yaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,33 @@ propertyRules:
1515
# Instead of replacing the property with an existing type, it can also be ignored using:
1616
# matchSuccess: omit
1717

18-
# 1. Name-directed matching.
18+
# Step 1: name-directed matching.
1919
#
20-
# The first step of determining if a rule applies to a given CRD property, is to attempt
20+
# This is the first step of determining if a rule applies to a given CRD property. It tries
2121
# to match the property's name against zero or more exact strings or regular expressions.
22+
#
23+
# Any `matchName` expressions are evaluated prior to `matchSchema` expressions.
2224
matchName:
2325
# An exact match checks the property name matches exactly.
2426
- exact: resources
2527
# This is the equivalent regular expression to `exact` match, above.
2628
#
27-
# You should prefer to use precise `exact` matches if possible, as they are performed using
28-
# `O(1)` `HashMap::get(name)`. In constrast; the property name must be tested against _every_
29-
# `regex` defined in the overrides, via a `O(n)` linear scan per property, if no `exact`
30-
# matches were found.
29+
# You should prefer to use precise `exact` matches if possible, as they can optimized to use
30+
# `O(1)` `HashMap::get(name)`. With `regex` matches however, the property name must be tested
31+
# against _every_ `regex` requiring an `O(n)` linear scan per property, if no `exact` matches
32+
# were found.
3133
#
3234
# Regular expression syntax is that of the <https://docs.rs/regex> crate.
3335
- regex: ^resources$
3436

35-
# 2. Type-directed matching.
37+
# Step 2: type-directed matching.
38+
#
39+
# This is the second step of determining if a rule applies to a given CRD property. It tries
40+
# to match the property's schema against a partial specification.
3641
#
37-
# If one of the `matchName` expressions succeeded in matching the property name, or no
38-
# expressions were specified, then the property's `JSONSchemaProps` value will be tested against
39-
# the partially specified schema defined in `matchSchema`.
42+
# If one of the `matchName` expressions succeeded in matching the property name, or no `matchName`
43+
# expressions were specified, the property's `JSONSchemaProps` value will be tested against the
44+
# schema defined in `matchSchema`.
4045
#
4146
# The full `JSONSchemaProps` format is supported. It's the same as what you see within a CRD YAML,
4247
# and can be copy-pasted directly from CRD properties. However, only a certain subset of
@@ -281,7 +286,7 @@ propertyRules:
281286
- matchSuccess:
282287
replace: Vec<LocalObjectReference>
283288
matchAnyName:
284-
- exact:
289+
- exact: imagePullSecrets
285290
matchSchema:
286291
exhaustive:
287292
type: array

src/overrides.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,15 @@ impl Overrides {
111111
errors.push(error);
112112
})
113113
.ok()?;
114+
// For each `name` in exact matches, a clone of the rule is stored in the
115+
// `property_index` `HashMap`, hence all compiled rules are wrapped in `Rc`.
116+
let rule = Rc::new(rule);
114117
let has_exact_matches = !exact_matches.is_empty();
115118
for name in exact_matches {
116119
property_index
117120
.entry(name)
118-
.and_modify(|rules: &mut Vec<Rc<CompiledPropertyRule>>| rules.push(rule.clone()))
119-
.or_insert(vec![rule.clone(); 1]);
121+
.and_modify(|rules: &mut Vec<Rc<CompiledPropertyRule>>| rules.push(Rc::clone(&rule)))
122+
.or_insert(vec![Rc::clone(&rule); 1]);
120123
}
121124

122125
// Don't yield the rule for the linear scan if it has an exact match and _no_ regex matches,
@@ -244,7 +247,7 @@ impl PropertyRule {
244247
/// Compile any regular expressions contained in the property rule, returning a set of exact
245248
/// matches that were not compiled into the resulting regular expression set, so they can be
246249
/// optimized elsewhere.
247-
fn compile(self) -> Result<(Rc<CompiledPropertyRule>, HashSet<String>), regex::Error> {
250+
fn compile(self) -> Result<(CompiledPropertyRule, HashSet<String>), regex::Error> {
248251
let mut exact_matches = HashSet::new();
249252
let regex_matches = self.match_name.into_iter().filter_map(|name| match name {
250253
PropertyName::Regex(regex) => Some(regex),
@@ -255,11 +258,11 @@ impl PropertyRule {
255258
});
256259

257260
Ok((
258-
Rc::new(PropertyRule {
261+
PropertyRule {
259262
match_name: PropertyRegexSet::new(regex_matches)?,
260263
match_schema: self.match_schema,
261264
match_success: self.match_success,
262-
}),
265+
},
263266
exact_matches,
264267
))
265268
}

0 commit comments

Comments
 (0)