diff --git a/examples/nats/Cargo.toml b/examples/nats/Cargo.toml new file mode 100644 index 0000000..2d2dcec --- /dev/null +++ b/examples/nats/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "example-nats" +edition = "2024" +version.workspace = true +readme.workspace = true +license.workspace = true +publish = false + +[dependencies] +harmony = { path = "../../harmony" } +harmony_cli = { path = "../../harmony_cli" } +harmony_types = { path = "../../harmony_types" } +cidr = { workspace = true } +tokio = { workspace = true } +harmony_macros = { path = "../../harmony_macros" } +log = { workspace = true } +env_logger = { workspace = true } +url = { workspace = true } diff --git a/examples/nats/src/main.rs b/examples/nats/src/main.rs new file mode 100644 index 0000000..a3e50d3 --- /dev/null +++ b/examples/nats/src/main.rs @@ -0,0 +1,61 @@ +use std::str::FromStr; + +use harmony::{ + inventory::Inventory, + modules::helm::chart::{HelmChartScore, HelmRepository, NonBlankString}, + topology::K8sAnywhereTopology, +}; +use harmony_macros::hurl; +use log::info; + +#[tokio::main] +async fn main() { + // env_logger::init(); + let values_yaml = Some( + r#"config: + cluster: + enabled: true + replicas: 3 + jetstream: + enabled: true + fileStorage: + enabled: true + size: 10Gi + storageDirectory: /data/jetstream + leafnodes: + enabled: false + # port: 7422 + gateway: + enabled: false + # name: my-gateway + # port: 7522"# + .to_string(), + ); + let namespace = "nats"; + let nats = HelmChartScore { + namespace: Some(NonBlankString::from_str(namespace).unwrap()), + release_name: NonBlankString::from_str("nats").unwrap(), + chart_name: NonBlankString::from_str("nats/nats").unwrap(), + chart_version: None, + values_overrides: None, + values_yaml, + create_namespace: true, + install_only: true, + repository: Some(HelmRepository::new( + "nats".to_string(), + hurl!("https://nats-io.github.io/k8s/helm/charts/"), + true, + )), + }; + + harmony_cli::run( + Inventory::autoload(), + K8sAnywhereTopology::from_env(), + vec![Box::new(nats)], + None, + ) + .await + .unwrap(); + + info!("Enjoy! You can test your nats cluster by running : `kubectl exec -n {namespace} -it deployment/nats-box -- nats pub test hi`"); +}