Skip to content

Commit f501087

Browse files
committed
minor refactor
1 parent 7c8a393 commit f501087

3 files changed

Lines changed: 23 additions & 26 deletions

File tree

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use futures::{StreamExt as _, TryStreamExt};
22
use indexmap::IndexMap;
33
use reqwest::StatusCode;
44
use serde::{Deserialize, Serialize};
5-
use serde_yaml::{Mapping, Value};
5+
use serde_yaml::Mapping;
66
use snafu::{ResultExt, Snafu};
77
use tokio::task::JoinError;
88
use tracing::{Instrument, Span, debug, info, instrument};
@@ -19,7 +19,7 @@ use crate::{
1919
utils::{
2020
k8s::{self, Client},
2121
path::{IntoPathOrUrl as _, PathOrUrlParseError},
22-
yaml::deep_merge,
22+
yaml::merged_values_for_operator,
2323
},
2424
xfer::{self, processor::Text},
2525
};
@@ -104,24 +104,14 @@ impl ReleaseSpec {
104104
Span::current().pb_set_length(operators.len() as u64);
105105

106106
let namespace = namespace.to_string();
107-
let common_values = operator_values
108-
.get("common")
109-
.and_then(Value::as_mapping)
110-
.cloned()
111-
.unwrap_or_default();
112107
futures::stream::iter(operators)
113108
.map(|(product_name, product)| {
114109
let task_span =
115110
tracing::info_span!("install_operator", product_name = tracing::field::Empty);
116111

117112
let namespace = namespace.clone();
118113
let chart_source = chart_source.clone();
119-
let operator_specific = operator_values
120-
.get(format!("{product_name}-operator"))
121-
.and_then(Value::as_mapping)
122-
.cloned()
123-
.unwrap_or_default();
124-
let merged_values = deep_merge(common_values.clone(), operator_specific);
114+
let merged_values = merged_values_for_operator(operator_values, &product_name);
125115
// Helm installs currently `block_in_place`, so we need to spawn each job onto a separate task to
126116
// get useful parallelism.
127117
tokio::spawn(

rust/stackable-cockpit/src/utils/yaml.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
use serde_yaml::{Mapping, Value};
22

3+
/// Extracts the merged Helm values for a specific operator from the operator values mapping.
4+
///
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
14+
.get(format!("{operator_name}-operator"))
15+
.and_then(Value::as_mapping)
16+
.cloned()
17+
.unwrap_or_default();
18+
deep_merge(common, operator_specific)
19+
}
20+
321
/// Deep merges `overlay` into `base`. Overlay values take precedence.
422
/// When both values are mappings, their contents are merged recursively.
523
/// Non-mapping values (including sequences) are replaced entirely, not merged.

rust/stackablectl/src/cmds/operator.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use comfy_table::{
88
use indexmap::IndexMap;
99
use semver::Version;
1010
use serde::Serialize;
11-
use serde_yaml::Value;
1211
use snafu::{ResultExt, Snafu};
1312
use stackable_cockpit::{
1413
constants::{
@@ -25,7 +24,7 @@ use stackable_cockpit::{
2524
chartsource::ChartSourceMetadata,
2625
k8s::{self, Client},
2726
path::PathOrUrlParseError,
28-
yaml::deep_merge,
27+
yaml::merged_values_for_operator,
2928
},
3029
xfer,
3130
};
@@ -351,18 +350,8 @@ async fn install_cmd(
351350
.await
352351
.context(FileTransferSnafu)?;
353352

354-
let common_values = operator_values
355-
.get("common")
356-
.and_then(Value::as_mapping)
357-
.cloned()
358-
.unwrap_or_default();
359353
for operator in &args.operators {
360-
let operator_specific = operator_values
361-
.get(format!("{}-operator", &operator.name))
362-
.and_then(Value::as_mapping)
363-
.cloned()
364-
.unwrap_or_default();
365-
let merged_values = deep_merge(common_values.clone(), operator_specific);
354+
let merged_values = merged_values_for_operator(&operator_values, &operator.name);
366355

367356
operator
368357
.install(

0 commit comments

Comments
 (0)