From 6f63289a11e0de36a3fe84788d8e2e961139b4f7 Mon Sep 17 00:00:00 2001 From: Lucas Fontes Date: Tue, 20 Aug 2024 15:33:52 -0400 Subject: [PATCH] feat: Configure max component memory (#91) * feat: Configure max component memory Signed-off-by: Lucas Fontes * chore: Bumping versions Signed-off-by: Lucas Fontes --------- Signed-off-by: Lucas Fontes --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- crates/types/Cargo.toml | 12 ++++++------ crates/types/src/v1alpha1/wasmcloud_host_config.rs | 2 ++ examples/full-config/wasmcloud-annotated.yaml | 2 ++ src/controller.rs | 8 ++++++++ 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e79d7ac..4cc3c36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3717,7 +3717,7 @@ dependencies = [ [[package]] name = "wasmcloud-operator" -version = "0.4.0" +version = "0.4.1" dependencies = [ "anyhow", "async-nats", @@ -3757,7 +3757,7 @@ dependencies = [ [[package]] name = "wasmcloud-operator-types" -version = "0.1.7" +version = "0.1.8" dependencies = [ "k8s-openapi", "kube", diff --git a/Cargo.toml b/Cargo.toml index 4798341..02c51c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmcloud-operator" -version = "0.4.0" +version = "0.4.1" edition = "2021" [[bin]] @@ -77,7 +77,7 @@ opentelemetry_sdk = { version = "0.21", features = [ "metrics", "trace", "rt-tokio", -]} +] } opentelemetry-otlp = { version = "0.14", features = ["tokio"] } rcgen = "0.11" schemars = "0.8" diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 369f793..bf2a0dd 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "wasmcloud-operator-types" -version = "0.1.7" +version = "0.1.8" edition = "2021" [dependencies] -k8s-openapi = {workspace = true} -kube = {workspace = true, features = ["derive"]} -schemars = {workspace = true} -serde = {workspace = true} -serde_json = {workspace = true} +k8s-openapi = { workspace = true } +kube = { workspace = true, features = ["derive"] } +schemars = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } diff --git a/crates/types/src/v1alpha1/wasmcloud_host_config.rs b/crates/types/src/v1alpha1/wasmcloud_host_config.rs index 46e4337..5514e31 100644 --- a/crates/types/src/v1alpha1/wasmcloud_host_config.rs +++ b/crates/types/src/v1alpha1/wasmcloud_host_config.rs @@ -82,6 +82,8 @@ pub struct WasmCloudHostConfigSpec { pub certificates: Option, /// wasmCloud secrets topic prefix, must not be empty if set. pub secrets_topic_prefix: Option, + /// Maximum memory in bytes that components can use. + pub max_linear_memory_bytes: Option, } #[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)] diff --git a/examples/full-config/wasmcloud-annotated.yaml b/examples/full-config/wasmcloud-annotated.yaml index 58a1cb2..26f738c 100644 --- a/examples/full-config/wasmcloud-annotated.yaml +++ b/examples/full-config/wasmcloud-annotated.yaml @@ -71,6 +71,8 @@ spec: # Optional: Subject prefix that will be used by the host to query for wasmCloud Secrets. # See https://wasmcloud.com/docs/concepts/secrets for more context secretsTopicPrefix: "wasmcloud.secrets" + # Optional: The maximum amount of memory bytes that a component can allocate. + maxLinearMemoryBytes: 20000000 # Optional: Additional options to control how the underlying wasmCloud hosts are scheduled in Kubernetes. # This includes setting resource requirements for the nats and wasmCloud host # containers along with any additional pot template settings. diff --git a/src/controller.rs b/src/controller.rs index 06b98ce..c08038c 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -381,6 +381,14 @@ async fn pod_template(config: &WasmCloudHostConfig, ctx: Arc) -> Result }) } + if let Some(max_linear_memory_bytes) = &config.spec.max_linear_memory_bytes { + wasmcloud_env.push(EnvVar { + name: "WASMCLOUD_MAX_LINEAR_MEMORY".to_string(), + value: Some(max_linear_memory_bytes.to_string()), + ..Default::default() + }) + } + let mut wasmcloud_args = configure_observability(&config.spec); let mut nats_resources: Option = None;