Skip to content

Commit 3527ee7

Browse files
apollo_node_config: include base prefix when pruning unset optionals
1 parent e13acc4 commit 3527ee7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

crates/apollo_node_config/src/config_utils.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ pub fn config_to_preset(config_map: &Value) -> Value {
9898
}
9999
}
100100

101-
/// Keep "{prefix}.#is_none": true, remove all other "{prefix}.*" keys.
101+
/// Keep "{prefix}.#is_none": true, remove all other "{prefix}.*" keys and also the bare
102+
/// "{prefix}" key.
102103
pub fn prune_by_is_none(mut v: Value) -> Value {
103104
let obj: &mut Map<String, Value> =
104105
v.as_object_mut().expect("prune_by_is_none: expected a JSON object");
@@ -115,9 +116,13 @@ pub fn prune_by_is_none(mut v: Value) -> Value {
115116
}
116117
}
117118

118-
// Remove keys that begin with any such prefix, except the "#is_none" flag itself
119+
// Remove keys that begin with any such prefix, or equal the bare prefix, except the "#is_none"
120+
// flag itself
119121
obj.retain(|k, _| {
120-
if let Some(p) = unset_optional_param_paths.iter().find(|p| k.starts_with(&***p)) {
122+
if let Some(p) = unset_optional_param_paths
123+
.iter()
124+
.find(|p| k.starts_with(&***p) || k.as_str() == p.trim_end_matches(FIELD_SEPARATOR))
125+
{
121126
// keep only the "{prefix}.#is_none" key
122127
k == &format!("{p}{IS_NONE_MARK}")
123128
} else {
@@ -202,6 +207,7 @@ impl DeploymentBaseAppConfig {
202207

203208
// Extract only the required fields from the config map.
204209
let preset = config_to_preset(&config_as_map);
210+
let preset = prune_by_is_none(preset);
205211
validate_all_pointer_targets_set(preset.clone()).expect("Pointer target not set");
206212
preset
207213
}

0 commit comments

Comments
 (0)