11//! Ensures that `Pod`s are configured and running for each [`v1alpha2::AirflowCluster`]
22use std:: {
33 collections:: { BTreeMap , BTreeSet , HashMap } ,
4- io:: Write ,
54 sync:: Arc ,
65} ;
76
@@ -72,17 +71,14 @@ use stackable_operator::{
7271use strum:: { EnumDiscriminants , IntoStaticStr } ;
7372
7473use crate :: {
75- config:: {
76- self , PYTHON_IMPORTS ,
77- writer:: { self , FlaskAppConfigWriterError } ,
78- } ,
74+ config,
7975 controller_commons:: { self , CONFIG_VOLUME_NAME , LOG_CONFIG_VOLUME_NAME , LOG_VOLUME_NAME } ,
8076 crd:: {
8177 self , AIRFLOW_CONFIG_FILENAME , APP_NAME , AirflowClusterStatus , AirflowConfig ,
82- AirflowConfigOptions , AirflowExecutor , AirflowExecutorCommonConfiguration , AirflowRole ,
83- CONFIG_PATH , Container , ExecutorConfig , HTTP_PORT , HTTP_PORT_NAME , LISTENER_VOLUME_DIR ,
84- LISTENER_VOLUME_NAME , LOG_CONFIG_DIR , METRICS_PORT , METRICS_PORT_NAME , OPERATOR_NAME ,
85- STACKABLE_LOG_DIR , TEMPLATE_LOCATION , TEMPLATE_NAME , TEMPLATE_VOLUME_NAME ,
78+ AirflowExecutor , AirflowExecutorCommonConfiguration , AirflowRole , CONFIG_PATH , Container ,
79+ ExecutorConfig , HTTP_PORT , HTTP_PORT_NAME , LISTENER_VOLUME_DIR , LISTENER_VOLUME_NAME ,
80+ LOG_CONFIG_DIR , METRICS_PORT , METRICS_PORT_NAME , OPERATOR_NAME , STACKABLE_LOG_DIR ,
81+ TEMPLATE_LOCATION , TEMPLATE_NAME , TEMPLATE_VOLUME_NAME ,
8682 authentication:: {
8783 AirflowAuthenticationClassResolved , AirflowClientAuthenticationDetailsResolved ,
8884 } ,
@@ -112,9 +108,6 @@ pub const CONTAINER_IMAGE_BASE_NAME: &str = "airflow";
112108pub const AIRFLOW_FULL_CONTROLLER_NAME : & str =
113109 concatcp ! ( AIRFLOW_CONTROLLER_NAME , '.' , OPERATOR_NAME ) ;
114110
115- const CONFIG_OVERRIDE_FILE_HEADER_KEY : & str = "FILE_HEADER" ;
116- const CONFIG_OVERRIDE_FILE_FOOTER_KEY : & str = "FILE_FOOTER" ;
117-
118111pub struct Ctx {
119112 pub client : stackable_operator:: client:: Client ,
120113 pub operator_environment : OperatorEnvironmentOptions ,
@@ -164,9 +157,9 @@ pub enum Error {
164157 source : stackable_operator:: commons:: rbac:: Error ,
165158 } ,
166159
167- #[ snafu( display( "failed to build config file for {rolegroup}" ) ) ]
168- BuildRoleGroupConfigFile {
169- source : FlaskAppConfigWriterError ,
160+ #[ snafu( display( "failed to build webserver config for {rolegroup}" ) ) ]
161+ BuildWebserverConfig {
162+ source : config :: webserver_config :: Error ,
170163 rolegroup : RoleGroupRef < v1alpha2:: AirflowCluster > ,
171164 } ,
172165
@@ -257,14 +250,6 @@ pub enum Error {
257250 source : stackable_operator:: builder:: meta:: Error ,
258251 } ,
259252
260- #[ snafu( display( "failed to construct config" ) ) ]
261- ConstructConfig { source : config:: Error } ,
262-
263- #[ snafu( display(
264- "failed to write to String (Vec<u8> to be precise) containing Airflow config"
265- ) ) ]
266- WriteToConfigFileString { source : std:: io:: Error } ,
267-
268253 #[ snafu( display( "failed to configure logging" ) ) ]
269254 ConfigureLogging { source : LoggingError } ,
270255
@@ -728,58 +713,15 @@ fn build_rolegroup_config_map(
728713 logging : & Logging < Container > ,
729714 container : & Container ,
730715) -> Result < ConfigMap , Error > {
731- let mut config: BTreeMap < String , String > = BTreeMap :: new ( ) ;
732-
733- // this will call default values from AirflowClientAuthenticationDetails
734- config:: add_airflow_config (
735- & mut config,
716+ let config_file = config:: webserver_config:: build (
736717 authentication_config,
737718 authorization_config,
738719 & resolved_product_image. product_version ,
720+ config_file_overrides,
739721 )
740- . context ( ConstructConfigSnafu ) ?;
741-
742- tracing:: debug!(
743- "Default config for {}: {:?}" ,
744- rolegroup. object_name( ) ,
745- config
746- ) ;
747-
748- let mut file_config = config_file_overrides. clone ( ) ;
749-
750- tracing:: debug!(
751- "Config overrides for {}: {:?}" ,
752- rolegroup. object_name( ) ,
753- file_config
754- ) ;
755-
756- // now add any overrides, replacing any defaults
757- config. append ( & mut file_config) ;
758-
759- tracing:: debug!(
760- "Merged config for {}: {:?}" ,
761- rolegroup. object_name( ) ,
762- config
763- ) ;
764-
765- let mut config_file = Vec :: new ( ) ;
766-
767- // By removing the keys from `config_properties`, we avoid pasting the Python code into a Python variable as well
768- // (which would be bad)
769- if let Some ( header) = config. remove ( CONFIG_OVERRIDE_FILE_HEADER_KEY ) {
770- writeln ! ( config_file, "{}" , header) . context ( WriteToConfigFileStringSnafu ) ?;
771- }
772-
773- let temp_file_footer: Option < String > = config. remove ( CONFIG_OVERRIDE_FILE_FOOTER_KEY ) ;
774-
775- writer:: write :: < AirflowConfigOptions , _ , _ > ( & mut config_file, config. iter ( ) , PYTHON_IMPORTS )
776- . with_context ( |_| BuildRoleGroupConfigFileSnafu {
777- rolegroup : rolegroup. clone ( ) ,
778- } ) ?;
779-
780- if let Some ( footer) = temp_file_footer {
781- writeln ! ( config_file, "{}" , footer) . context ( WriteToConfigFileStringSnafu ) ?;
782- }
722+ . with_context ( |_| BuildWebserverConfigSnafu {
723+ rolegroup : rolegroup. clone ( ) ,
724+ } ) ?;
783725
784726 let mut cm_builder = ConfigMapBuilder :: new ( ) ;
785727
@@ -800,10 +742,7 @@ fn build_rolegroup_config_map(
800742 . context ( ObjectMetaSnafu ) ?
801743 . build ( ) ,
802744 )
803- . add_data (
804- AIRFLOW_CONFIG_FILENAME ,
805- String :: from_utf8 ( config_file) . unwrap ( ) ,
806- ) ;
745+ . add_data ( AIRFLOW_CONFIG_FILENAME , config_file) ;
807746
808747 extend_config_map_with_log_config (
809748 rolegroup,
0 commit comments