From 7169fe2d188b2b9bd71c81477d1c56649c6d36bb Mon Sep 17 00:00:00 2001 From: Taha Hawa Date: Thu, 3 Jul 2025 11:59:15 -0400 Subject: [PATCH] Create YAML from struct --- .../application/features/argo_types.rs | 52 +++++++++++++++++++ .../application/features/helm_argocd_score.rs | 8 +-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/harmony/src/modules/application/features/argo_types.rs b/harmony/src/modules/application/features/argo_types.rs index 812f673..a59e9c4 100644 --- a/harmony/src/modules/application/features/argo_types.rs +++ b/harmony/src/modules/application/features/argo_types.rs @@ -172,3 +172,55 @@ impl From 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") + } +} diff --git a/harmony/src/modules/application/features/helm_argocd_score.rs b/harmony/src/modules/application/features/helm_argocd_score.rs index e654a9b..ab9cd1e 100644 --- a/harmony/src/modules/application/features/helm_argocd_score.rs +++ b/harmony/src/modules/application/features/helm_argocd_score.rs @@ -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 "#, );