|
1 | 1 | use serde_yaml::{Mapping, Value}; |
2 | 2 |
|
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. |
4 | 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 |
| 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 |
14 | 9 | .get(format!("{operator_name}-operator")) |
15 | 10 | .and_then(Value::as_mapping) |
16 | 11 | .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() |
50 | 13 | } |
0 commit comments