Skip to content

Commit

Permalink
History server pod overrides support and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
razvan committed Jul 4, 2023
1 parent 7c8ea65 commit 006b8dc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
25 changes: 24 additions & 1 deletion rust/crd/src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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<HistoryConfigFragment> {
&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<SparkHistoryServer>,
) -> Result<RoleGroup<HistoryConfigFragment>, 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<SparkHistoryServer>,
Expand Down
14 changes: 13 additions & 1 deletion rust/operator-binary/src/history_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use stackable_operator::{
};
use stackable_spark_k8s_crd::{
constants::*,
history,
history::{HistoryConfig, SparkHistoryServer, SparkHistoryServerContainer},
s3logdir::S3LogDir,
tlscerts,
Expand All @@ -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};

Expand Down Expand Up @@ -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<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions rust/operator-binary/src/spark_k8s_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
11 changes: 11 additions & 0 deletions tests/templates/kuttl/pod_overrides/06-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 006b8dc

Please sign in to comment.