Skip to content

Commit

Permalink
fix: init container resources
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed Jun 30, 2023
1 parent 9484d5d commit 36beb57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
13 changes: 6 additions & 7 deletions rust/crd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,12 @@ impl CurrentlySupportedListenerClasses {
/// This is a shared trait for all role/role-group config structs to avoid duplication
/// when extracting role specific configuration structs like resources or logging.
pub trait MergedConfig {
/// Resources shared by all roles (except datanodes).
/// DataNodes must use `data_node_resources`
fn resources(&self) -> Option<Resources<HdfsStorageConfig, NoRuntimeLimits>> {
fn name_node_resources(&self) -> Option<Resources<HdfsStorageConfig, NoRuntimeLimits>> {
None
}
fn journal_node_resources(&self) -> Option<Resources<HdfsStorageConfig, NoRuntimeLimits>> {
None
}
/// Resources for datanodes.
/// Other roles must use `resources`.
fn data_node_resources(
&self,
) -> Option<Resources<DataNodeStorageConfigInnerType, NoRuntimeLimits>> {
Expand Down Expand Up @@ -786,7 +785,7 @@ pub struct NameNodeConfig {
}

impl MergedConfig for NameNodeConfig {
fn resources(&self) -> Option<Resources<HdfsStorageConfig, NoRuntimeLimits>> {
fn name_node_resources(&self) -> Option<Resources<HdfsStorageConfig, NoRuntimeLimits>> {
Some(self.resources.clone())
}

Expand Down Expand Up @@ -1095,7 +1094,7 @@ pub struct JournalNodeConfig {
}

impl MergedConfig for JournalNodeConfig {
fn resources(&self) -> Option<Resources<HdfsStorageConfig, NoRuntimeLimits>> {
fn journal_node_resources(&self) -> Option<Resources<HdfsStorageConfig, NoRuntimeLimits>> {
Some(self.resources.clone())
}

Expand Down
32 changes: 26 additions & 6 deletions rust/operator/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,23 @@ impl ContainerConfig {
// We use the main app container resources here in contrast to several operators (which use
// hardcoded resources) due to the different code structure.
// Going forward this should be replaced by calculating init container resources in the pod builder.
if let Some(resources) = merged_config.resources() {
create_tls_cert_bundle_init_cb.resources(resources.into());
}
match role {
HdfsRole::NameNode => {
if let Some(resources) = merged_config.name_node_resources() {
create_tls_cert_bundle_init_cb.resources(resources.into());
}
}
HdfsRole::DataNode => {
if let Some(resources) = merged_config.data_node_resources() {
create_tls_cert_bundle_init_cb.resources(resources.into());
}
}
HdfsRole::JournalNode => {
if let Some(resources) = merged_config.journal_node_resources() {
create_tls_cert_bundle_init_cb.resources(resources.into());
}
}
};

pb.add_init_container(create_tls_cert_bundle_init_cb.build());
}
Expand Down Expand Up @@ -325,7 +339,13 @@ impl ContainerConfig {
merged_config: &(dyn MergedConfig + Send + 'static),
) -> Option<Vec<PersistentVolumeClaim>> {
match role {
HdfsRole::NameNode | HdfsRole::JournalNode => merged_config.resources().map(|r| {
HdfsRole::NameNode => merged_config.name_node_resources().map(|r| {
vec![r.storage.data.build_pvc(
ContainerConfig::DATA_VOLUME_MOUNT_NAME,
Some(vec!["ReadWriteOnce"]),
)]
}),
HdfsRole::JournalNode => merged_config.journal_node_resources().map(|r| {
vec![r.storage.data.build_pvc(
ContainerConfig::DATA_VOLUME_MOUNT_NAME,
Some(vec!["ReadWriteOnce"]),
Expand Down Expand Up @@ -746,13 +766,13 @@ impl ContainerConfig {
match self {
// name node and journal node resources
ContainerConfig::Hdfs { role, .. } if role != &HdfsRole::DataNode => {
merged_config.resources().map(|c| c.into())
merged_config.data_node_resources().map(|c| c.into())
}
// data node resources
ContainerConfig::Hdfs { .. } => merged_config.data_node_resources().map(|c| c.into()),
// init containers inherit their respective main (app) container resources
ContainerConfig::FormatNameNodes { .. } | ContainerConfig::FormatZooKeeper { .. } => {
merged_config.resources().map(|c| c.into())
merged_config.name_node_resources().map(|c| c.into())
}
// name node side car zk failover
ContainerConfig::Zkfc { .. } => Some(
Expand Down

0 comments on commit 36beb57

Please sign in to comment.