Skip to content

Commit

Permalink
feat: allow overriding cas api envars (#167)
Browse files Browse the repository at this point in the history
* feat: allow overriding cas api envars

* fix: review comments and minor renaming
  • Loading branch information
smrz2001 authored May 1, 2024
1 parent 7e8b165 commit 97fbdb6
Show file tree
Hide file tree
Showing 20 changed files with 746 additions and 338 deletions.
19 changes: 19 additions & 0 deletions keramik/src/advanced_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 19 additions & 1 deletion operator/src/network/cas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<BTreeMap<String, String>>,
}

impl From<CasApiSpec> for CasApiConfig {
fn from(value: CasApiSpec) -> Self {
Self { env: value.env }
}
}

impl CasConfig {
Expand Down Expand Up @@ -89,6 +102,7 @@ impl Default for CasConfig {
memory: Some(Quantity("1Gi".to_owned())),
storage: Quantity("1Gi".to_owned()),
},
api: Default::default(),
}
}
}
Expand Down Expand Up @@ -125,6 +139,7 @@ impl From<CasSpec> for CasConfig {
value.localstack_resource_limits,
default.localstack_resource_limits,
),
api: value.api.map(Into::into).unwrap_or(default.api),
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 3 additions & 16 deletions operator/src/network/ceramic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::{
resource_limits::ResourceLimitsConfig,
CeramicSpec, NetworkSpec, NetworkType,
},
utils::override_env_vars,
};

use super::debug_mode_security_context;
Expand Down Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit 97fbdb6

Please sign in to comment.