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

move Stacks objects to tembo-stacks #764

Merged
merged 9 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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.46.0"
version = "0.47.0"
edition = "2021"
default-run = "controller"
license = "Apache-2.0"
Expand Down
25 changes: 18 additions & 7 deletions tembo-operator/src/defaults.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
use k8s_openapi::{
api::core::v1::ResourceRequirements,
apimachinery::pkg::{api::resource::Quantity, util::intstr::IntOrString},
};
use std::collections::BTreeMap;

use crate::apis::coredb_types::CoreDB;
use crate::{
apis::coredb_types::{
Expand All @@ -12,8 +6,25 @@ use crate::{
cloudnativepg::clusters::ClusterAffinity,
cloudnativepg::poolers::{PoolerPgbouncerPoolMode, PoolerTemplateSpecContainersResources},
extensions::types::{Extension, TrunkInstall},
stacks::types::ImagePerPgVersion,
};
use k8s_openapi::{
api::core::v1::ResourceRequirements,
apimachinery::pkg::{api::resource::Quantity, util::intstr::IntOrString},
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use utoipa::ToSchema;

#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, ToSchema)]
pub struct ImagePerPgVersion {
#[serde(rename = "14")]
pub pg14: String,
#[serde(rename = "15")]
pub pg15: String,
#[serde(rename = "16")]
pub pg16: String,
}

pub fn default_replicas() -> i32 {
1
Expand Down
1 change: 0 additions & 1 deletion tembo-operator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod app_service;
pub mod configmap;
pub mod extensions;
pub mod postgres_exporter;
pub mod stacks;
/// Log and trace integrations
pub mod telemetry;

Expand Down
3 changes: 0 additions & 3 deletions tembo-operator/src/stacks/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions tembo-operator/src/stacks/mod.rs

This file was deleted.

116 changes: 0 additions & 116 deletions tembo-operator/src/stacks/types.rs

This file was deleted.

7 changes: 4 additions & 3 deletions tembo-stacks/Cargo.lock

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

7 changes: 4 additions & 3 deletions tembo-stacks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tembo-stacks"
description = "Tembo Stacks for Postgres"
version = "0.6.0"
version = "0.7.0"
authors = ["tembo.io"]
edition = "2021"
license = "Apache-2.0"
Expand All @@ -11,14 +11,15 @@ repository = "https://github.com/tembo-io/tembo"
[dependencies]
anyhow = "1.0.71"
futures = "0.3.28"
k8s-openapi = { version = "0.18.0", features = ["v1_25", "schemars"], default-features = false } # This version has to be in line with the same version we use in the controller
lazy_static = "1.4.0"
regex = "1.10.4"
schemars = {version = "0.8.12", features = ["chrono"]}
k8s-openapi = { version = "0.18.0", features = ["v1_25", "schemars"], default-features = false } # This version has to be in line with the same version we use in the controller
serde = "1.0.152"
serde_yaml = "0.9.21"
strum = "0.26.2"
strum_macros = "0.26.2"
tembo-controller = { package = "controller", version = "0.46.0" }
tembo-controller = { package = "controller", version = "0.47.0" }
tracing = "0.1"
utoipa = { version = "3", features = ["actix_extras", "chrono"] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

use crate::{
use crate::stacks::types::Stack;
use lazy_static::lazy_static;
use regex::Regex;
use tembo_controller::{
apis::postgres_parameters::{ConfigValue, PgConfig},
errors::ValueError,
stacks::types::Stack,
};

const DEFAULT_MAINTENANCE_WORK_MEM_MB: i32 = 64;
Expand Down Expand Up @@ -288,14 +290,10 @@ fn dynamic_effective_cache_size_mb(sys_mem_mb: i32) -> i32 {
(sys_mem_mb as f64 * EFFECTIVE_CACHE_SIZE).floor() as i32
}

use lazy_static::lazy_static;

lazy_static! {
static ref RE: Regex = Regex::new(r"^([0-9]*\.?[0-9]+)([a-zA-Z]+)$").unwrap();
}

use regex::Regex;

fn split_string(input: &str) -> Result<(f64, String), ValueError> {
if let Some(cap) = RE.captures(input) {
let num = cap[1].parse::<f64>()?;
Expand Down
4 changes: 2 additions & 2 deletions tembo-stacks/src/stacks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod config_engines;
pub mod types;

use crate::stacks::types::StackType;
use tembo_controller::stacks::types::Stack;
use crate::stacks::types::{Stack, StackType};

use lazy_static::lazy_static;

Expand Down
104 changes: 104 additions & 0 deletions tembo-stacks/src/stacks/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
use crate::stacks::config_engines::{
mq_config_engine, olap_config_engine, standard_config_engine, ConfigEngine,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use tembo_controller::{
apis::postgres_parameters::PgConfig,
app_service::types::AppService,
defaults::ImagePerPgVersion,
defaults::{default_images, default_repository},
extensions::types::{Extension, TrunkInstall},
postgres_exporter::QueryConfig,
};
use utoipa::ToSchema;

#[derive(
Expand Down Expand Up @@ -71,6 +82,99 @@ impl StackType {
}
}

#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, ToSchema)]
pub struct Stack {
pub name: String,
/// specifies any resource constraints that should be applied to an instance of the Stack
pub compute_constraints: Option<ComputeConstraint>,
pub description: Option<String>,
/// Organization hosting the Docker images used in this stack
/// Default: "tembo"
#[serde(default = "default_organization")]
pub organization: String,
#[serde(default = "default_stack_repository")]
pub repository: String,
/// The Docker images to use for each supported Postgres versions
///
/// Default:
/// 14: "standard-cnpg:14-a0a5ab5"
/// 15: "standard-cnpg:15-a0a5ab5"
/// 16: "standard-cnpg:16-a0a5ab5"
#[serde(default = "default_images")]
pub images: ImagePerPgVersion,
pub stack_version: Option<String>,
pub trunk_installs: Option<Vec<TrunkInstall>>,
pub extensions: Option<Vec<Extension>>,
/// Postgres metric definition specific to the Stack
pub postgres_metrics: Option<QueryConfig>,
/// configs are strongly typed so that they can be programmatically transformed
pub postgres_config: Option<Vec<PgConfig>>,
#[serde(default = "default_config_engine")]
pub postgres_config_engine: Option<ConfigEngine>,
/// external application services
pub infrastructure: Option<Infrastructure>,
#[serde(rename = "appServices")]
pub app_services: Option<Vec<AppService>>,
}

#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, JsonSchema, PartialEq)]
pub struct ComputeConstraint {
pub min: Option<ComputeResource>,
}

#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, JsonSchema, PartialEq)]
pub struct ComputeResource {
pub cpu: Option<String>,
pub memory: Option<String>,
}

impl Stack {
// https://www.postgresql.org/docs/current/runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-MEMORY
pub fn runtime_config(&self) -> Option<Vec<PgConfig>> {
match &self.postgres_config_engine {
Some(ConfigEngine::Standard) => Some(standard_config_engine(self)),
Some(ConfigEngine::OLAP) => Some(olap_config_engine(self)),
Some(ConfigEngine::MQ) => Some(mq_config_engine(self)),
None => Some(standard_config_engine(self)),
}
}
}

fn default_organization() -> String {
"tembo".into()
}

fn default_stack_repository() -> String {
default_repository()
}

fn default_config_engine() -> Option<ConfigEngine> {
Some(ConfigEngine::Standard)
}

#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema, PartialEq, ToSchema)]
pub struct Infrastructure {
// generic specs
#[serde(default = "default_cpu")]
pub cpu: String,
#[serde(default = "default_memory")]
pub memory: String,
#[serde(default = "default_storage")]
pub storage: String,
}

fn default_cpu() -> String {
"1".to_owned()
}

fn default_memory() -> String {
"1Gi".to_owned()
}

fn default_storage() -> String {
"10Gi".to_owned()
}

#[cfg(test)]
mod tests {
use crate::stacks::{get_stack, types::StackType};
Expand Down
Loading