Skip to content

Commit

Permalink
feat: support configuring persistent storage for containers (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
dav1do authored May 22, 2024
1 parent fa4e31b commit cf9be35
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 112 deletions.
39 changes: 39 additions & 0 deletions keramik/src/advanced_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,45 @@ and adding the following environment variables to the `spec/template/spec/contai

# Image Resources

## Storage

Nearly all containers (monitoring outstanding), allow configuring the peristent storage size and class. The storage class must be created out of band, but can be included. The storage configuration has two keys (`size` and `class`) and can be used like so:

```yaml
apiVersion: "keramik.3box.io/v1alpha1"
kind: Network
metadata:
name: small
spec:
replicas: 2
bootstrap:
image: keramik/runner:dev
imagePullPolicy: IfNotPresent
cas:
casStorage:
size: "3Gi"
class: "fastDisk" # typically not set
ipfs:
go:
storage:
size: "1Gi"
ganacheStorage:
size: "1Gi"
postgresStorage:
size: "3Gi"
localstackStorage:
size: "5Gi"
ceramic:
- ipfs:
rust:
storage:
size: "3Gi"
```


## Requests / Limits

During local benchmarking, you may not have enough resources to run the cluster. A simple "fix" is to use the `devMode` flag on the network and simulation specs. This will override the resource requests and limits values to be none, which means it doesn't need available resources to deploy, and can consume as much as it desires. This would be problematic in production and should only be used for testing purposes.

```yaml
Expand Down
99 changes: 41 additions & 58 deletions operator/src/network/cas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use k8s_openapi::{
apps::v1::StatefulSetSpec,
core::v1::{
Container, ContainerPort, EnvVar, EnvVarSource, PersistentVolumeClaim,
PersistentVolumeClaimSpec, PersistentVolumeClaimVolumeSource, PodSecurityContext,
PodSpec, PodTemplateSpec, ResourceRequirements, SecretKeySelector, ServicePort,
ServiceSpec, Volume, VolumeMount,
PersistentVolumeClaimVolumeSource, PodSecurityContext, PodSpec, PodTemplateSpec,
ResourceRequirements, SecretKeySelector, ServicePort, ServiceSpec, Volume, VolumeMount,
},
},
apimachinery::pkg::{
Expand All @@ -30,6 +29,7 @@ use crate::{
ipfs::{IpfsConfig, IpfsInfo, IPFS_DATA_PV_CLAIM},
node_affinity::NodeAffinityConfig,
resource_limits::ResourceLimitsConfig,
storage::PersistentStorageConfig,
CasApiSpec, CasSpec,
},
utils::override_and_sort_env_vars,
Expand All @@ -42,9 +42,13 @@ pub struct CasConfig {
pub image_pull_policy: String,
pub ipfs: IpfsConfig,
pub cas_resource_limits: ResourceLimitsConfig,
pub cas_storage: PersistentStorageConfig,
pub ganache_resource_limits: ResourceLimitsConfig,
pub ganache_storage: PersistentStorageConfig,
pub postgres_resource_limits: ResourceLimitsConfig,
pub postgres_storage: PersistentStorageConfig,
pub localstack_resource_limits: ResourceLimitsConfig,
pub localstack_storage: PersistentStorageConfig,
pub api: CasApiConfig,
}

Expand Down Expand Up @@ -86,22 +90,38 @@ impl Default for CasConfig {
memory: Some(Quantity("1Gi".to_owned())),
storage: Quantity("1Gi".to_owned()),
},
cas_storage: PersistentStorageConfig {
size: Quantity("10Gi".to_owned()),
class: None,
},
ipfs: Default::default(),
ganache_resource_limits: ResourceLimitsConfig {
cpu: Some(Quantity("250m".to_owned())),
memory: Some(Quantity("1Gi".to_owned())),
storage: Quantity("1Gi".to_owned()),
},
ganache_storage: PersistentStorageConfig {
size: Quantity("10Gi".to_owned()),
class: None,
},
postgres_resource_limits: ResourceLimitsConfig {
cpu: Some(Quantity("250m".to_owned())),
memory: Some(Quantity("512Mi".to_owned())),
storage: Quantity("1Gi".to_owned()),
},
postgres_storage: PersistentStorageConfig {
size: Quantity("10Gi".to_owned()),
class: None,
},
localstack_resource_limits: ResourceLimitsConfig {
cpu: Some(Quantity("250m".to_owned())),
memory: Some(Quantity("1Gi".to_owned())),
storage: Quantity("1Gi".to_owned()),
},
localstack_storage: PersistentStorageConfig {
size: Quantity("10Gi".to_owned()),
class: None,
},
api: Default::default(),
}
}
Expand All @@ -126,19 +146,32 @@ impl From<CasSpec> for CasConfig {
value.cas_resource_limits,
default.cas_resource_limits,
),
cas_storage: PersistentStorageConfig::from_spec(value.cas_storage, default.cas_storage),
ipfs: value.ipfs.map(Into::into).unwrap_or(default.ipfs),
ganache_resource_limits: ResourceLimitsConfig::from_spec(
value.ganache_resource_limits,
default.ganache_resource_limits,
),
ganache_storage: PersistentStorageConfig::from_spec(
value.ganache_storage,
default.ganache_storage,
),
postgres_resource_limits: ResourceLimitsConfig::from_spec(
value.postgres_resource_limits,
default.postgres_resource_limits,
),
postgres_storage: PersistentStorageConfig::from_spec(
value.postgres_storage,
default.postgres_storage,
),
localstack_resource_limits: ResourceLimitsConfig::from_spec(
value.localstack_resource_limits,
default.localstack_resource_limits,
),
localstack_storage: PersistentStorageConfig::from_spec(
value.localstack_storage,
default.localstack_storage,
),
api: value.api.map(Into::into).unwrap_or(default.api),
}
}
Expand Down Expand Up @@ -504,17 +537,7 @@ pub fn cas_stateful_set_spec(
name: Some("cas-data".to_owned()),
..Default::default()
},
spec: Some(PersistentVolumeClaimSpec {
access_modes: Some(vec!["ReadWriteOnce".to_owned()]),
resources: Some(ResourceRequirements {
requests: Some(BTreeMap::from_iter(vec![(
"storage".to_owned(),
Quantity("10Gi".to_owned()),
)])),
..Default::default()
}),
..Default::default()
}),
spec: Some(config.cas_storage.clone().into()),
..Default::default()
}]),
..Default::default()
Expand Down Expand Up @@ -582,17 +605,7 @@ pub fn cas_ipfs_stateful_set_spec(
name: Some(IPFS_DATA_PV_CLAIM.to_owned()),
..Default::default()
},
spec: Some(PersistentVolumeClaimSpec {
access_modes: Some(vec!["ReadWriteOnce".to_owned()]),
resources: Some(ResourceRequirements {
requests: Some(BTreeMap::from_iter(vec![(
"storage".to_owned(),
Quantity("10Gi".to_owned()),
)])),
..Default::default()
}),
..Default::default()
}),
spec: Some(config.ipfs.storage_config().clone().into()),
..Default::default()
}]),
..Default::default()
Expand Down Expand Up @@ -676,17 +689,7 @@ pub fn ganache_stateful_set_spec(
name: Some("ganache-data".to_owned()),
..Default::default()
},
spec: Some(PersistentVolumeClaimSpec {
access_modes: Some(vec!["ReadWriteOnce".to_owned()]),
resources: Some(ResourceRequirements {
requests: Some(BTreeMap::from_iter(vec![(
"storage".to_owned(),
Quantity("10Gi".to_owned()),
)])),
..Default::default()
}),
..Default::default()
}),
spec: Some(config.ganache_storage.clone().into()),
..Default::default()
}]),
..Default::default()
Expand Down Expand Up @@ -799,17 +802,7 @@ pub fn postgres_stateful_set_spec(
name: Some("postgres-data".to_owned()),
..Default::default()
},
spec: Some(PersistentVolumeClaimSpec {
access_modes: Some(vec!["ReadWriteOnce".to_owned()]),
resources: Some(ResourceRequirements {
requests: Some(BTreeMap::from_iter(vec![(
"storage".to_owned(),
Quantity("10Gi".to_owned()),
)])),
..Default::default()
}),
..Default::default()
}),
spec: Some(config.postgres_storage.clone().into()),
..Default::default()
}]),
..Default::default()
Expand Down Expand Up @@ -883,17 +876,7 @@ pub fn localstack_stateful_set_spec(
name: Some("localstack-data".to_owned()),
..Default::default()
},
spec: Some(PersistentVolumeClaimSpec {
access_modes: Some(vec!["ReadWriteOnce".to_owned()]),
resources: Some(ResourceRequirements {
requests: Some(BTreeMap::from_iter(vec![(
"storage".to_owned(),
Quantity("10Gi".to_owned()),
)])),
..Default::default()
}),
..Default::default()
}),
spec: Some(config.localstack_storage.clone().into()),
..Default::default()
}]),
..Default::default()
Expand Down
61 changes: 22 additions & 39 deletions operator/src/network/ceramic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use k8s_openapi::{
apps::v1::{RollingUpdateStatefulSetStrategy, StatefulSetSpec, StatefulSetUpdateStrategy},
core::v1::{
ConfigMapVolumeSource, Container, ContainerPort, EmptyDirVolumeSource, EnvVar,
EnvVarSource, HTTPGetAction, PersistentVolumeClaim, PersistentVolumeClaimSpec,
PersistentVolumeClaimVolumeSource, PodSecurityContext, PodSpec, PodTemplateSpec, Probe,
ResourceRequirements, SecretKeySelector, SecurityContext, ServicePort, ServiceSpec,
Volume, VolumeMount,
EnvVarSource, HTTPGetAction, PersistentVolumeClaim, PersistentVolumeClaimVolumeSource,
PodSecurityContext, PodSpec, PodTemplateSpec, Probe, ResourceRequirements,
SecretKeySelector, SecurityContext, ServicePort, ServiceSpec, Volume, VolumeMount,
},
},
apimachinery::pkg::{
Expand All @@ -34,7 +33,7 @@ use crate::{
utils::override_and_sort_env_vars,
};

use super::debug_mode_security_context;
use super::{debug_mode_security_context, storage::PersistentStorageConfig};

pub fn config_maps(
info: &CeramicInfo,
Expand Down Expand Up @@ -143,7 +142,9 @@ pub struct CeramicConfig {
pub image_pull_policy: String,
pub ipfs: IpfsConfig,
pub resource_limits: ResourceLimitsConfig,
pub storage: PersistentStorageConfig,
pub postgres_resource_limits: ResourceLimitsConfig,
pub postgres_storage: PersistentStorageConfig,
pub env: Option<BTreeMap<String, String>>,
}

Expand Down Expand Up @@ -268,11 +269,19 @@ impl Default for CeramicConfig {
memory: Some(Quantity("1Gi".to_owned())),
storage: Quantity("1Gi".to_owned()),
},
storage: PersistentStorageConfig {
size: Quantity("10Gi".to_owned()),
class: None,
},
postgres_resource_limits: ResourceLimitsConfig {
cpu: Some(Quantity("250m".to_owned())),
memory: Some(Quantity("1Gi".to_owned())),
storage: Quantity("1Gi".to_owned()),
},
postgres_storage: PersistentStorageConfig {
size: Quantity("10Gi".to_owned()),
class: None,
},
env: None,
}
}
Expand Down Expand Up @@ -308,10 +317,15 @@ impl From<CeramicSpec> for CeramicConfig {
value.resource_limits,
default.resource_limits,
),
storage: PersistentStorageConfig::from_spec(value.storage, default.storage),
postgres_resource_limits: ResourceLimitsConfig::from_spec(
value.postgres_resource_limits,
default.postgres_resource_limits,
),
postgres_storage: PersistentStorageConfig::from_spec(
value.postgres_storage,
default.postgres_storage,
),
env: value.env,
}
}
Expand Down Expand Up @@ -700,54 +714,23 @@ pub fn stateful_set_spec(ns: &str, bundle: &CeramicBundle<'_>) -> StatefulSetSpe
name: Some("ceramic-data".to_owned()),
..Default::default()
},
spec: Some(PersistentVolumeClaimSpec {
access_modes: Some(vec!["ReadWriteOnce".to_owned()]),
resources: Some(ResourceRequirements {
requests: Some(BTreeMap::from_iter(vec![(
"storage".to_owned(),
Quantity("10Gi".to_owned()),
)])),
..Default::default()
}),
..Default::default()
}),
spec: Some(bundle.config.storage.clone().into()),
..Default::default()
},
PersistentVolumeClaim {
metadata: ObjectMeta {
name: Some(IPFS_DATA_PV_CLAIM.to_owned()),
..Default::default()
},
spec: Some(PersistentVolumeClaimSpec {
access_modes: Some(vec!["ReadWriteOnce".to_owned()]),
resources: Some(ResourceRequirements {
requests: Some(BTreeMap::from_iter(vec![(
"storage".to_owned(),
Quantity("10Gi".to_owned()),
)])),
..Default::default()
}),
storage_class_name: bundle.config.ipfs.storage_class_name(),
..Default::default()
}),
spec: Some(bundle.config.ipfs.storage_config().clone().into()),
..Default::default()
},
PersistentVolumeClaim {
metadata: ObjectMeta {
name: Some("postgres-data".to_owned()),
..Default::default()
},
spec: Some(PersistentVolumeClaimSpec {
access_modes: Some(vec!["ReadWriteOnce".to_owned()]),
resources: Some(ResourceRequirements {
requests: Some(BTreeMap::from_iter(vec![(
"storage".to_owned(),
Quantity("10Gi".to_owned()),
)])),
..Default::default()
}),
..Default::default()
}),
spec: Some(bundle.config.postgres_storage.clone().into()),
..Default::default()
},
]),
Expand Down
Loading

0 comments on commit cf9be35

Please sign in to comment.