1
1
//! Ensures that `Pod`s are configured and running for each [`AirflowCluster`]
2
2
use stackable_operator:: builder:: resources:: ResourceRequirementsBuilder ;
3
+ use stackable_operator:: k8s_openapi:: DeepMerge ;
3
4
4
5
use crate :: config:: { self , PYTHON_IMPORTS } ;
5
6
use crate :: controller_commons:: {
@@ -615,19 +616,41 @@ fn build_server_rolegroup_statefulset(
615
616
616
617
let rolegroup = role. role_groups . get ( & rolegroup_ref. role_group ) ;
617
618
618
- // initialising commands
619
619
let commands = airflow_role. get_commands ( ) ;
620
620
621
- // container
622
- let mut cb = ContainerBuilder :: new ( & Container :: Airflow . to_string ( ) )
623
- . context ( InvalidContainerNameSnafu ) ?;
624
621
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 ) ?;
625
644
626
645
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
+ ) ?;
628
651
}
629
652
630
- let cb = cb
653
+ airflow_container
631
654
. image_from_product_image ( resolved_product_image)
632
655
. resources ( config. resources . clone ( ) . into ( ) )
633
656
. command ( vec ! [ "/bin/bash" . to_string( ) ] )
@@ -648,15 +671,15 @@ fn build_server_rolegroup_statefulset(
648
671
// mapped environment variables
649
672
let env_mapped = build_mapped_envs ( airflow, rolegroup_config) ;
650
673
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 ( ) ) ;
654
677
655
678
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 ) ;
660
683
661
684
if let Some ( resolved_port) = airflow_role. get_http_port ( ) {
662
685
let probe = Probe {
@@ -668,12 +691,12 @@ fn build_server_rolegroup_statefulset(
668
691
period_seconds : Some ( 5 ) ,
669
692
..Probe :: default ( )
670
693
} ;
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 ( ) ) ;
674
697
}
675
698
676
- let container = cb . build ( ) ;
699
+ pb . add_container ( airflow_container . build ( ) ) ;
677
700
678
701
let metrics_container = ContainerBuilder :: new ( "metrics" )
679
702
. context ( InvalidContainerNameSnafu ) ?
@@ -690,16 +713,14 @@ fn build_server_rolegroup_statefulset(
690
713
. build ( ) ,
691
714
)
692
715
. build ( ) ;
716
+ pb. add_container ( metrics_container) ;
693
717
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 (
696
720
& rolegroup_ref. object_name ( ) ,
697
721
config. logging . containers . get ( & Container :: Airflow ) ,
698
722
) ) ;
699
723
700
- pb. add_container ( container) ;
701
- pb. add_container ( metrics_container) ;
702
-
703
724
if let Some ( gitsync) = airflow. git_sync ( ) {
704
725
let gitsync_container = ContainerBuilder :: new ( & format ! ( "{}-{}" , GIT_SYNC_NAME , 1 ) )
705
726
. context ( InvalidContainerNameSnafu ) ?
@@ -718,7 +739,7 @@ fn build_server_rolegroup_statefulset(
718
739
)
719
740
. build ( ) ;
720
741
721
- volumes . push (
742
+ pb . add_volume (
722
743
VolumeBuilder :: new ( GIT_CONTENT )
723
744
. empty_dir ( EmptyDirVolumeSource :: default ( ) )
724
745
. build ( ) ,
@@ -741,6 +762,12 @@ fn build_server_rolegroup_statefulset(
741
762
) ) ;
742
763
}
743
764
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
+
744
771
Ok ( StatefulSet {
745
772
metadata : ObjectMetaBuilder :: new ( )
746
773
. name_and_namespace ( airflow)
@@ -769,28 +796,7 @@ fn build_server_rolegroup_statefulset(
769
796
..LabelSelector :: default ( )
770
797
} ,
771
798
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,
794
800
..StatefulSetSpec :: default ( )
795
801
} ) ,
796
802
status : None ,
0 commit comments