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

feat: adds node-affinity spec config #150

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 additions & 4 deletions operator/src/network/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use k8s_openapi::api::{
},
};

use crate::network::{BootstrapSpec, PEERS_CONFIG_MAP_NAME};
use crate::network::{node_affinity::NodeAffinityConfig, BootstrapSpec, PEERS_CONFIG_MAP_NAME};

// BootstrapConfig defines which properties of the JobSpec can be customized.
pub struct BootstrapConfig {
Expand Down Expand Up @@ -51,11 +51,14 @@ impl From<BootstrapSpec> for BootstrapConfig {
}
}

pub fn bootstrap_job_spec(config: BootstrapConfig) -> JobSpec {
pub fn bootstrap_job_spec(
config: BootstrapConfig,
node_affinity_config: &NodeAffinityConfig,
) -> JobSpec {
debug_assert!(config.enabled);
JobSpec {
backoff_limit: Some(4),
template: PodTemplateSpec {
template: node_affinity_config.apply_to_pod_template(PodTemplateSpec {
spec: Some(PodSpec {
containers: vec![Container {
name: "bootstrap".to_owned(),
Expand Down Expand Up @@ -112,7 +115,7 @@ pub fn bootstrap_job_spec(config: BootstrapConfig) -> JobSpec {
..Default::default()
}),
..Default::default()
},
}),
..Default::default()
}
}
64 changes: 38 additions & 26 deletions operator/src/network/cas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::network::{
};
use crate::{
labels::{managed_labels, selector_labels},
network::ipfs::IpfsInfo,
network::{ipfs::IpfsInfo, node_affinity::NodeAffinityConfig},
};

const CAS_IPFS_INFO_SUFFIX: &str = "cas";
Expand Down Expand Up @@ -139,6 +139,7 @@ pub fn cas_stateful_set_spec(
ns: &str,
config: impl Into<CasConfig>,
datadog: &DataDogConfig,
node_affinity_config: &NodeAffinityConfig,
) -> StatefulSetSpec {
let config = config.into();
let pg_env = vec![
Expand Down Expand Up @@ -298,7 +299,7 @@ pub fn cas_stateful_set_spec(
..Default::default()
},
service_name: CAS_SERVICE_NAME.to_owned(),
template: PodTemplateSpec {
template: node_affinity_config.apply_to_pod_template(PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: selector_labels(CAS_APP).map(|mut lbls| {
lbls.append(&mut managed_labels().unwrap());
Expand Down Expand Up @@ -498,7 +499,7 @@ pub fn cas_stateful_set_spec(
}]),
..Default::default()
}),
},
}),
volume_claim_templates: Some(vec![PersistentVolumeClaim {
metadata: ObjectMeta {
name: Some("cas-data".to_owned()),
Expand Down Expand Up @@ -560,21 +561,23 @@ pub fn cas_ipfs_stateful_set_spec(
..Default::default()
},
service_name: CAS_IPFS_SERVICE_NAME.to_owned(),
template: PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: selector_labels(CAS_IPFS_APP),
annotations: Some(BTreeMap::from_iter(vec![(
"prometheus/path".to_owned(),
"/metrics".to_owned(),
)])),
..Default::default()
}),
spec: Some(PodSpec {
containers: vec![config.ipfs.container(ipfs_info, net_config)],
volumes: Some(volumes),
..Default::default()
template: net_config
.node_affinity_config
.apply_to_pod_template(PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: selector_labels(CAS_IPFS_APP),
annotations: Some(BTreeMap::from_iter(vec![(
"prometheus/path".to_owned(),
"/metrics".to_owned(),
)])),
..Default::default()
}),
spec: Some(PodSpec {
containers: vec![config.ipfs.container(ipfs_info, net_config)],
volumes: Some(volumes),
..Default::default()
}),
}),
},
volume_claim_templates: Some(vec![PersistentVolumeClaim {
metadata: ObjectMeta {
name: Some(IPFS_DATA_PV_CLAIM.to_owned()),
Expand Down Expand Up @@ -611,7 +614,10 @@ pub fn cas_ipfs_service_spec() -> ServiceSpec {
..Default::default()
}
}
pub fn ganache_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSetSpec {
pub fn ganache_stateful_set_spec(
config: impl Into<CasConfig>,
node_affinity_config: &NodeAffinityConfig,
) -> StatefulSetSpec {
let config = config.into();
StatefulSetSpec {
replicas: Some(1),
Expand All @@ -620,7 +626,7 @@ pub fn ganache_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSetSpe
..Default::default()
},
service_name: GANACHE_SERVICE_NAME.to_owned(),
template: PodTemplateSpec {
template: node_affinity_config.apply_to_pod_template(PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: selector_labels(GANACHE_APP),
..Default::default()
Expand Down Expand Up @@ -665,7 +671,7 @@ pub fn ganache_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSetSpe
}]),
..Default::default()
}),
},
}),
volume_claim_templates: Some(vec![PersistentVolumeClaim {
metadata: ObjectMeta {
name: Some("ganache-data".to_owned()),
Expand Down Expand Up @@ -701,7 +707,10 @@ pub fn ganache_service_spec() -> ServiceSpec {
..Default::default()
}
}
pub fn postgres_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSetSpec {
pub fn postgres_stateful_set_spec(
config: impl Into<CasConfig>,
node_affinity_config: &NodeAffinityConfig,
) -> StatefulSetSpec {
let config = config.into();
StatefulSetSpec {
replicas: Some(1),
Expand All @@ -710,7 +719,7 @@ pub fn postgres_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSetSp
..Default::default()
},
service_name: CAS_POSTGRES_SERVICE_NAME.to_owned(),
template: PodTemplateSpec {
template: node_affinity_config.apply_to_pod_template(PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: selector_labels(CAS_POSTGRES_APP),
..Default::default()
Expand Down Expand Up @@ -785,7 +794,7 @@ pub fn postgres_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSetSp
}]),
..Default::default()
}),
},
}),
volume_claim_templates: Some(vec![PersistentVolumeClaim {
metadata: ObjectMeta {
name: Some("postgres-data".to_owned()),
Expand Down Expand Up @@ -821,7 +830,10 @@ pub fn postgres_service_spec() -> ServiceSpec {
}
}

pub fn localstack_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSetSpec {
pub fn localstack_stateful_set_spec(
config: impl Into<CasConfig>,
node_affinity_config: &NodeAffinityConfig,
) -> StatefulSetSpec {
let config = config.into();
StatefulSetSpec {
replicas: Some(1),
Expand All @@ -830,7 +842,7 @@ pub fn localstack_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSet
..Default::default()
},
service_name: LOCALSTACK_SERVICE_NAME.to_owned(),
template: PodTemplateSpec {
template: node_affinity_config.apply_to_pod_template(PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: selector_labels(LOCALSTACK_APP),
..Default::default()
Expand Down Expand Up @@ -866,7 +878,7 @@ pub fn localstack_stateful_set_spec(config: impl Into<CasConfig>) -> StatefulSet
}]),
..Default::default()
}),
},
}),
volume_claim_templates: Some(vec![PersistentVolumeClaim {
metadata: ObjectMeta {
name: Some("localstack-data".to_owned()),
Expand Down
Loading
Loading