diff --git a/Cargo.lock b/Cargo.lock index 94f83a8..9481478 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1752,6 +1752,7 @@ dependencies = [ "non-blank-string-rs", "opnsense-config", "opnsense-config-xml", + "pretty_assertions", "rand 0.9.1", "reqwest 0.11.27", "russh", @@ -1760,6 +1761,7 @@ dependencies = [ "serde", "serde-value", "serde_json", + "serde_with", "serde_yaml", "similar", "strum 0.27.1", @@ -4080,6 +4082,18 @@ dependencies = [ "serde_json", ] +[[package]] +name = "schemars" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1375ba8ef45a6f15d83fa8748f1079428295d403d6ea991d09ab100155fbc06d" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -4280,22 +4294,36 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf65a400f8f66fb7b0552869ad70157166676db75ed8181f8104ea91cf9d0b42" +checksum = "f2c45cd61fefa9db6f254525d46e392b852e0e61d9a1fd36e5bd183450a556d5" dependencies = [ "base64 0.22.1", "chrono", "hex", "indexmap 1.9.3", "indexmap 2.10.0", - "schemars", + "schemars 0.9.0", + "schemars 1.0.3", "serde", "serde_derive", "serde_json", + "serde_with_macros", "time", ] +[[package]] +name = "serde_with_macros" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de90945e6565ce0d9a25098082ed4ee4002e047cb59892c318d66821e14bb30f" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_yaml" version = "0.9.34+deprecated" diff --git a/Cargo.toml b/Cargo.toml index 92bfc4a..c30f10c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,3 +52,4 @@ convert_case = "0.8" chrono = "0.4" similar = "2" uuid = { version = "1.11", features = ["v4", "fast-rng", "macro-diagnostics"] } +pretty_assertions = "1.4.1" diff --git a/harmony/Cargo.toml b/harmony/Cargo.toml index 2a7a97f..ec2e2fa 100644 --- a/harmony/Cargo.toml +++ b/harmony/Cargo.toml @@ -58,3 +58,7 @@ futures-util = "0.3.31" tokio-util = "0.7.15" strum = { version = "0.27.1", features = ["derive"] } tempfile = "3.20.0" +serde_with = "3.14.0" + +[dev-dependencies] +pretty_assertions.workspace = true diff --git a/harmony/src/modules/application/features/argo_types.rs b/harmony/src/modules/application/features/argo_types.rs index 41ba8a3..197742a 100644 --- a/harmony/src/modules/application/features/argo_types.rs +++ b/harmony/src/modules/application/features/argo_types.rs @@ -3,11 +3,13 @@ use std::{backtrace, collections::HashMap}; use k8s_openapi::{Metadata, NamespaceResourceScope, Resource}; use log::debug; use serde::Serialize; +use serde_with::skip_serializing_none; use serde_yaml::Value; use url::Url; use crate::modules::application::features::CDApplicationConfig; +#[skip_serializing_none] #[derive(Clone, Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct Helm { @@ -27,9 +29,11 @@ pub struct Helm { pub namespace: Option, } +#[skip_serializing_none] #[derive(Clone, Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct Source { + #[serde(rename = "repoURL")] pub repo_url: Url, pub target_revision: Option, pub chart: String, @@ -67,6 +71,7 @@ pub struct SyncPolicy { pub retry: Retry, } +#[skip_serializing_none] #[derive(Clone, Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct ArgoApplication { @@ -135,7 +140,7 @@ impl From for ArgoApplication { source: Source { repo_url: Url::parse(value.helm_chart_repo_url.to_string().as_str()) .expect("couldn't convert to URL"), - target_revision: None, + target_revision: Some(value.version.to_string()), chart: value.helm_chart_name, helm: Helm { pass_credentials: None, @@ -145,7 +150,7 @@ impl From for ArgoApplication { value_files: vec![], ignore_missing_value_files: None, values: None, - values_object: Some(value.values_overrides), + values_object: value.values_overrides, skip_crds: None, skip_schema_validation: None, version: None, @@ -252,6 +257,7 @@ spec: #[cfg(test)] mod tests { + use pretty_assertions::assert_eq; use url::Url; use crate::modules::application::features::{ @@ -315,24 +321,14 @@ spec: server: https://kubernetes.default.svc namespace: test-ns source: - repoUrl: http://test/ - targetRevision: null + repoURL: http://test/ chart: test-chart helm: - passCredentials: null parameters: [] fileParameters: [] releaseName: test-release-neame valueFiles: [] - ignoreMissingValueFiles: null - values: null - valuesObject: null - skipCrds: null - skipSchemaValidation: null - version: null - kubeVersion: null apiVersions: [] - namespace: null syncPolicy: automated: prune: false diff --git a/harmony/src/modules/application/features/continuous_delivery.rs b/harmony/src/modules/application/features/continuous_delivery.rs index 85fd87a..8396124 100644 --- a/harmony/src/modules/application/features/continuous_delivery.rs +++ b/harmony/src/modules/application/features/continuous_delivery.rs @@ -161,6 +161,7 @@ impl< let helm_chart = self.application.build_push_helm_package(&image).await?; info!("Pushed new helm chart {helm_chart}"); + error!("TODO Make building image configurable/skippable"); let image = self.application.build_push_oci_image().await?; info!("Pushed new docker image {image}"); @@ -194,7 +195,7 @@ impl< version: Version::from("0.1.0").unwrap(), helm_chart_repo_url: Url::Url(url::Url::parse("oci://hub.nationtech.io/harmony/harmony-example-rust-webapp-chart/harmony-example-rust-webapp-chart").unwrap()), helm_chart_name: "harmony-example-rust-webapp-chart".to_string(), - values_overrides: Value::Null, + values_overrides: None, name: "harmony-demo-rust-webapp".to_string(), namespace: "harmonydemo-staging".to_string(), })], @@ -226,7 +227,7 @@ pub struct CDApplicationConfig { pub version: Version, pub helm_chart_repo_url: Url, pub helm_chart_name: String, - pub values_overrides: Value, + pub values_overrides: Option, pub name: String, pub namespace: String, } diff --git a/harmony/src/modules/application/features/helm_argocd_score.rs b/harmony/src/modules/application/features/helm_argocd_score.rs index 92a468b..d5dbd44 100644 --- a/harmony/src/modules/application/features/helm_argocd_score.rs +++ b/harmony/src/modules/application/features/helm_argocd_score.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; use k8s_openapi::Resource; +use log::error; use non_blank_string_rs::NonBlankString; use serde::Serialize; use std::str::FromStr; @@ -50,6 +51,7 @@ impl Interpret for ArgoInterpret { inventory: &Inventory, topology: &T, ) -> Result { + error!("Uncomment below, only disabled for debugging"); self.score .create_interpret() .execute(inventory, topology) diff --git a/opnsense-config/Cargo.toml b/opnsense-config/Cargo.toml index bb9a425..f271d10 100644 --- a/opnsense-config/Cargo.toml +++ b/opnsense-config/Cargo.toml @@ -22,4 +22,4 @@ tokio-util = { version = "0.7.13", features = [ "codec" ] } tokio-stream = "0.1.17" [dev-dependencies] -pretty_assertions = "1.4.1" +pretty_assertions.workspace = true