diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d7a6282..73000046 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - Generate OLM bundle for Release 23.4.0 ([#350]). - Missing CRD defaults for `status.conditions` field ([#354]). - Set explicit resources on all containers ([#359]). +- Support podOverrides ([#368]). ### Changed @@ -27,6 +28,7 @@ All notable changes to this project will be documented in this file. [#354]: https://github.com/stackabletech/hdfs-operator/pull/354 [#359]: https://github.com/stackabletech/hdfs-operator/pull/359 [#364]: https://github.com/stackabletech/hdfs-operator/pull/364 +[#368]: https://github.com/stackabletech/hdfs-operator/pull/368 ## [23.4.0] - 2023-04-17 diff --git a/rust/crd/src/lib.rs b/rust/crd/src/lib.rs index 8fc0e55f..21d3adec 100644 --- a/rust/crd/src/lib.rs +++ b/rust/crd/src/lib.rs @@ -23,7 +23,10 @@ use stackable_operator::{ fragment::{Fragment, ValidationError}, merge::Merge, }, - k8s_openapi::apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector}, + k8s_openapi::{ + api::core::v1::PodTemplateSpec, + apimachinery::pkg::{api::resource::Quantity, apis::meta::v1::LabelSelector}, + }, kube::{runtime::reflector::ObjectRef, CustomResource, ResourceExt}, labels::role_group_selector_labels, product_config::types::PropertyNameKind, @@ -465,6 +468,44 @@ impl HdfsCluster { .get(role_group) } + pub fn pod_overrides_for_role(&self, role: &HdfsRole) -> Option<&PodTemplateSpec> { + match role { + HdfsRole::NameNode => self + .spec + .name_nodes + .as_ref() + .map(|n| &n.config.pod_overrides), + HdfsRole::DataNode => self + .spec + .data_nodes + .as_ref() + .map(|n| &n.config.pod_overrides), + HdfsRole::JournalNode => self + .spec + .journal_nodes + .as_ref() + .map(|n| &n.config.pod_overrides), + } + } + + pub fn pod_overrides_for_role_group( + &self, + role: &HdfsRole, + role_group: &str, + ) -> Option<&PodTemplateSpec> { + match role { + HdfsRole::NameNode => self + .namenode_rolegroup(role_group) + .map(|r| &r.config.pod_overrides), + HdfsRole::DataNode => self + .datanode_rolegroup(role_group) + .map(|r| &r.config.pod_overrides), + HdfsRole::JournalNode => self + .journalnode_rolegroup(role_group) + .map(|r| &r.config.pod_overrides), + } + } + pub fn rolegroup_ref( &self, role_name: impl Into, diff --git a/rust/operator/src/hdfs_controller.rs b/rust/operator/src/hdfs_controller.rs index ce99aa51..23462bdf 100644 --- a/rust/operator/src/hdfs_controller.rs +++ b/rust/operator/src/hdfs_controller.rs @@ -27,6 +27,7 @@ use stackable_operator::{ core::v1::{ConfigMap, Service, ServicePort, ServiceSpec}, }, apimachinery::pkg::apis::meta::v1::LabelSelector, + DeepMerge, }, kube::{ api::ObjectMeta, @@ -620,6 +621,15 @@ fn rolegroup_statefulset( ) .context(FailedToCreateContainerAndVolumeConfigurationSnafu)?; + let mut pod_template = pb.build_template(); + if let Some(pod_overrides) = hdfs.pod_overrides_for_role(role) { + pod_template.merge_from(pod_overrides.clone()); + } + if let Some(pod_overrides) = hdfs.pod_overrides_for_role_group(role, &rolegroup_ref.role_group) + { + pod_template.merge_from(pod_overrides.clone()); + } + Ok(StatefulSet { metadata: ObjectMetaBuilder::new() .name_and_namespace(hdfs) @@ -649,7 +659,7 @@ fn rolegroup_statefulset( ..LabelSelector::default() }, service_name: object_name, - template: pb.build_template(), + template: pod_template, volume_claim_templates: ContainerConfig::volume_claim_templates(role, merged_config), ..StatefulSetSpec::default()