diff --git a/keramik/src/advanced_configuration.md b/keramik/src/advanced_configuration.md index a87b6d91..d43810d5 100644 --- a/keramik/src/advanced_configuration.md +++ b/keramik/src/advanced_configuration.md @@ -154,6 +154,25 @@ spec: memory: "1Gi" ``` +# CAS API Configuration + +The CAS API environment variables can be set or overridden through the network configuration. + +```yaml +# network configuration +--- +apiVersion: "keramik.3box.io/v1alpha1" +kind: Network +metadata: + name: small +spec: + replicas: 0 + cas: + api: + env: + APP_PORT: "8080" +``` + # Enabling Recon You can also use Recon for reconciliation by setting 'CERAMIC_ONE_RECON' env variable to true. diff --git a/operator/src/network/cas.rs b/operator/src/network/cas.rs index 575c214a..b655051b 100644 --- a/operator/src/network/cas.rs +++ b/operator/src/network/cas.rs @@ -30,8 +30,9 @@ use crate::{ ipfs::{IpfsConfig, IpfsInfo, IPFS_DATA_PV_CLAIM}, node_affinity::NodeAffinityConfig, resource_limits::ResourceLimitsConfig, - CasSpec, + CasApiSpec, CasSpec, }, + utils::override_env_vars, }; const CAS_IPFS_INFO_SUFFIX: &str = "cas"; @@ -44,6 +45,18 @@ pub struct CasConfig { pub ganache_resource_limits: ResourceLimitsConfig, pub postgres_resource_limits: ResourceLimitsConfig, pub localstack_resource_limits: ResourceLimitsConfig, + pub api: CasApiConfig, +} + +#[derive(Default)] +pub struct CasApiConfig { + pub env: Option>, +} + +impl From for CasApiConfig { + fn from(value: CasApiSpec) -> Self { + Self { env: value.env } + } } impl CasConfig { @@ -89,6 +102,7 @@ impl Default for CasConfig { memory: Some(Quantity("1Gi".to_owned())), storage: Quantity("1Gi".to_owned()), }, + api: Default::default(), } } } @@ -125,6 +139,7 @@ impl From for CasConfig { value.localstack_resource_limits, default.localstack_resource_limits, ), + api: value.api.map(Into::into).unwrap_or(default.api), } } } @@ -293,6 +308,9 @@ pub fn cas_stateful_set_spec( datadog.inject_env(&mut cas_api_env); + // Apply the CAS API env overrides, if specified. + override_env_vars(&mut cas_api_env, &config.api.env); + StatefulSetSpec { replicas: Some(1), selector: LabelSelector { diff --git a/operator/src/network/ceramic.rs b/operator/src/network/ceramic.rs index c33874ac..6ebc3047 100644 --- a/operator/src/network/ceramic.rs +++ b/operator/src/network/ceramic.rs @@ -31,6 +31,7 @@ use crate::{ resource_limits::ResourceLimitsConfig, CeramicSpec, NetworkSpec, NetworkType, }, + utils::override_env_vars, }; use super::debug_mode_security_context; @@ -400,22 +401,8 @@ pub fn stateful_set_spec(ns: &str, bundle: &CeramicBundle<'_>) -> StatefulSetSpe }) } - if let Some(extra_env) = &bundle.config.env { - extra_env.iter().for_each(|(key, value)| { - if let Some((pos, _)) = ceramic_env - .iter() - .enumerate() - .find(|(_, var)| &var.name == key) - { - ceramic_env.swap_remove(pos); - } - ceramic_env.push(EnvVar { - name: key.to_string(), - value: Some(value.to_string()), - ..Default::default() - }) - }); - } + // Apply env overrides, if specified. + override_env_vars(&mut ceramic_env, &bundle.config.env); let mut init_env = vec![EnvVar { name: "CERAMIC_ADMIN_PRIVATE_KEY".to_owned(), diff --git a/operator/src/network/controller.rs b/operator/src/network/controller.rs index d5b89916..34cd60dd 100644 --- a/operator/src/network/controller.rs +++ b/operator/src/network/controller.rs @@ -1092,6 +1092,7 @@ mod tests { }, }; + use crate::network::CasApiSpec; use expect_test::{expect, expect_file}; use k8s_openapi::{ api::{ @@ -2269,40 +2270,40 @@ mod tests { { - "env": [ - { - - "name": "CERAMIC_ONE_BIND_ADDRESS", - - "value": "0.0.0.0:5001" + - "name": "RUST_LOG", + - "value": "info,ceramic_one=debug,multipart=error" - }, - { - - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - - "value": "1" + - "name": "CERAMIC_ONE_BIND_ADDRESS", + - "value": "0.0.0.0:5001" - }, - { - - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - - "value": "6" + - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + - "value": "0.0.0.0:9465" - }, - { - - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - - "value": "0" + - "name": "CERAMIC_ONE_SWARM_ADDRESSES", + - "value": "/ip4/0.0.0.0/tcp/4001" - }, - { - - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - - "value": "0.0.0.0:9465" + - "name": "CERAMIC_ONE_STORE_DIR", + - "value": "/data/ipfs" - }, - { - "name": "CERAMIC_ONE_NETWORK", - "value": "local" - }, - { - - "name": "CERAMIC_ONE_STORE_DIR", - - "value": "/data/ipfs" + - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + - "value": "0" - }, - { - - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - - "value": "/ip4/0.0.0.0/tcp/4001" + - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + - "value": "6" - }, - { - - "name": "RUST_LOG", - - "value": "info,ceramic_one=debug,multipart=error" + - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + - "value": "1" - } - ], - "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", @@ -2398,40 +2399,40 @@ mod tests { { - "env": [ - { - - "name": "CERAMIC_ONE_BIND_ADDRESS", - - "value": "0.0.0.0:5001" + - "name": "RUST_LOG", + - "value": "info,ceramic_one=debug,multipart=error" - }, - { - - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - - "value": "1" + - "name": "CERAMIC_ONE_BIND_ADDRESS", + - "value": "0.0.0.0:5001" - }, - { - - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - - "value": "6" + - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + - "value": "0.0.0.0:9465" - }, - { - - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - - "value": "0" + - "name": "CERAMIC_ONE_SWARM_ADDRESSES", + - "value": "/ip4/0.0.0.0/tcp/4001" - }, - { - - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - - "value": "0.0.0.0:9465" + - "name": "CERAMIC_ONE_STORE_DIR", + - "value": "/data/ipfs" - }, - { - "name": "CERAMIC_ONE_NETWORK", - "value": "local" - }, - { - - "name": "CERAMIC_ONE_STORE_DIR", - - "value": "/data/ipfs" + - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + - "value": "0" - }, - { - - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - - "value": "/ip4/0.0.0.0/tcp/4001" + - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + - "value": "6" - }, - { - - "name": "RUST_LOG", - - "value": "info,ceramic_one=debug,multipart=error" + - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + - "value": "1" - } - ], - "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", @@ -2546,40 +2547,40 @@ mod tests { { - "env": [ - { - - "name": "CERAMIC_ONE_BIND_ADDRESS", - - "value": "0.0.0.0:5001" + - "name": "RUST_LOG", + - "value": "info,ceramic_one=debug,multipart=error" - }, - { - - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - - "value": "1" + - "name": "CERAMIC_ONE_BIND_ADDRESS", + - "value": "0.0.0.0:5001" - }, - { - - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - - "value": "6" + - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + - "value": "0.0.0.0:9465" - }, - { - - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - - "value": "0" + - "name": "CERAMIC_ONE_SWARM_ADDRESSES", + - "value": "/ip4/0.0.0.0/tcp/4001" - }, - { - - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - - "value": "0.0.0.0:9465" + - "name": "CERAMIC_ONE_STORE_DIR", + - "value": "/data/ipfs" - }, - { - "name": "CERAMIC_ONE_NETWORK", - "value": "local" - }, - { - - "name": "CERAMIC_ONE_STORE_DIR", - - "value": "/data/ipfs" + - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + - "value": "0" - }, - { - - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - - "value": "/ip4/0.0.0.0/tcp/4001" + - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + - "value": "6" - }, - { - - "name": "RUST_LOG", - - "value": "info,ceramic_one=debug,multipart=error" + - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + - "value": "1" - } - ], - "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", @@ -2677,10 +2678,30 @@ mod tests { stub.ceramics[0].stateful_set.patch(expect![[r#" --- original +++ modified - @@ -236,6 +236,10 @@ - "value": "0" + @@ -220,20 +220,32 @@ + { + "env": [ + { + - "name": "RUST_LOG", + - "value": "info,ceramic_one=debug,multipart=error" + + "name": "CERAMIC_ONE_BIND_ADDRESS", + + "value": "0.0.0.0:5001" + + }, + + { + + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + + "value": "1" }, { + - "name": "CERAMIC_ONE_BIND_ADDRESS", + - "value": "0.0.0.0:5001" + + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + + "value": "6" + }, + { + + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + + "value": "0" + + }, + + { + "name": "CERAMIC_ONE_METRICS", + "value": "false" + }, @@ -2688,20 +2709,40 @@ mod tests { "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", "value": "0.0.0.0:9465" }, - @@ -252,11 +256,19 @@ - "value": "/ip4/0.0.0.0/tcp/4001" + { + - "name": "CERAMIC_ONE_SWARM_ADDRESSES", + - "value": "/ip4/0.0.0.0/tcp/4001" + + "name": "CERAMIC_ONE_NETWORK", + + "value": "local" + }, + { + "name": "CERAMIC_ONE_STORE_DIR", + @@ -240,23 +252,23 @@ + "value": "/data/ipfs" }, { + - "name": "CERAMIC_ONE_NETWORK", + - "value": "local" + + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + + "value": "/ip4/0.0.0.0/tcp/4001" + }, + { + - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + - "value": "0" + "name": "ENV_KEY_A", + "value": "ENV_VALUE_A" - + }, - + { + }, + { + - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + - "value": "6" + "name": "ENV_KEY_B", + "value": "ENV_VALUE_B" - + }, - + { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + }, + { + - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + - "value": "1" + + "name": "RUST_LOG", + + "value": "info,ceramic_one=debug,multipart=error" } ], - "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", @@ -3271,7 +3312,7 @@ mod tests { + "value": "dev-unstable" }, { - "name": "CERAMIC_ONE_STORE_DIR", + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", @@ -315,15 +311,15 @@ }, { @@ -3742,23 +3783,175 @@ mod tests { stub.ceramics[0].stateful_set.patch(expect![[r#" --- original +++ modified - @@ -102,6 +102,10 @@ + @@ -46,16 +46,28 @@ + ], + "env": [ { - "name": "CERAMIC_NETWORK_TOPIC", - "value": "/ceramic/local-0" + + "name": "CAS_API_URL", + + "value": "http://cas:8081" + + }, + + { + + "name": "CERAMIC_CORS_ALLOWED_ORIGINS", + + "value": ".*" + + }, + + { + + "name": "CERAMIC_IPFS_HOST", + + "value": "http://localhost:5001" + + }, + + { + + "name": "CERAMIC_LOG_LEVEL", + + "value": "2" + }, + { + "name": "CERAMIC_NETWORK", + "value": "local" + }, + { + - "name": "ETH_RPC_URL", + - "value": "http://ganache:8545" + - }, + - { + - "name": "CAS_API_URL", + - "value": "http://cas:8081" + + "name": "CERAMIC_NETWORK_TOPIC", + + "value": "/ceramic/local-0" + }, + { + "name": "CERAMIC_SQLITE_PATH", + @@ -66,16 +78,8 @@ + "value": "/ceramic-data/statestore" + }, + { + - "name": "CERAMIC_IPFS_HOST", + - "value": "http://localhost:5001" + - }, + - { + - "name": "CERAMIC_CORS_ALLOWED_ORIGINS", + - "value": ".*" + - }, + - { + - "name": "CERAMIC_LOG_LEVEL", + - "value": "2" + + "name": "ETH_RPC_URL", + + "value": "http://ganache:8545" + }, + { + "name": "POSTGRES_DB", + @@ -82,26 +86,26 @@ + "value": "ceramic" + }, + { + - "name": "POSTGRES_USER", + + "name": "POSTGRES_PASSWORD", + "valueFrom": { + "secretKeyRef": { + - "key": "username", + + "key": "password", + "name": "ceramic-postgres-auth" + } + } + }, + { + - "name": "POSTGRES_PASSWORD", + + "name": "POSTGRES_USER", + "valueFrom": { + "secretKeyRef": { + - "key": "password", + + "key": "username", + "name": "ceramic-postgres-auth" + } + } + }, + { + - "name": "CERAMIC_NETWORK_TOPIC", + - "value": "/ceramic/local-0" + "name": "SOME_ENV_VAR", + "value": "SOME_ENV_VALUE" } ], "image": "ceramicnetwork/composedb:latest", - @@ -370,6 +374,10 @@ + @@ -314,16 +318,28 @@ + } + }, { - "name": "CERAMIC_NETWORK_TOPIC", - "value": "/ceramic/local-0" + + "name": "CAS_API_URL", + + "value": "http://cas:8081" + + }, + + { + + "name": "CERAMIC_CORS_ALLOWED_ORIGINS", + + "value": ".*" + + }, + + { + + "name": "CERAMIC_IPFS_HOST", + + "value": "http://localhost:5001" + }, + { + + "name": "CERAMIC_LOG_LEVEL", + + "value": "2" + + }, + + { + "name": "CERAMIC_NETWORK", + "value": "local" + }, + { + - "name": "ETH_RPC_URL", + - "value": "http://ganache:8545" + - }, + - { + - "name": "CAS_API_URL", + - "value": "http://cas:8081" + + "name": "CERAMIC_NETWORK_TOPIC", + + "value": "/ceramic/local-0" + }, + { + "name": "CERAMIC_SQLITE_PATH", + @@ -334,16 +350,8 @@ + "value": "/ceramic-data/statestore" + }, + { + - "name": "CERAMIC_IPFS_HOST", + - "value": "http://localhost:5001" + - }, + - { + - "name": "CERAMIC_CORS_ALLOWED_ORIGINS", + - "value": ".*" + - }, + - { + - "name": "CERAMIC_LOG_LEVEL", + - "value": "2" + + "name": "ETH_RPC_URL", + + "value": "http://ganache:8545" + }, + { + "name": "POSTGRES_DB", + @@ -350,26 +358,26 @@ + "value": "ceramic" + }, + { + - "name": "POSTGRES_USER", + + "name": "POSTGRES_PASSWORD", + "valueFrom": { + "secretKeyRef": { + - "key": "username", + + "key": "password", + "name": "ceramic-postgres-auth" + } + } + }, + { + - "name": "POSTGRES_PASSWORD", + + "name": "POSTGRES_USER", + "valueFrom": { + "secretKeyRef": { + - "key": "password", + + "key": "username", + "name": "ceramic-postgres-auth" + } + } + }, + { + - "name": "CERAMIC_NETWORK_TOPIC", + - "value": "/ceramic/local-0" + "name": "SOME_ENV_VAR", + "value": "SOME_ENV_VALUE" } @@ -4036,40 +4229,40 @@ mod tests { { - "env": [ - { - - "name": "CERAMIC_ONE_BIND_ADDRESS", - - "value": "0.0.0.0:5001" + - "name": "RUST_LOG", + - "value": "info,ceramic_one=debug,multipart=error" - }, - { - - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - - "value": "1" + - "name": "CERAMIC_ONE_BIND_ADDRESS", + - "value": "0.0.0.0:5001" - }, - { - - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - - "value": "6" + - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + - "value": "0.0.0.0:9465" - }, - { - - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - - "value": "0" + - "name": "CERAMIC_ONE_SWARM_ADDRESSES", + - "value": "/ip4/0.0.0.0/tcp/4001" - }, - { - - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - - "value": "0.0.0.0:9465" + - "name": "CERAMIC_ONE_STORE_DIR", + - "value": "/data/ipfs" - }, - { - "name": "CERAMIC_ONE_NETWORK", - "value": "local" - }, - { - - "name": "CERAMIC_ONE_STORE_DIR", - - "value": "/data/ipfs" + - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + - "value": "0" - }, - { - - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - - "value": "/ip4/0.0.0.0/tcp/4001" + - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + - "value": "6" - }, - { - - "name": "RUST_LOG", - - "value": "info,ceramic_one=debug,multipart=error" + - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + - "value": "1" - } - ], - "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", @@ -4356,17 +4549,17 @@ mod tests { "volumeMounts": [ { "mountPath": "/config", - @@ -252,6 +259,10 @@ - "value": "/ip4/0.0.0.0/tcp/4001" - }, + @@ -254,6 +261,10 @@ { - + "name": "CERAMIC_ONE_TOKIO_CONSOLE", - + "value": "true" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" + }, + { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + + "name": "CERAMIC_ONE_TOKIO_CONSOLE", + + "value": "true" } + ], + "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", @@ -274,6 +285,11 @@ "containerPort": 9465, "name": "metrics", @@ -4397,17 +4590,17 @@ mod tests { stub.cas_ipfs_stateful_set.patch(expect![[r#" --- original +++ modified - @@ -69,6 +69,10 @@ - "value": "/ip4/0.0.0.0/tcp/4001" - }, + @@ -71,6 +71,10 @@ { - + "name": "CERAMIC_ONE_TOKIO_CONSOLE", - + "value": "true" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" + }, + { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + + "name": "CERAMIC_ONE_TOKIO_CONSOLE", + + "value": "true" } + ], + "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", @@ -91,6 +95,11 @@ "containerPort": 9465, "name": "metrics", @@ -4443,4 +4636,173 @@ mod tests { .expect("reconciler"); timeout_after_1s(mocksrv).await; } + + #[tokio::test] + async fn cas_api_env_override() { + // Setup network spec and status + let network = Network::test().with_spec(NetworkSpec { + cas: Some(CasSpec { + api: Some(CasApiSpec { + env: Some(BTreeMap::from_iter([ + ("ENV_KEY_A".to_string(), "ENV_VALUE_A".to_string()), + ("ENV_KEY_B".to_string(), "ENV_VALUE_B".to_string()), + // Override one existing var + ("APP_PORT".to_string(), "8080".to_string()), + ])), + ..Default::default() + }), + ..Default::default() + }), + ..Default::default() + }); + let mock_rpc_client = default_ipfs_rpc_mock(); + let mut stub = Stub::default().with_network(network.clone()); + stub.cas_stateful_set.patch(expect![[r#" + --- original + +++ modified + @@ -36,8 +36,28 @@ + { + "env": [ + { + - "name": "DB_NAME", + - "value": "anchor_db" + + "name": "APP_MODE", + + "value": "server" + + }, + + { + + "name": "APP_PORT", + + "value": "8080" + + }, + + { + + "name": "AWS_ACCESS_KEY_ID", + + "value": "." + + }, + + { + + "name": "AWS_ACCOUNT_ID", + + "value": "000000000000" + + }, + + { + + "name": "AWS_REGION", + + "value": "us-east-1" + + }, + + { + + "name": "AWS_SECRET_ACCESS_KEY", + + "value": "." + }, + { + "name": "DB_HOST", + @@ -44,42 +64,38 @@ + "value": "cas-postgres" + }, + { + - "name": "DB_USERNAME", + + "name": "DB_NAME", + + "value": "anchor_db" + + }, + + { + + "name": "DB_PASSWORD", + "valueFrom": { + "secretKeyRef": { + - "key": "username", + + "key": "password", + "name": "postgres-auth" + } + } + }, + { + - "name": "DB_PASSWORD", + + "name": "DB_USERNAME", + "valueFrom": { + "secretKeyRef": { + - "key": "password", + + "key": "username", + "name": "postgres-auth" + } + } + }, + { + - "name": "AWS_ACCOUNT_ID", + - "value": "000000000000" + + "name": "ENV_KEY_A", + + "value": "ENV_VALUE_A" + }, + { + - "name": "AWS_REGION", + - "value": "us-east-1" + - }, + - { + - "name": "AWS_ACCESS_KEY_ID", + - "value": "." + + "name": "ENV_KEY_B", + + "value": "ENV_VALUE_B" + }, + { + - "name": "AWS_SECRET_ACCESS_KEY", + - "value": "." + - }, + - { + - "name": "SQS_QUEUE_URL", + - "value": "http://localstack:4566/000000000000/cas-anchor-dev-" + + "name": "ETH_CONTRACT_ADDRESS", + + "value": "0x231055A0852D67C7107Ad0d0DFeab60278fE6AdC" + }, + { + "name": "ETH_GAS_LIMIT", + @@ -98,20 +114,20 @@ + "value": "0x06dd0990d19001c57eeea6d32e8fdeee40d3945962caf18c18c3930baa5a6ec9" + }, + { + - "name": "ETH_CONTRACT_ADDRESS", + - "value": "0x231055A0852D67C7107Ad0d0DFeab60278fE6AdC" + + "name": "LOG_LEVEL", + + "value": "debug" + }, + { + - "name": "NODE_ENV", + - "value": "dev" + + "name": "MERKLE_CAR_STORAGE_MODE", + + "value": "s3" + }, + { + - "name": "LOG_LEVEL", + - "value": "debug" + + "name": "METRICS_PORT", + + "value": "9464" + }, + { + - "name": "MERKLE_CAR_STORAGE_MODE", + - "value": "s3" + + "name": "NODE_ENV", + + "value": "dev" + }, + { + "name": "S3_BUCKET_NAME", + @@ -122,16 +138,8 @@ + "value": "http://localstack:4566" + }, + { + - "name": "APP_MODE", + - "value": "server" + - }, + - { + - "name": "APP_PORT", + - "value": "8081" + - }, + - { + - "name": "METRICS_PORT", + - "value": "9464" + + "name": "SQS_QUEUE_URL", + + "value": "http://localstack:4566/000000000000/cas-anchor-dev-" + } + ], + "image": "ceramicnetwork/ceramic-anchor-service:latest", + "#]]); + let (testctx, api_handle) = Context::test(mock_rpc_client); + let fakeserver = ApiServerVerifier::new(api_handle); + let mocksrv = stub.run(fakeserver); + reconcile(Arc::new(network), testctx) + .await + .expect("reconciler"); + timeout_after_1s(mocksrv).await; + } } diff --git a/operator/src/network/ipfs.rs b/operator/src/network/ipfs.rs index 1ddb2b80..87a37b3b 100644 --- a/operator/src/network/ipfs.rs +++ b/operator/src/network/ipfs.rs @@ -12,9 +12,13 @@ const IPFS_CONTAINER_NAME: &str = "ipfs"; pub const IPFS_DATA_PV_CLAIM: &str = "ipfs-data"; const IPFS_SERVICE_PORT: i32 = 5001; -use crate::network::{ - ceramic::NetworkConfig, controller::NETWORK_DEV_MODE_RESOURCES, - resource_limits::ResourceLimitsConfig, GoIpfsSpec, IpfsSpec, RustIpfsSpec, NETWORK_LOCAL_ID, +use crate::{ + network::{ + ceramic::NetworkConfig, controller::NETWORK_DEV_MODE_RESOURCES, + resource_limits::ResourceLimitsConfig, GoIpfsSpec, IpfsSpec, RustIpfsSpec, + NETWORK_LOCAL_ID, + }, + utils::override_env_vars, }; use super::debug_mode_security_context; @@ -197,20 +201,9 @@ impl RustIpfsConfig { ..Default::default() }) } - if let Some(extra_env) = &self.env { - extra_env.iter().for_each(|(key, value)| { - if let Some((pos, _)) = env.iter().enumerate().find(|(_, var)| &var.name == key) { - env.swap_remove(pos); - } - env.push(EnvVar { - name: key.to_string(), - value: Some(value.to_string()), - ..Default::default() - }) - }); - } - // Sort env vars so we can have stable tests - env.sort_unstable_by(|a, b| a.name.cmp(&b.name)); + + // Apply env overrides, if specified. + override_env_vars(&mut env, &self.env); // Construct the set of ports let mut ports = vec![ diff --git a/operator/src/network/spec.rs b/operator/src/network/spec.rs index ba27509e..cc6751e1 100644 --- a/operator/src/network/spec.rs +++ b/operator/src/network/spec.rs @@ -233,6 +233,17 @@ pub struct CasSpec { pub postgres_resource_limits: Option, /// Resource limits for the LocalStack pod, applies to both requests and limits. pub localstack_resource_limits: Option, + /// Configuration for the CAS API + pub api: Option, +} + +/// Describes how the CAS API is configured. +#[derive(Default, Serialize, Deserialize, Debug, PartialEq, Clone, JsonSchema)] +#[serde(rename_all = "camelCase")] +pub struct CasApiSpec { + /// Extra env values to pass to the image. + /// CAUTION: Any env vars specified in this set will override any predefined values. + pub env: Option>, } /// Describes if and how to configure datadog telemetry diff --git a/operator/src/network/testdata/ceramic_ss_1 b/operator/src/network/testdata/ceramic_ss_1 index 68e6338c..fec46ed5 100644 --- a/operator/src/network/testdata/ceramic_ss_1 +++ b/operator/src/network/testdata/ceramic_ss_1 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_0 b/operator/src/network/testdata/ceramic_ss_weighted_0 index b80267c4..030d0d0f 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_0 +++ b/operator/src/network/testdata/ceramic_ss_weighted_0 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_1 b/operator/src/network/testdata/ceramic_ss_weighted_1 index c6d18cb2..32d2bd96 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_1 +++ b/operator/src/network/testdata/ceramic_ss_weighted_1 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_2 b/operator/src/network/testdata/ceramic_ss_weighted_2 index 3d538804..0008f30d 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_2 +++ b/operator/src/network/testdata/ceramic_ss_weighted_2 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_3 b/operator/src/network/testdata/ceramic_ss_weighted_3 index c4452c30..fe2f8a69 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_3 +++ b/operator/src/network/testdata/ceramic_ss_weighted_3 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_4 b/operator/src/network/testdata/ceramic_ss_weighted_4 index fa444bcd..96f20b94 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_4 +++ b/operator/src/network/testdata/ceramic_ss_weighted_4 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_5 b/operator/src/network/testdata/ceramic_ss_weighted_5 index c2bcebf8..a75c7aa2 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_5 +++ b/operator/src/network/testdata/ceramic_ss_weighted_5 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_6 b/operator/src/network/testdata/ceramic_ss_weighted_6 index bfa3eadf..8a14905f 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_6 +++ b/operator/src/network/testdata/ceramic_ss_weighted_6 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_7 b/operator/src/network/testdata/ceramic_ss_weighted_7 index 841d075f..ccc0476c 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_7 +++ b/operator/src/network/testdata/ceramic_ss_weighted_7 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_8 b/operator/src/network/testdata/ceramic_ss_weighted_8 index b048a493..637c6b16 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_8 +++ b/operator/src/network/testdata/ceramic_ss_weighted_8 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/ceramic_ss_weighted_9 b/operator/src/network/testdata/ceramic_ss_weighted_9 index 6fce17a8..858a6ec5 100644 --- a/operator/src/network/testdata/ceramic_ss_weighted_9 +++ b/operator/src/network/testdata/ceramic_ss_weighted_9 @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/default_stubs/cas_ipfs_stateful_set b/operator/src/network/testdata/default_stubs/cas_ipfs_stateful_set index 5e33c1ff..fc4f54f1 100644 --- a/operator/src/network/testdata/default_stubs/cas_ipfs_stateful_set +++ b/operator/src/network/testdata/default_stubs/cas_ipfs_stateful_set @@ -37,40 +37,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/network/testdata/default_stubs/ceramic_stateful_set b/operator/src/network/testdata/default_stubs/ceramic_stateful_set index 56ff6825..9e1c9b68 100644 --- a/operator/src/network/testdata/default_stubs/ceramic_stateful_set +++ b/operator/src/network/testdata/default_stubs/ceramic_stateful_set @@ -220,40 +220,40 @@ Request { { "env": [ { - "name": "CERAMIC_ONE_BIND_ADDRESS", - "value": "0.0.0.0:5001" + "name": "RUST_LOG", + "value": "info,ceramic_one=debug,multipart=error" }, { - "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", - "value": "1" + "name": "CERAMIC_ONE_BIND_ADDRESS", + "value": "0.0.0.0:5001" }, { - "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", - "value": "6" + "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", + "value": "0.0.0.0:9465" }, { - "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", - "value": "0" + "name": "CERAMIC_ONE_SWARM_ADDRESSES", + "value": "/ip4/0.0.0.0/tcp/4001" }, { - "name": "CERAMIC_ONE_METRICS_BIND_ADDRESS", - "value": "0.0.0.0:9465" + "name": "CERAMIC_ONE_STORE_DIR", + "value": "/data/ipfs" }, { "name": "CERAMIC_ONE_NETWORK", "value": "local" }, { - "name": "CERAMIC_ONE_STORE_DIR", - "value": "/data/ipfs" + "name": "CERAMIC_ONE_LOCAL_NETWORK_ID", + "value": "0" }, { - "name": "CERAMIC_ONE_SWARM_ADDRESSES", - "value": "/ip4/0.0.0.0/tcp/4001" + "name": "CERAMIC_ONE_KADEMLIA_REPLICATION", + "value": "6" }, { - "name": "RUST_LOG", - "value": "info,ceramic_one=debug,multipart=error" + "name": "CERAMIC_ONE_KADEMLIA_PARALLELISM", + "value": "1" } ], "image": "public.ecr.aws/r5b3e0r5/3box/ceramic-one:latest", diff --git a/operator/src/utils/mod.rs b/operator/src/utils/mod.rs index 1310e3aa..a1749fdd 100644 --- a/operator/src/utils/mod.rs +++ b/operator/src/utils/mod.rs @@ -10,7 +10,7 @@ use k8s_openapi::{ api::{ apps::v1::{StatefulSet, StatefulSetSpec, StatefulSetStatus}, batch::v1::{Job, JobSpec, JobStatus}, - core::v1::{ConfigMap, Service, ServiceAccount, ServiceSpec, ServiceStatus}, + core::v1::{ConfigMap, EnvVar, Service, ServiceAccount, ServiceSpec, ServiceStatus}, rbac::v1::{ClusterRole, ClusterRoleBinding}, }, apimachinery::pkg::apis::meta::v1::OwnerReference, @@ -318,3 +318,21 @@ pub fn generate_random_secret( rng.fill_bytes(&mut secret_bytes); hex::encode(secret_bytes) } + +/// Apply override env vars to an existing env var list +pub fn override_env_vars(env: &mut Vec, overrides: &Option>) { + if let Some(override_env) = &overrides { + override_env.iter().for_each(|(key, value)| { + if let Some((pos, _)) = env.iter().enumerate().find(|(_, var)| &var.name == key) { + env.swap_remove(pos); + } + env.push(EnvVar { + name: key.to_string(), + value: Some(value.to_string()), + ..Default::default() + }) + }); + // Sort env vars so we can have stable tests + env.sort_unstable_by(|a, b| a.name.cmp(&b.name)); + } +}