Skip to content

Commit f1c3e07

Browse files
committed
feat: Support podOverrides
1 parent 23ed311 commit f1c3e07

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Support Airflow `2.6.1` ([#284]).
1111
- Set explicit resources on all containers ([#289])
1212
- Operator errors out when credentialsSecret is missing ([#293]).
13+
- Support podOverrides ([#XXX]).
1314

1415
### Changed
1516

rust/operator-binary/src/airflow_controller.rs

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Ensures that `Pod`s are configured and running for each [`AirflowCluster`]
22
use stackable_operator::builder::resources::ResourceRequirementsBuilder;
3+
use stackable_operator::k8s_openapi::DeepMerge;
34

45
use crate::config::{self, PYTHON_IMPORTS};
56
use crate::controller_commons::{
@@ -615,19 +616,41 @@ fn build_server_rolegroup_statefulset(
615616

616617
let rolegroup = role.role_groups.get(&rolegroup_ref.role_group);
617618

618-
// initialising commands
619619
let commands = airflow_role.get_commands();
620620

621-
// container
622-
let mut cb = ContainerBuilder::new(&Container::Airflow.to_string())
623-
.context(InvalidContainerNameSnafu)?;
624621
let mut pb = PodBuilder::new();
622+
pb.metadata_builder(|m| {
623+
m.with_recommended_labels(build_recommended_labels(
624+
airflow,
625+
AIRFLOW_CONTROLLER_NAME,
626+
&resolved_product_image.app_version_label,
627+
&rolegroup_ref.role,
628+
&rolegroup_ref.role_group,
629+
))
630+
})
631+
.image_pull_secrets_from_product_image(resolved_product_image)
632+
.affinity(&config.affinity)
633+
.service_account_name(sa_name)
634+
.security_context(
635+
PodSecurityContextBuilder::new()
636+
.run_as_user(AIRFLOW_UID)
637+
.run_as_group(0)
638+
.fs_group(1000) // Needed for secret-operator
639+
.build(),
640+
);
641+
642+
let mut airflow_container = ContainerBuilder::new(&Container::Airflow.to_string())
643+
.context(InvalidContainerNameSnafu)?;
625644

626645
if let Some(authentication_class) = authentication_class {
627-
add_authentication_volumes_and_volume_mounts(authentication_class, &mut cb, &mut pb)?;
646+
add_authentication_volumes_and_volume_mounts(
647+
authentication_class,
648+
&mut airflow_container,
649+
&mut pb,
650+
)?;
628651
}
629652

630-
let cb = cb
653+
airflow_container
631654
.image_from_product_image(resolved_product_image)
632655
.resources(config.resources.clone().into())
633656
.command(vec!["/bin/bash".to_string()])
@@ -648,15 +671,15 @@ fn build_server_rolegroup_statefulset(
648671
// mapped environment variables
649672
let env_mapped = build_mapped_envs(airflow, rolegroup_config);
650673

651-
cb.add_env_vars(env_config);
652-
cb.add_env_vars(env_mapped);
653-
cb.add_env_vars(build_static_envs());
674+
airflow_container.add_env_vars(env_config);
675+
airflow_container.add_env_vars(env_mapped);
676+
airflow_container.add_env_vars(build_static_envs());
654677

655678
let volume_mounts = airflow.volume_mounts();
656-
cb.add_volume_mounts(volume_mounts);
657-
cb.add_volume_mount(CONFIG_VOLUME_NAME, CONFIG_PATH);
658-
cb.add_volume_mount(LOG_CONFIG_VOLUME_NAME, LOG_CONFIG_DIR);
659-
cb.add_volume_mount(LOG_VOLUME_NAME, STACKABLE_LOG_DIR);
679+
airflow_container.add_volume_mounts(volume_mounts);
680+
airflow_container.add_volume_mount(CONFIG_VOLUME_NAME, CONFIG_PATH);
681+
airflow_container.add_volume_mount(LOG_CONFIG_VOLUME_NAME, LOG_CONFIG_DIR);
682+
airflow_container.add_volume_mount(LOG_VOLUME_NAME, STACKABLE_LOG_DIR);
660683

661684
if let Some(resolved_port) = airflow_role.get_http_port() {
662685
let probe = Probe {
@@ -668,12 +691,12 @@ fn build_server_rolegroup_statefulset(
668691
period_seconds: Some(5),
669692
..Probe::default()
670693
};
671-
cb.readiness_probe(probe.clone());
672-
cb.liveness_probe(probe);
673-
cb.add_container_port("http", resolved_port.into());
694+
airflow_container.readiness_probe(probe.clone());
695+
airflow_container.liveness_probe(probe);
696+
airflow_container.add_container_port("http", resolved_port.into());
674697
}
675698

676-
let container = cb.build();
699+
pb.add_container(airflow_container.build());
677700

678701
let metrics_container = ContainerBuilder::new("metrics")
679702
.context(InvalidContainerNameSnafu)?
@@ -690,16 +713,14 @@ fn build_server_rolegroup_statefulset(
690713
.build(),
691714
)
692715
.build();
716+
pb.add_container(metrics_container);
693717

694-
let mut volumes = airflow.volumes();
695-
volumes.extend(controller_commons::create_volumes(
718+
pb.add_volumes(airflow.volumes());
719+
pb.add_volumes(controller_commons::create_volumes(
696720
&rolegroup_ref.object_name(),
697721
config.logging.containers.get(&Container::Airflow),
698722
));
699723

700-
pb.add_container(container);
701-
pb.add_container(metrics_container);
702-
703724
if let Some(gitsync) = airflow.git_sync() {
704725
let gitsync_container = ContainerBuilder::new(&format!("{}-{}", GIT_SYNC_NAME, 1))
705726
.context(InvalidContainerNameSnafu)?
@@ -718,7 +739,7 @@ fn build_server_rolegroup_statefulset(
718739
)
719740
.build();
720741

721-
volumes.push(
742+
pb.add_volume(
722743
VolumeBuilder::new(GIT_CONTENT)
723744
.empty_dir(EmptyDirVolumeSource::default())
724745
.build(),
@@ -741,6 +762,12 @@ fn build_server_rolegroup_statefulset(
741762
));
742763
}
743764

765+
let mut pod_template = pb.build_template();
766+
pod_template.merge_from(role.config.pod_overrides.clone());
767+
if let Some(rolegroup) = rolegroup {
768+
pod_template.merge_from(rolegroup.config.pod_overrides.clone());
769+
}
770+
744771
Ok(StatefulSet {
745772
metadata: ObjectMetaBuilder::new()
746773
.name_and_namespace(airflow)
@@ -769,28 +796,7 @@ fn build_server_rolegroup_statefulset(
769796
..LabelSelector::default()
770797
},
771798
service_name: rolegroup_ref.object_name(),
772-
template: pb
773-
.metadata_builder(|m| {
774-
m.with_recommended_labels(build_recommended_labels(
775-
airflow,
776-
AIRFLOW_CONTROLLER_NAME,
777-
&resolved_product_image.app_version_label,
778-
&rolegroup_ref.role,
779-
&rolegroup_ref.role_group,
780-
))
781-
})
782-
.image_pull_secrets_from_product_image(resolved_product_image)
783-
.add_volumes(volumes)
784-
.affinity(&config.affinity)
785-
.service_account_name(sa_name)
786-
.security_context(
787-
PodSecurityContextBuilder::new()
788-
.run_as_user(AIRFLOW_UID)
789-
.run_as_group(0)
790-
.fs_group(1000) // Needed for secret-operator
791-
.build(),
792-
)
793-
.build_template(),
799+
template: pod_template,
794800
..StatefulSetSpec::default()
795801
}),
796802
status: None,

0 commit comments

Comments
 (0)