Skip to content

Commit 631e9e0

Browse files
chore: Improve comment wording
1 parent 4e1e353 commit 631e9e0

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

crates/stackable-operator/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ All notable changes to this project will be documented in this file.
66

77
### Added
88

9-
- [v2] BREAKING: Converting an `EnvVarSet` into a `Vec<EnvVar>` takes dependencies between the
9+
- [v2] Add `EnvVarSet::with_env_var` to add a given `EnvVar` to the set ([#1249]).
10+
11+
### Changed
12+
13+
- [v2] BREAKING: Converting an `EnvVarSet` into a `Vec<EnvVar>` takes dependencies between
1014
environment variables into account ([#1249]).
1115

1216
[#1249]: https://github.com/stackabletech/operator-rs/pull/1249

crates/stackable-operator/src/v2/builder/pod/container.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ use crate::{
1616
v2::types::kubernetes::{ConfigMapKey, ConfigMapName, ContainerName},
1717
};
1818

19-
/// Pattern for an escaped dollar sign, e.g. `$$`
19+
/// Pattern for an escaped dollar sign (`$$`)
2020
static ESCAPED_DOLLAR_SIGN_PATTERN: LazyLock<Regex> =
2121
LazyLock::new(|| Regex::new(r"\$\$").expect("should be a valid regular expression"));
2222

2323
/// Pattern for a referenced environment variable, e.g. `$(ENV_VAR)`
2424
static REFERENCED_ENV_VARS_PATTERN: LazyLock<Regex> =
2525
LazyLock::new(|| Regex::new(r"\$\(([^\)]+)\)").expect("should be a valid regular expression"));
2626

27-
/// Maximum recursion depth until references in environment variables are followed
27+
/// Maximum depth to which references between environment variables are followed
2828
const ENV_VAR_DEPENDENCY_RESOLVER_MAX_RECURSION_DEPTH: usize = 10;
2929

3030
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -177,11 +177,11 @@ impl EnvVarSet {
177177

178178
impl From<EnvVarSet> for Vec<EnvVar> {
179179
fn from(value: EnvVarSet) -> Self {
180-
let env_var_closure =
180+
let dependency_resolver =
181181
EnvVarDependencyResolver::new(&value, ENV_VAR_DEPENDENCY_RESOLVER_MAX_RECURSION_DEPTH);
182182

183183
let mut vec: Self = value.0.values().cloned().collect();
184-
vec.sort_by_cached_key(|env_var| env_var_closure.sort_key(env_var));
184+
vec.sort_by_cached_key(|env_var| dependency_resolver.sort_key(env_var));
185185
vec
186186
}
187187
}
@@ -198,12 +198,13 @@ impl IntoIterator for EnvVarSet {
198198
/// Resolves dependencies between environment variables and provides sort keys which take these
199199
/// dependencies into account
200200
pub struct EnvVarDependencyResolver<'a> {
201-
/// [EnvVarSet] with possibly dependent environment variables
201+
/// [`EnvVarSet`] with possibly dependent environment variables
202202
env_vars: &'a EnvVarSet,
203203

204-
/// Maximum recursion depth
204+
/// Maximum depth to which references between environment variables are followed
205205
///
206-
/// Long dependency chains could slow down the operator.
206+
/// The recursion depth is limited because long dependency chains could slow down the
207+
/// operator.
207208
max_recursion_depth: usize,
208209
}
209210

@@ -215,8 +216,8 @@ impl<'a> EnvVarDependencyResolver<'a> {
215216
}
216217
}
217218

218-
/// Returns a sort key for the given environment variable which considers dependencies to other
219-
/// environment variables
219+
/// Returns a sort key for the given environment variable, taking dependencies on other
220+
/// environment variables into account
220221
///
221222
/// # Example
222223
///
@@ -262,7 +263,7 @@ impl<'a> EnvVarDependencyResolver<'a> {
262263
/// };
263264
/// let env_var5 = EnvVar {
264265
/// name: "ENV5".to_owned(),
265-
/// value: Some("self reference to $(ENV5)".to_owned()),
266+
/// value: Some("self-reference to $(ENV5)".to_owned()),
266267
/// value_from: None,
267268
/// };
268269
///
@@ -296,8 +297,8 @@ impl<'a> EnvVarDependencyResolver<'a> {
296297
/// ```
297298
pub fn sort_key(&self, env_var: &EnvVar) -> Vec<String> {
298299
if let Some(mut closure) = self.calculate_closure(env_var) {
299-
// Add the name of the variable to its closure to make the set unique for every
300-
// variable.
300+
// Add the name of the variable to its closure so that every variable gets a unique
301+
// sort key.
301302
closure.insert(env_var.name.clone());
302303

303304
closure.into_iter().rev().collect()
@@ -355,7 +356,7 @@ impl<'a> EnvVarDependencyResolver<'a> {
355356
/// };
356357
/// let env_var5 = EnvVar {
357358
/// name: "ENV5".to_owned(),
358-
/// value: Some("self reference to $(ENV5)".to_owned()),
359+
/// value: Some("self-reference to $(ENV5)".to_owned()),
359360
/// value_from: None,
360361
/// };
361362
/// let env_var6 = EnvVar {

0 commit comments

Comments
 (0)