diff --git a/Cargo.lock b/Cargo.lock index ac4598b..f3befcc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1809,6 +1809,21 @@ dependencies = [ "url", ] +[[package]] +name = "example-nats" +version = "0.1.0" +dependencies = [ + "cidr", + "env_logger", + "harmony", + "harmony_cli", + "harmony_macros", + "harmony_types", + "log", + "tokio", + "url", +] + [[package]] name = "example-ntfy" version = "0.1.0" @@ -1883,6 +1898,36 @@ dependencies = [ "url", ] +[[package]] +name = "example-postgresql" +version = "0.1.0" +dependencies = [ + "cidr", + "env_logger", + "harmony", + "harmony_cli", + "harmony_macros", + "harmony_types", + "log", + "tokio", + "url", +] + +[[package]] +name = "example-public-postgres" +version = "0.1.0" +dependencies = [ + "cidr", + "env_logger", + "harmony", + "harmony_cli", + "harmony_macros", + "harmony_types", + "log", + "tokio", + "url", +] + [[package]] name = "example-pxe" version = "0.1.0" @@ -2435,6 +2480,7 @@ dependencies = [ "serde_json", "serde_with", "serde_yaml", + "serial_test", "similar", "sqlx", "strum 0.27.2", @@ -5116,6 +5162,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scc" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46e6f046b7fef48e2660c57ed794263155d713de679057f2d0c169bfc6e756cc" +dependencies = [ + "sdd", +] + [[package]] name = "schannel" version = "0.1.27" @@ -5200,6 +5255,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "sdd" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "490dcfcbfef26be6800d11870ff2df8774fa6e86d047e3e8c8a76b25655e41ca" + [[package]] name = "sec1" version = "0.7.3" @@ -5437,6 +5498,32 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "serial_test" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d0b343e184fc3b7bb44dff0705fffcf4b3756ba6aff420dddd8b24ca145e555" +dependencies = [ + "futures-executor", + "futures-util", + "log", + "once_cell", + "parking_lot", + "scc", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "3.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f50427f258fb77356e4cd4aa0e87e2bd2c66dbcee41dc405282cae2bfc26c83" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + [[package]] name = "sha1" version = "0.10.6" diff --git a/examples/nats/src/main.rs b/examples/nats/src/main.rs index a3e50d3..ca0d7d5 100644 --- a/examples/nats/src/main.rs +++ b/examples/nats/src/main.rs @@ -57,5 +57,7 @@ async fn main() { .await .unwrap(); - info!("Enjoy! You can test your nats cluster by running : `kubectl exec -n {namespace} -it deployment/nats-box -- nats pub test hi`"); + info!( + "Enjoy! You can test your nats cluster by running : `kubectl exec -n {namespace} -it deployment/nats-box -- nats pub test hi`" + ); } diff --git a/harmony/Cargo.toml b/harmony/Cargo.toml index 634cbe9..9086e84 100644 --- a/harmony/Cargo.toml +++ b/harmony/Cargo.toml @@ -79,6 +79,7 @@ sqlx.workspace = true inquire.workspace = true brocade = { path = "../brocade" } option-ext = "0.2.0" +serial_test = "3.3.1" [dev-dependencies] pretty_assertions.workspace = true diff --git a/harmony/src/domain/topology/k8s_anywhere/.k8s_anywhere.rs.swp b/harmony/src/domain/topology/k8s_anywhere/.k8s_anywhere.rs.swp new file mode 100644 index 0000000..ff072bd Binary files /dev/null and b/harmony/src/domain/topology/k8s_anywhere/.k8s_anywhere.rs.swp differ diff --git a/harmony/src/domain/topology/k8s_anywhere/k8s_anywhere.rs b/harmony/src/domain/topology/k8s_anywhere/k8s_anywhere.rs index 4e0337b..76971f0 100644 --- a/harmony/src/domain/topology/k8s_anywhere/k8s_anywhere.rs +++ b/harmony/src/domain/topology/k8s_anywhere/k8s_anywhere.rs @@ -1128,6 +1128,8 @@ impl Ingress for K8sAnywhereTopology { #[cfg(test)] mod tests { + use serial_test::serial; + use super::*; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -1167,6 +1169,7 @@ mod tests { } #[test] + #[serial] fn test_remote_k8s_from_env_var_full() { let (config_var, profile_var) = setup_env_vars(Some("kubeconfig=/foo.kc,context=bar"), Some("testprof")); @@ -1183,6 +1186,7 @@ mod tests { } #[test] + #[serial] fn test_remote_k8s_from_env_var_only_kubeconfig() { let (config_var, profile_var) = setup_env_vars(Some("kubeconfig=/foo.kc"), None); @@ -1195,6 +1199,7 @@ mod tests { } #[test] + #[serial] fn test_remote_k8s_from_env_var_only_context() { run_in_isolated_env(|| { unsafe { @@ -1211,6 +1216,7 @@ mod tests { } #[test] + #[serial] fn test_remote_k8s_from_env_var_unknown_key_trim() { run_in_isolated_env(|| { unsafe { @@ -1230,6 +1236,7 @@ mod tests { } #[test] + #[serial] fn test_remote_k8s_from_env_var_empty_malformed() { run_in_isolated_env(|| { unsafe { @@ -1247,6 +1254,7 @@ mod tests { } #[test] + #[serial] fn test_remote_k8s_from_env_var_kubeconfig_fallback() { run_in_isolated_env(|| { unsafe { @@ -1263,6 +1271,7 @@ mod tests { } #[test] + #[serial] fn test_remote_k8s_from_env_var_kubeconfig_no_fallback_if_provided() { run_in_isolated_env(|| { unsafe { diff --git a/harmony/src/domain/topology/k8s_anywhere/postgres.rs b/harmony/src/domain/topology/k8s_anywhere/postgres.rs index 7051a1b..2bf800b 100644 --- a/harmony/src/domain/topology/k8s_anywhere/postgres.rs +++ b/harmony/src/domain/topology/k8s_anywhere/postgres.rs @@ -29,7 +29,10 @@ impl PostgreSQL for K8sAnywhereTopology { /// Extracts PostgreSQL-specific replication certs (PEM format) from a deployed primary cluster. /// Abstracts away storage/retrieval details (e.g., secrets, files). - async fn get_replication_certs(&self, config: &PostgreSQLConfig) -> Result { + async fn get_replication_certs( + &self, + config: &PostgreSQLConfig, + ) -> Result { let cluster_name = &config.cluster_name; let namespace = &config.namespace; let k8s_client = self.k8s_client().await.map_err(|e| e.to_string())?; diff --git a/harmony/src/domain/topology/router.rs b/harmony/src/domain/topology/router.rs index 26aa572..5217c82 100644 --- a/harmony/src/domain/topology/router.rs +++ b/harmony/src/domain/topology/router.rs @@ -60,6 +60,7 @@ impl Router for UnmanagedRouter { /// hostname: "postgres-cluster-example.public.domain.io".to_string(), /// backend: "postgres-cluster-example-rw".to_string(), // k8s Service or HAProxy upstream /// target_port: 5432, +/// namespace: "sample-namespace".to_string(), /// }; /// ``` #[derive(Clone, Debug, Serialize)] @@ -115,11 +116,7 @@ pub trait TlsRouter: Send + Sync { /// routed to this cluster. /// /// For example, if we have *.apps.nationtech.io pointing to a public load balancer, then this - /// function would return - /// - /// ``` - /// Some(String::new("apps.nationtech.io")) - /// ``` + /// function would install route apps.nationtech.io async fn get_wildcard_domain(&self) -> Result, String>; /// Returns the port that this router exposes externally. diff --git a/harmony/src/modules/network/failover.rs b/harmony/src/modules/network/failover.rs index 9c99c5e..3880c02 100644 --- a/harmony/src/modules/network/failover.rs +++ b/harmony/src/modules/network/failover.rs @@ -5,10 +5,14 @@ use crate::topology::{FailoverTopology, TlsRoute, TlsRouter}; #[async_trait] impl TlsRouter for FailoverTopology { - async fn get_wildcard_domain(&self) -> Result, String> {todo!()} + async fn get_wildcard_domain(&self) -> Result, String> { + todo!() + } /// Returns the port that this router exposes externally. - async fn get_router_port(&self) -> u16 {todo!()} + async fn get_router_port(&self) -> u16 { + todo!() + } async fn install_route(&self, config: TlsRoute) -> Result<(), String> { warn!( "Failover topology TlsRouter capability currently defers to the primary only. Make sure to check this is OK for you. The Replica Topology WILL NOT be affected here" diff --git a/harmony/src/modules/network/tls_router.rs b/harmony/src/modules/network/tls_router.rs index 75f1a00..762f981 100644 --- a/harmony/src/modules/network/tls_router.rs +++ b/harmony/src/modules/network/tls_router.rs @@ -25,6 +25,7 @@ use crate::topology::{K8sclient, Topology}; /// backend: "postgres-cluster-rw".to_string(), /// hostname: "postgres-rw.example.com".to_string(), /// target_port: 5432, +/// namespace: "example-namespace".to_string(), /// }, /// }; /// ``` diff --git a/harmony/src/modules/postgresql/capability.rs b/harmony/src/modules/postgresql/capability.rs index 2de12a8..81ca83e 100644 --- a/harmony/src/modules/postgresql/capability.rs +++ b/harmony/src/modules/postgresql/capability.rs @@ -9,7 +9,10 @@ pub trait PostgreSQL: Send + Sync { /// Extracts PostgreSQL-specific replication certs (PEM format) from a deployed primary cluster. /// Abstracts away storage/retrieval details (e.g., secrets, files). - async fn get_replication_certs(&self, config: &PostgreSQLConfig) -> Result; + async fn get_replication_certs( + &self, + config: &PostgreSQLConfig, + ) -> Result; /// Gets the internal/private endpoint (e.g., k8s service FQDN:5432) for the cluster. async fn get_endpoint(&self, config: &PostgreSQLConfig) -> Result; diff --git a/harmony/src/modules/postgresql/score_public.rs b/harmony/src/modules/postgresql/score_public.rs index 66cf1a9..eaf3c88 100644 --- a/harmony/src/modules/postgresql/score_public.rs +++ b/harmony/src/modules/postgresql/score_public.rs @@ -69,9 +69,7 @@ struct PublicPostgreSQLInterpret { } #[async_trait] -impl Interpret - for PublicPostgreSQLInterpret -{ +impl Interpret for PublicPostgreSQLInterpret { async fn execute(&self, _inventory: &Inventory, topo: &T) -> Result { // Deploy CNPG cluster first (creates -rw service) topo.deploy(&self.config)