diff --git a/rust/crd/src/history.rs b/rust/crd/src/history.rs index 20579b60..2b872c47 100644 --- a/rust/crd/src/history.rs +++ b/rust/crd/src/history.rs @@ -3,7 +3,8 @@ use crate::{affinity::history_affinity, constants::*}; use std::collections::{BTreeMap, HashMap}; use serde::{Deserialize, Serialize}; -use snafu::{ResultExt, Snafu}; +use snafu::{OptionExt, ResultExt, Snafu}; +use stackable_operator::role_utils::RoleGroup; use stackable_operator::{ commons::{ affinity::StackableAffinity, @@ -45,6 +46,8 @@ pub enum Error { }, #[snafu(display("fragment validation failure"))] FragmentValidationFailure { source: ValidationError }, + #[snafu(display("the role group {role_group} is not defined"))] + CannotRetrieveRoleGroup { role_group: String }, } #[derive(Clone, CustomResource, Debug, Deserialize, JsonSchema, Serialize)] @@ -118,6 +121,26 @@ impl CurrentlySupportedListenerClasses { } impl SparkHistoryServer { + /// Returns a reference to the role. Raises an error if the role is not defined. + pub fn role(&self) -> &Role { + &self.spec.nodes + } + + /// Returns a reference to the role group. Raises an error if the role or role group are not defined. + pub fn rolegroup( + &self, + rolegroup_ref: &RoleGroupRef, + ) -> Result, Error> { + self.spec + .nodes + .role_groups + .get(&rolegroup_ref.role_group) + .with_context(|| CannotRetrieveRoleGroupSnafu { + role_group: rolegroup_ref.role_group.to_owned(), + }) + .cloned() + } + pub fn merged_config( &self, rolegroup_ref: &RoleGroupRef, diff --git a/rust/operator-binary/src/history_controller.rs b/rust/operator-binary/src/history_controller.rs index 1913ed49..f7444c41 100644 --- a/rust/operator-binary/src/history_controller.rs +++ b/rust/operator-binary/src/history_controller.rs @@ -30,6 +30,7 @@ use stackable_operator::{ }; use stackable_spark_k8s_crd::{ constants::*, + history, history::{HistoryConfig, SparkHistoryServer, SparkHistoryServerContainer}, s3logdir::S3LogDir, tlscerts, @@ -39,6 +40,7 @@ use std::{collections::BTreeMap, sync::Arc}; use snafu::{OptionExt, ResultExt, Snafu}; use stackable_operator::builder::resources::ResourceRequirementsBuilder; +use stackable_operator::k8s_openapi::DeepMerge; use stackable_operator::logging::controller::ReconcilerError; use strum::{EnumDiscriminants, IntoStaticStr}; @@ -119,6 +121,8 @@ pub enum Error { source: product_logging::Error, cm_name: String, }, + #[snafu(display("cannot retrieve role group"))] + CannotRetrieveRoleGroup { source: history::Error }, } type Result = std::result::Result; @@ -388,6 +392,14 @@ fn build_stateful_set( )); } + let mut pod_template = pb.build_template(); + pod_template.merge_from(shs.role().config.pod_overrides.clone()); + let role_group = shs + .rolegroup(rolegroupref) + .with_context(|_| CannotRetrieveRoleGroupSnafu)?; + + pod_template.merge_from(role_group.config.pod_overrides); + Ok(StatefulSet { metadata: ObjectMetaBuilder::new() .name_and_namespace(shs) @@ -401,7 +413,7 @@ fn build_stateful_set( )) .build(), spec: Some(StatefulSetSpec { - template: pb.build_template(), + template: pod_template, replicas: shs.replicas(rolegroupref), selector: LabelSelector { match_labels: Some(role_group_selector_labels( diff --git a/rust/operator-binary/src/spark_k8s_controller.rs b/rust/operator-binary/src/spark_k8s_controller.rs index 7dc56108..85473c48 100644 --- a/rust/operator-binary/src/spark_k8s_controller.rs +++ b/rust/operator-binary/src/spark_k8s_controller.rs @@ -517,8 +517,6 @@ fn pod_template( let mut pod_template = pb.build_template(); pod_template.merge_from(config.pod_overrides.clone()); - // tracing::info!("pod_template: {:?}", pod_template); - // pb.build().context(PodTemplateConfigMapSnafu) Ok(pod_template) } diff --git a/tests/templates/kuttl/pod_overrides/06-assert.yaml b/tests/templates/kuttl/pod_overrides/06-assert.yaml index 68c0e487..310c3ea5 100644 --- a/tests/templates/kuttl/pod_overrides/06-assert.yaml +++ b/tests/templates/kuttl/pod_overrides/06-assert.yaml @@ -7,5 +7,16 @@ apiVersion: apps/v1 kind: StatefulSet metadata: name: spark-history-node-default +spec: + template: + containers: + - name: spark-history + resources: + limits: + cpu: 1500m + memory: 1Gi + requests: + cpu: 500m + memory: 512Mi status: readyReplicas: 1 diff --git a/tests/templates/kuttl/pod_overrides/06-deploy-history-server.yaml.j2 b/tests/templates/kuttl/pod_overrides/06-deploy-history-server.yaml.j2 index 349f0239..cc3d7170 100644 --- a/tests/templates/kuttl/pod_overrides/06-deploy-history-server.yaml.j2 +++ b/tests/templates/kuttl/pod_overrides/06-deploy-history-server.yaml.j2 @@ -40,3 +40,14 @@ spec: replicas: 1 config: cleaner: true + podOverrides: + spec: + containers: + - name: spark-history + resources: + requests: + cpu: 500m + memory: 512Mi + limits: + cpu: 1500m + memory: 1024Mi \ No newline at end of file