From 2e367d88d4a5bf37e415854de7c41f637ef46f8a Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Thu, 11 Dec 2025 22:54:57 -0500 Subject: [PATCH] feat: PostgreSQL score works, added postgresql example, tested on OKD 4.19, added note about incompatible default namespace settings --- examples/postgresql/Cargo.toml | 18 ++++++++++++++++++ examples/postgresql/src/main.rs | 22 ++++++++++++++++++++++ harmony/src/modules/postgresql/cnpg/crd.rs | 1 + harmony/src/modules/postgresql/score.rs | 10 ++++++++-- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 examples/postgresql/Cargo.toml create mode 100644 examples/postgresql/src/main.rs diff --git a/examples/postgresql/Cargo.toml b/examples/postgresql/Cargo.toml new file mode 100644 index 0000000..df160a7 --- /dev/null +++ b/examples/postgresql/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "example-postgresql" +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/postgresql/src/main.rs b/examples/postgresql/src/main.rs new file mode 100644 index 0000000..13da98a --- /dev/null +++ b/examples/postgresql/src/main.rs @@ -0,0 +1,22 @@ +use harmony::{ + inventory::Inventory, modules::postgresql::PostgreSQLScore, topology::K8sAnywhereTopology, +}; + +#[tokio::main] +async fn main() { + let postgresql = PostgreSQLScore { + name: "harmony-postgres-example".to_string(), // Override default name + namespace: "harmony-postgres-example".to_string(), + ..Default::default() // Use harmony defaults, they are based on CNPG's default values : + // "default" namespace, 1 instance, 1Gi storage + }; + + harmony_cli::run( + Inventory::autoload(), + K8sAnywhereTopology::from_env(), + vec![Box::new(postgresql)], + None, + ) + .await + .unwrap(); +} diff --git a/harmony/src/modules/postgresql/cnpg/crd.rs b/harmony/src/modules/postgresql/cnpg/crd.rs index fad1003..5f06156 100644 --- a/harmony/src/modules/postgresql/cnpg/crd.rs +++ b/harmony/src/modules/postgresql/cnpg/crd.rs @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize}; namespaced = true, schema = "disabled" )] +#[serde(rename_all = "camelCase")] pub struct ClusterSpec { pub instances: i32, pub image_name: Option, diff --git a/harmony/src/modules/postgresql/score.rs b/harmony/src/modules/postgresql/score.rs index d32c1fc..2a5e82f 100644 --- a/harmony/src/modules/postgresql/score.rs +++ b/harmony/src/modules/postgresql/score.rs @@ -27,6 +27,9 @@ use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta; /// specific behavior #[derive(Debug, Clone, Serialize)] pub struct PostgreSQLScore { + pub name: String, + /// **Note :** on OpenShfit based clusters, the namespace `default` has security + /// settings incompatible with the default CNPG behavior. pub namespace: String, pub instances: i32, pub storage_size: String, @@ -36,7 +39,10 @@ pub struct PostgreSQLScore { impl Default for PostgreSQLScore { fn default() -> Self { Self { - namespace: "default".to_string(), + name: "harmony-pg".to_string(), + // We are using the namespace harmony by default since some clusters (openshift family) + // have incompatible configuration of the default namespace with cnpg + namespace: "harmony".to_string(), instances: 1, storage_size: "1Gi".to_string(), image_name: None, // This lets cnpg use its default image @@ -56,7 +62,7 @@ impl PostgreSQLScore { impl Score for PostgreSQLScore { fn create_interpret(&self) -> Box> { let metadata = ObjectMeta { - name: Some("postgres".to_string()), + name: Some(self.name.clone()), namespace: Some(self.namespace.clone()), ..ObjectMeta::default() };