Create YAML from struct
All checks were successful
Run Check Script / check (pull_request) Successful in -8s

This commit is contained in:
Taha Hawa 2025-07-03 11:59:15 -04:00
parent c7a4aeb5cf
commit 7169fe2d18
2 changed files with 56 additions and 4 deletions

View File

@ -172,3 +172,55 @@ impl From<CDApplicationConfig> for ArgoApplication {
}
}
}
impl ArgoApplication {
fn to_yaml(self) -> serde_yaml::Value {
let name = self.name;
let namespace = if let Some(ns) = self.namespace {
ns
} else {
"argocd".to_string()
};
let project = self.project;
let source = self.source;
let mut yaml_str = format!(
r#"
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: {name}
# You'll usually want to add your resources to the argocd namespace.
namespace: {namespace}
spec:
# The project the application belongs to.
project: {project}
# Destination cluster and namespace to deploy the application
destination:
# cluster API URL
server: https://kubernetes.default.svc
# or cluster name
# name: in-cluster
# The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace
namespace: {namespace}
"#
);
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 source to yaml string"),
);
yaml_str.push_str(
&serde_yaml::to_string(&self.revision_history_limit)
.expect("couldn't serialize source to yaml string"),
);
serde_yaml::from_str(&yaml_str).expect("Couldn't parse YAML")
}
}

View File

@ -3,7 +3,7 @@ use std::str::FromStr;
use crate::modules::helm::chart::{HelmChartScore, HelmRepository};
pub fn ntfy_helm_chart_score(namespace: String, openshift: bool, domain: String) -> HelmChartScore {
pub fn argo_helm_chart_score(namespace: String, openshift: bool, domain: String) -> HelmChartScore {
let values = format!(
r#"
# -- Create aggregated roles that extend existing cluster roles to interact with argo-cd resources
@ -317,7 +317,7 @@ controller:
annotations: {{}}
rules:
# -- Deploy a PrometheusRule for the application controller
enabled: true
enabled: false
# -- PrometheusRule namespace
namespace: "" # "monitoring"
# -- PrometheusRule selector
@ -898,8 +898,8 @@ notifications:
templates: {{}}
commitServer:
# -- Enable commit server
enabled: false
# -- Enable commit server
enabled: false
"#,
);