Skip to content

Commit

Permalink
update extension object (#34)
Browse files Browse the repository at this point in the history
* update extension object

* uncomment stuff

* update test

* update spec

* build

* update the version in tests

* Update reconciler-test.yml

* roll back comment

* Update reconciler-test.yml

* Update coredb_crd.rs

---------

Co-authored-by: Ian Stanton <ian@coredb.io>
  • Loading branch information
ChuckHend and ianstanton authored Mar 7, 2023
1 parent b0b57b0 commit e995db8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reconciler-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
helm install --namespace=traefik-v2 --values ./tests/traefik-values.yaml traefik traefik/traefik
# Install the CoreDB operator
cargo install --version 2023.2.15 coredb-cli
cargo install --version 2023.3.6 coredb-cli
coredb-cli install
kubectl get crds
Expand Down
1 change: 0 additions & 1 deletion reconciler/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Reconciler


The reconciler is responsible for creating, updating, deleting database instances (custom resource) on a kubernetes cluster.
It runs in each data plane and performs these actions based on messages written to a queue in the control plane.
Upon connecting to this queue, it will continuously poll for new messages posted by the `cp-service` component.
Expand Down
41 changes: 35 additions & 6 deletions reconciler/src/coredb_crd.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium coredbs.coredb.io
// kopium version: 0.14.0
// kopium version: 0.15.0

use kube::CustomResource;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

#[derive(CustomResource, Serialize, Deserialize, Clone, Debug)]
#[kube(
Expand All @@ -16,22 +17,50 @@ use serde::{Deserialize, Serialize};
#[kube(status = "CoreDBStatus")]
#[kube(schema = "disabled")]
pub struct CoreDBSpec {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub extensions: Option<Vec<CoreDBExtensions>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub image: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub port: Option<i32>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "enabledExtensions"
rename = "postgresExporterEnabled"
)]
pub enabled_extensions: Option<Vec<String>>,
pub postgres_exporter_enabled: Option<bool>,
#[serde(
default,
skip_serializing_if = "Option::is_none",
rename = "postgresExporterImage"
)]
pub postgres_exporter_image: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub image: Option<String>,
pub replicas: Option<i32>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub port: Option<i32>,
pub resources: Option<CoreDBResources>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub replicas: Option<i32>,
pub storage: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub uid: Option<i32>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CoreDBExtensions {
pub enabled: bool,
pub name: String,
pub schema: String,
pub version: String,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CoreDBResources {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub limits: Option<BTreeMap<String, String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub requests: Option<BTreeMap<String, String>>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CoreDBStatus {
pub running: bool,
Expand Down
2 changes: 1 addition & 1 deletion reconciler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn generate_spec(event_body: &types::EventBody) -> Value {
},
"spec": {
"replicas": 1,
"enabledExtensions": event_body.extensions
"extensions": event_body.extensions,
},
});
spec
Expand Down
4 changes: 2 additions & 2 deletions reconciler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
let msg_id = queue.send(&data_plane_events_queue, &msg).await?;
info!("msg_id: {:?}", msg_id);
}
None | _ => warn!("action was not in expected format"),
_ => warn!("action was not in expected format"),
}

// TODO(ianstanton) This is here as an example for now. We want to use
// TODO (ianstanton) This is here as an example for now. We want to use
// this to ensure a PostgresCluster exists before we attempt to delete it.
// Get all existing PostgresClusters
let vec = get_all(client.clone(), "default".to_owned());
Expand Down
27 changes: 26 additions & 1 deletion reconciler/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ pub struct CRUDevent {
pub body: EventBody,
}

pub enum UpdateEvent {
ToggleExtension,
UpdateInfra,
InstallExtension,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct EventBody {
pub resource_type: String,
pub resource_name: String,
pub storage: Option<String>,
pub memory: Option<String>,
pub cpu: Option<String>,
pub extensions: Option<Vec<String>>,
pub extensions: Option<Vec<Extension>>,
}

/// message returned to control plane
Expand All @@ -39,3 +45,22 @@ pub enum Status {
Up,
Deleted,
}

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct Extension {
pub name: String,
pub version: String,
pub enabled: bool,
pub schema: String,
}

impl Default for Extension {
fn default() -> Self {
Extension {
name: "pg_stat_statements".to_owned(),
version: "1.9".to_owned(),
enabled: true,
schema: "postgres".to_owned(),
}
}
}
2 changes: 1 addition & 1 deletion reconciler/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod test {
"storage": "1Gi",
"resource_name": name,
"resource_type": "CoreDB",
"enabled_extensions": ["postgis"],
"extensions": [{"name": "postgis", "enabled": true, "version": "1.1.1", "schema": "public"}],
},
"data_plane_id": "org_02s3owPQskuGXHE8vYsGSY",
"event_id": "coredb-poc1.org_02s3owPQskuGXHE8vYsGSY.CoreDB.inst_02s4UKVbRy34SAYVSwZq2H",
Expand Down

0 comments on commit e995db8

Please sign in to comment.