Skip to content

Commit f4a2fb7

Browse files
committed
Remove common key in yaml and deep merge logic; recommend yaml anchors
1 parent 15cde97 commit f4a2fb7

File tree

5 files changed

+28
-62
lines changed

5 files changed

+28
-62
lines changed

rust/stackable-cockpit/src/platform/release/spec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
utils::{
2020
k8s::{self, Client},
2121
path::{IntoPathOrUrl as _, PathOrUrlParseError},
22-
yaml::merged_values_for_operator,
22+
yaml::values_for_operator,
2323
},
2424
xfer::{self, processor::Text},
2525
};
@@ -111,7 +111,7 @@ impl ReleaseSpec {
111111

112112
let namespace = namespace.clone();
113113
let chart_source = chart_source.clone();
114-
let merged_values = merged_values_for_operator(operator_values, &product_name);
114+
let operator_helm_values = values_for_operator(operator_values, &product_name);
115115
// Helm installs currently `block_in_place`, so we need to spawn each job onto a separate task to
116116
// get useful parallelism.
117117
tokio::spawn(
@@ -126,7 +126,7 @@ impl ReleaseSpec {
126126

127127
// Install operator
128128
operator
129-
.install(&namespace, &chart_source, &merged_values)
129+
.install(&namespace, &chart_source, &operator_helm_values)
130130
.context(HelmInstallSnafu)?;
131131

132132
info!("Installed {product_name}-operator");
Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,13 @@
11
use serde_yaml::{Mapping, Value};
22

3-
/// Extracts the merged Helm values for a specific operator from the operator values mapping.
3+
/// Extracts the Helm values for a specific operator from the operator values mapping.
44
///
5-
/// Looks up the `common` key and the operator-specific key (e.g. `airflow-operator`),
6-
/// then deep-merges them with operator-specific values taking precedence.
7-
pub fn merged_values_for_operator(operator_values: &Mapping, operator_name: &str) -> Mapping {
8-
let common = operator_values
9-
.get("common")
10-
.and_then(Value::as_mapping)
11-
.cloned()
12-
.unwrap_or_default();
13-
let operator_specific = operator_values
5+
/// Looks up the operator-specific key (e.g. `airflow-operator`) and returns
6+
/// the associated mapping, or an empty mapping if not found.
7+
pub fn values_for_operator(operator_values: &Mapping, operator_name: &str) -> Mapping {
8+
operator_values
149
.get(format!("{operator_name}-operator"))
1510
.and_then(Value::as_mapping)
1611
.cloned()
17-
.unwrap_or_default();
18-
deep_merge(common, operator_specific)
19-
}
20-
21-
/// Deep merges `overlay` into `base`. Overlay values take precedence.
22-
/// When both values are mappings, their contents are merged recursively.
23-
/// Non-mapping values (including sequences) are replaced entirely, not merged.
24-
fn deep_merge(mut base: Mapping, overlay: Mapping) -> Mapping {
25-
for (k, v) in overlay {
26-
match base.get_mut(&k) {
27-
Some(base_v) => merge_value(base_v, v),
28-
None => {
29-
base.insert(k, v);
30-
}
31-
}
32-
}
33-
base
34-
}
35-
36-
fn merge_value(base: &mut Value, overlay: Value) {
37-
match (base, overlay) {
38-
(Value::Mapping(base), Value::Mapping(overlay)) => {
39-
for (k, v) in overlay {
40-
match base.get_mut(&k) {
41-
Some(base_v) => merge_value(base_v, v),
42-
None => {
43-
base.insert(k, v);
44-
}
45-
}
46-
}
47-
}
48-
(base, overlay) => *base = overlay,
49-
}
12+
.unwrap_or_default()
5013
}

rust/stackablectl/src/args/file.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,21 @@ to provide multiple additional release files.")]
4848
#[arg(
4949
long_help = "Path to a Helm values file that will be used for the installation of operators
5050
51-
The file is a YAML file containing Helm values used to deploy operators. It
52-
supports a 'common' key for values shared across all operators, as well as
53-
operator-specific keys (e.g. 'airflow-operator', 'zookeeper-operator') for
54-
values that only apply to a single operator. Operator-specific values are
55-
merged with common values, with operator-specific values taking precedence.
51+
The file is a YAML file containing Helm values used to deploy operators.
52+
Operator-specific keys (e.g. 'airflow-operator', 'zookeeper-operator') map
53+
to the Helm values for that operator. Use YAML anchors and aliases to share
54+
values across operators.
5655
5756
Example values file:
5857
59-
common:
60-
tolerations:
58+
airflow-operator:
59+
tolerations: &default-tolerations
6160
- key: \"example\"
6261
operator: \"Exists\"
6362
effect: \"NoSchedule\"
64-
airflow-operator:
6563
replicas: 2
6664
zookeeper-operator:
65+
tolerations: *default-tolerations
6766
replicas: 3
6867
6968
Use \"stackablectl [OPTIONS] <COMMAND> -f path/to/values.yaml\" to provide a

rust/stackablectl/src/cmds/operator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use stackable_cockpit::{
2424
chartsource::ChartSourceMetadata,
2525
k8s::{self, Client},
2626
path::PathOrUrlParseError,
27-
yaml::merged_values_for_operator,
27+
yaml::values_for_operator,
2828
},
2929
xfer,
3030
};
@@ -351,13 +351,13 @@ async fn install_cmd(
351351
.context(LoadOperatorValuesSnafu)?;
352352

353353
for operator in &args.operators {
354-
let merged_values = merged_values_for_operator(&operator_values, &operator.name);
354+
let operator_helm_values = values_for_operator(&operator_values, &operator.name);
355355

356356
operator
357357
.install(
358358
&args.operator_namespace,
359359
&ChartSourceType::from(cli.chart_type()),
360-
&merged_values,
360+
&operator_helm_values,
361361
)
362362
.context(HelmSnafu)?;
363363

rust/stackablectl/src/utils.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ pub fn use_colored_output(use_color: bool) -> bool {
5656

5757
/// Loads operator helm values from a YAML file.
5858
///
59-
/// The file should contain a YAML mapping of operator names to their helm values:
59+
/// The file should contain a YAML mapping of operator names to their helm values.
60+
/// Use YAML anchors and aliases to share values across operators:
6061
/// ```yaml
61-
/// common:
62-
/// key: value
6362
/// airflow-operator:
64-
/// key: value
63+
/// tolerations: &default-tolerations
64+
/// - key: "example"
65+
/// operator: "Exists"
66+
/// effect: "NoSchedule"
67+
/// replicas: 2
6568
/// zookeeper-operator:
66-
/// key: value
69+
/// tolerations: *default-tolerations
70+
/// replicas: 3
6771
/// ```
6872
pub async fn load_operator_values(
6973
values_file: Option<&PathOrUrl>,

0 commit comments

Comments
 (0)