diff --git a/charts/tembo-operator/templates/crd.yaml b/charts/tembo-operator/templates/crd.yaml index ae2027446..c04e05d42 100644 --- a/charts/tembo-operator/templates/crd.yaml +++ b/charts/tembo-operator/templates/crd.yaml @@ -1826,6 +1826,9 @@ spec: default: 8Gi description: "Quantity is a fixed-point representation of a number. It provides convenient marshaling/unmarshaling in JSON and YAML, in addition to String() and AsInt64() accessors.\n\nThe serialization format is:\n\n``` ::= \n\n\t(Note that may be empty, from the \"\" case in .)\n\n ::= 0 | 1 | ... | 9 ::= | ::= | . | . | . ::= \"+\" | \"-\" ::= | ::= | | ::= Ki | Mi | Gi | Ti | Pi | Ei\n\n\t(International System of units; See: http://physics.nist.gov/cuu/Units/binary.html)\n\n ::= m | \"\" | k | M | G | T | P | E\n\n\t(Note that 1024 = 1Ki but 1000 = 1k; I didn't choose the capitalization.)\n\n ::= \"e\" | \"E\" ```\n\nNo matter which of the three exponent forms is used, no quantity may represent a number greater than 2^63-1 in magnitude, nor may it have more than 3 decimal places. Numbers larger or more precise will be capped or rounded up. (E.g.: 0.1m will rounded up to 1m.) This may be extended in the future if we require larger or smaller quantities.\n\nWhen a Quantity is parsed from a string, it will remember the type of suffix it had, and will use the same type again when it is serialized.\n\nBefore serializing, Quantity will be put in \"canonical form\". This means that Exponent/suffix will be adjusted up or down (with a corresponding increase or decrease in Mantissa) such that:\n\n- No precision is lost - No fractional digits will be emitted - The exponent (or suffix) is as large as possible.\n\nThe sign will be omitted unless the number is negative.\n\nExamples:\n\n- 1.5 will be serialized as \"1500m\" - 1.5Gi will be serialized as \"1536Mi\"\n\nNote that the quantity will NEVER be internally represented by a floating point number. That is the whole point of this exercise.\n\nNon-canonical values will still parse as long as they are well formed, but will be re-emitted in their canonical form. (So always use canonical form, or don't diff.)\n\nThis format is intended to make it difficult to use these numbers without writing some sort of special handling code in the hopes that that will cause implementors to also use a fixed point implementation." type: string + storageClass: + nullable: true + type: string trunk_installs: default: [] items: diff --git a/tembo-operator/Cargo.lock b/tembo-operator/Cargo.lock index 9d6b77129..cbd1b3c66 100644 --- a/tembo-operator/Cargo.lock +++ b/tembo-operator/Cargo.lock @@ -494,7 +494,7 @@ dependencies = [ [[package]] name = "controller" -version = "0.24.1" +version = "0.25.0" dependencies = [ "actix-web", "anyhow", diff --git a/tembo-operator/Cargo.toml b/tembo-operator/Cargo.toml index 14e2eefd3..ee27ff3ee 100644 --- a/tembo-operator/Cargo.toml +++ b/tembo-operator/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "controller" description = "Tembo Operator for Postgres" -version = "0.24.1" +version = "0.25.0" edition = "2021" default-run = "controller" license = "Apache-2.0" diff --git a/tembo-operator/src/apis/coredb_types.rs b/tembo-operator/src/apis/coredb_types.rs index 6aa2c9d38..756ac127a 100644 --- a/tembo-operator/src/apis/coredb_types.rs +++ b/tembo-operator/src/apis/coredb_types.rs @@ -198,6 +198,10 @@ pub struct CoreDBSpec { // instance restore from backup pub restore: Option, + + // Expose storage class to allow user to specify a custom storage class + #[serde(rename = "storageClass")] + pub storage_class: Option, } impl CoreDBSpec { diff --git a/tembo-operator/src/app_service/ingress.rs b/tembo-operator/src/app_service/ingress.rs index 5714ff6eb..20192d30d 100644 --- a/tembo-operator/src/app_service/ingress.rs +++ b/tembo-operator/src/app_service/ingress.rs @@ -17,7 +17,7 @@ use kube::{ use std::collections::BTreeMap; -use tracing::{debug, error, warn}; +use tracing::{debug, error}; use super::{ manager::to_delete, @@ -79,7 +79,7 @@ fn generate_ingress_tcp( IngressRouteTCP { metadata: ObjectMeta { // using coredb name, since we'll have 1x ingress per coredb - name: Some(format!("{}", name)), + name: Some(name.to_string()), namespace: Some(namespace.to_owned()), owner_references: Some(vec![oref]), labels: Some(labels.clone()), @@ -352,7 +352,7 @@ pub async fn reconcile_ingress( let ingress = generate_ingress(coredb_name, ns, oref, desired_routes.clone(), entry_points); if desired_routes.is_empty() { // we don't need an IngressRoute when there are no routes - let lp = ListParams::default().labels(&format!("component=appService")); + let lp = ListParams::default().labels("component=appService"); // Check if there are any IngressRoute objects with the label component=appService and delete them let ingress_routes = ingress_api.list(&lp).await?; if let Some(ingress_route) = ingress_routes.into_iter().next() { @@ -438,7 +438,7 @@ pub async fn reconcile_ingress_tcp( let ingress = generate_ingress_tcp(&name, ns, oref, desired_routes.clone(), entry_points_tcp); if desired_routes.is_empty() { // we don't need an IngressRouteTCP when there are no routes - let lp = ListParams::default().labels(&format!("component=appService")); + let lp = ListParams::default().labels("component=appService"); // Check if there are any IngressRouteTCP objects with the label component=appService and delete them let ingress_tcp_routes = ingress_api.list(&lp).await?; if let Some(ingress_tcp_route) = ingress_tcp_routes.into_iter().next() { diff --git a/tembo-operator/src/cloudnativepg/cnpg.rs b/tembo-operator/src/cloudnativepg/cnpg.rs index 54f8e33dd..eb14248ed 100644 --- a/tembo-operator/src/cloudnativepg/cnpg.rs +++ b/tembo-operator/src/cloudnativepg/cnpg.rs @@ -409,7 +409,6 @@ pub fn cnpg_cluster_bootstrap_from_cdb( max_parallel: Some(5), encryption: Some(ClusterExternalClustersBarmanObjectStoreWalEncryption::Aes256), compression: Some(ClusterExternalClustersBarmanObjectStoreWalCompression::Snappy), - ..ClusterExternalClustersBarmanObjectStoreWal::default() }), server_name: Some(restore.server_name.clone()), ..ClusterExternalClustersBarmanObjectStore::default() @@ -493,16 +492,22 @@ fn cnpg_postgres_config( fn cnpg_cluster_storage(cdb: &CoreDB) -> Option { let storage = cdb.spec.storage.clone().0; + let storage_class = cnpg_cluster_storage_class(cdb); Some(ClusterStorage { resize_in_use_volumes: Some(true), size: Some(storage), - // TODO: pass storage class from cdb - // storage_class: Some("gp3-enc".to_string()), - storage_class: None, + storage_class, ..ClusterStorage::default() }) } +fn cnpg_cluster_storage_class(cdb: &CoreDB) -> Option { + match &cdb.spec.storage_class { + Some(storage_class) if !storage_class.is_empty() => Some(storage_class.clone()), + _ => None, + } +} + // Check replica count to enable HA fn cnpg_high_availability(cdb: &CoreDB) -> Option { if cdb.spec.replicas > 1 { @@ -2347,4 +2352,67 @@ mod tests { let result = parse_target_time(Some("invalid-format")); assert!(result.is_err()); // check for error } + + #[test] + fn test_cnpg_cluster_storage_class() { + let cdb_storage_class_yaml = r#" + apiVersion: coredb.io/v1alpha1 + kind: CoreDB + metadata: + name: test + namespace: default + spec: + image: quay.io/tembo/tembo-pg-cnpg:15.3.0-5-48d489e + port: 5432 + postgresExporterEnabled: true + postgresExporterImage: quay.io/prometheuscommunity/postgres-exporter:v0.12.1 + replicas: 1 + resources: + limits: + cpu: "1" + memory: 0.5Gi + serviceAccountTemplate: + metadata: + annotations: + eks.amazonaws.com/role-arn: arn:aws:iam::012345678901:role/aws-iam-role-iam + sharedirStorage: 1Gi + stop: false + storage: 1Gi + storageClass: "gp3-enc" + uid: 999 + "#; + let cdb_storage_class: CoreDB = from_str(cdb_storage_class_yaml).unwrap(); + assert_eq!( + cnpg_cluster_storage_class(&cdb_storage_class), + Some("gp3-enc".to_string()) + ); + + let cdb_no_storage_class_yaml = r#" + apiVersion: coredb.io/v1alpha1 + kind: CoreDB + metadata: + name: test + namespace: default + spec: + image: quay.io/tembo/tembo-pg-cnpg:15.3.0-5-48d489e + port: 5432 + postgresExporterEnabled: true + postgresExporterImage: quay.io/prometheuscommunity/postgres-exporter:v0.12.1 + replicas: 1 + resources: + limits: + cpu: "1" + memory: 0.5Gi + serviceAccountTemplate: + metadata: + annotations: + eks.amazonaws.com/role-arn: arn:aws:iam::012345678901:role/aws-iam-role-iam + sharedirStorage: 1Gi + stop: false + storage: 1Gi + uid: 999 + "#; + let cdb_no_storage_class: CoreDB = from_str(cdb_no_storage_class_yaml).unwrap(); + assert_eq!(cnpg_cluster_storage_class(&cdb_no_storage_class), None); + } } diff --git a/tembo-operator/src/ingress.rs b/tembo-operator/src/ingress.rs index d41ffb8f6..0c641cf87 100644 --- a/tembo-operator/src/ingress.rs +++ b/tembo-operator/src/ingress.rs @@ -340,7 +340,7 @@ pub async fn reconcile_postgres_ing_route_tcp( present_matchers_list.push(matcher_actual.clone()); // Check if either the service name or port are mismatched - if !(service_name_actual == service_name && service_port_actual == port) && !app_svc_label { + if !(app_svc_label || service_name_actual == service_name && service_port_actual == port) { // This situation should only occur when the service name or port is changed, for example during cut-over from // CoreDB operator managing the service to CNPG managing the service. warn!(