fix: try to properly append YAML in correct places in argoapplication

This commit is contained in:
tahahawa 2025-07-04 10:22:40 -04:00
parent b73f2e76d0
commit e560b59f60

View File

@ -3,6 +3,7 @@ use std::{backtrace, collections::HashMap};
use k8s_openapi::{Metadata, NamespaceResourceScope, Resource};
use log::debug;
use serde::Serialize;
use serde_json::map::ValuesMut;
use serde_yaml::{Mapping, Value};
use url::Url;
@ -210,17 +211,31 @@ spec:
"#
);
yaml_str.push_str(
&serde_yaml::to_string(&source.clone())
.expect("couldn't serialize source to yaml string"),
);
yaml_str.push_str(
&serde_yaml::to_string(&self.sync_policy)
.expect("couldn't serialize sync policy to yaml string"),
);
yaml_str.push_str(
&serde_yaml::to_string(&self.revision_history_limit)
.expect("couldn't serialize revision history to yaml string"),
let mut yaml_value: Value =
serde_yaml::from_str(yaml_str.as_str()).expect("couldn't parse string to YAML");
let mut spec = yaml_value
.get_mut("spec")
.expect("couldn't get spec from yaml")
.as_mapping_mut()
.expect("couldn't unwrap spec as mutable mapping");
let source =
serde_yaml::to_value(&self.source).expect("couldn't serialize source to value");
let sync_policy = serde_yaml::to_value(&self.sync_policy)
.expect("couldn't serialize sync_policy to value");
let revision_history_limit = serde_yaml::to_value(&self.revision_history_limit)
.expect("couldn't serialize revision_history_limit to value");
spec.entry(source.clone()).or_insert(source);
spec.entry(sync_policy.clone()).or_insert(sync_policy);
spec.entry(revision_history_limit.clone())
.or_insert(revision_history_limit);
debug!("spec: {}", serde_yaml::to_string(spec).unwrap());
debug!(
"entire yaml_value: {}",
serde_yaml::to_string(&yaml_value).unwrap()
);
debug!("yaml serialize of :\n{yaml_str}");