Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose storageClass in CoreDB #414

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions charts/tembo-operator/templates/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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``` <quantity> ::= <signedNumber><suffix>\n\n\t(Note that <suffix> may be empty, from the \"\" case in <decimalSI>.)\n\n<digit> ::= 0 | 1 | ... | 9 <digits> ::= <digit> | <digit><digits> <number> ::= <digits> | <digits>.<digits> | <digits>. | .<digits> <sign> ::= \"+\" | \"-\" <signedNumber> ::= <number> | <sign><number> <suffix> ::= <binarySI> | <decimalExponent> | <decimalSI> <binarySI> ::= Ki | Mi | Gi | Ti | Pi | Ei\n\n\t(International System of units; See: http://physics.nist.gov/cuu/Units/binary.html)\n\n<decimalSI> ::= 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<decimalExponent> ::= \"e\" <signedNumber> | \"E\" <signedNumber> ```\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:
Expand Down
2 changes: 1 addition & 1 deletion tembo-operator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tembo-operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 4 additions & 0 deletions tembo-operator/src/apis/coredb_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ pub struct CoreDBSpec {

// instance restore from backup
pub restore: Option<Restore>,

// Expose storage class to allow user to specify a custom storage class
#[serde(rename = "storageClass")]
pub storage_class: Option<String>,
}

impl CoreDBSpec {
Expand Down
8 changes: 4 additions & 4 deletions tembo-operator/src/app_service/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use kube::{

use std::collections::BTreeMap;

use tracing::{debug, error, warn};
use tracing::{debug, error};

use super::{
manager::to_delete,
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
76 changes: 72 additions & 4 deletions tembo-operator/src/cloudnativepg/cnpg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -493,16 +492,22 @@ fn cnpg_postgres_config(

fn cnpg_cluster_storage(cdb: &CoreDB) -> Option<ClusterStorage> {
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<String> {
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<ClusterReplicationSlots> {
if cdb.spec.replicas > 1 {
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion tembo-operator/src/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
Loading