@@ -9,6 +9,7 @@ use product_config::types::PropertyNameKind;
99use rand:: Rng ;
1010use snafu:: Snafu ;
1111use stackable_operator:: {
12+ commons:: product_image_selection:: ResolvedProductImage ,
1213 crd:: { authentication:: oidc, git_sync} ,
1314 k8s_openapi:: api:: core:: v1:: EnvVar ,
1415 kube:: ResourceExt ,
@@ -85,11 +86,45 @@ pub fn build_airflow_statefulset_envs(
8586 authorization_config : & AirflowAuthorizationResolved ,
8687 git_sync_resources : & git_sync:: v1alpha1:: GitSyncResources ,
8788 rolegroup : & String ,
89+ resolved_product_image : & ResolvedProductImage ,
8890) -> Result < Vec < EnvVar > , Error > {
8991 let mut env: BTreeMap < String , EnvVar > = BTreeMap :: new ( ) ;
9092
9193 env. extend ( static_envs ( git_sync_resources) ) ;
92- env. extend ( execution_server_env_vars ( airflow, rolegroup) ) ;
94+
95+ if resolved_product_image. product_version . starts_with ( "3." ) {
96+ env. extend ( execution_server_env_vars ( airflow, rolegroup) ) ;
97+ env. insert ( AIRFLOW_CORE_AUTH_MANAGER . into ( ) , EnvVar {
98+ name : AIRFLOW_CORE_AUTH_MANAGER . into ( ) ,
99+ value : Some (
100+ "airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager" . to_string ( ) ,
101+ ) ,
102+ ..Default :: default ( )
103+ } ) ;
104+ env. insert ( AIRFLOW_API_AUTH_BACKENDS . into ( ) , EnvVar {
105+ name : AIRFLOW_API_AUTH_BACKENDS . into ( ) ,
106+ value : Some ( "airflow.api.auth.backend.session" . into ( ) ) ,
107+ ..Default :: default ( )
108+ } ) ;
109+ // As of 3.x a JWT key is required.
110+ // See https://airflow.apache.org/docs/apache-airflow/3.0.1/configurations-ref.html#jwt-secret
111+ // This must be random, but must also be consistent across api-services.
112+ // The key will be consistent for all clusters started by this
113+ // operator instance. TODO: Make this cluster specific.
114+ env. insert ( "AIRFLOW__API_AUTH__JWT_SECRET" . into ( ) , EnvVar {
115+ name : "AIRFLOW__API_AUTH__JWT_SECRET" . into ( ) ,
116+ value : Some ( JWT_KEY . clone ( ) ) ,
117+ ..Default :: default ( )
118+ } ) ;
119+ } else {
120+ env. insert ( AIRFLOW_API_AUTH_BACKENDS . into ( ) , EnvVar {
121+ name : AIRFLOW_API_AUTH_BACKENDS . into ( ) ,
122+ value : Some (
123+ "airflow.api.auth.backend.basic_auth, airflow.api.auth.backend.session" . into ( ) ,
124+ ) ,
125+ ..Default :: default ( )
126+ } ) ;
127+ }
93128
94129 // environment variables
95130 let env_vars = rolegroup_config. get ( & PropertyNameKind :: Env ) ;
@@ -306,33 +341,6 @@ fn static_envs(
306341 ..Default :: default ( )
307342 } ) ;
308343
309- env. insert ( AIRFLOW_CORE_AUTH_MANAGER . into ( ) , EnvVar {
310- name : AIRFLOW_CORE_AUTH_MANAGER . into ( ) ,
311- value : Some (
312- "airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager" . to_string ( ) ,
313- ) ,
314- ..Default :: default ( )
315- } ) ;
316-
317- // Basic auth is only relevant to 2.x and can be removed once
318- // that version is no longer supported.
319- env. insert ( AIRFLOW_API_AUTH_BACKENDS . into ( ) , EnvVar {
320- name : AIRFLOW_API_AUTH_BACKENDS . into ( ) ,
321- value : Some ( "airflow.api.auth.backend.basic_auth, airflow.api.auth.backend.session" . into ( ) ) ,
322- ..Default :: default ( )
323- } ) ;
324-
325- // As of 3.x a JWT key is required.
326- // See https://airflow.apache.org/docs/apache-airflow/3.0.1/configurations-ref.html#jwt-secret
327- // This must be random, but must also be consistent across api-services.
328- // The key will be consistent for all clusters started by this
329- // operator instance. TODO: Make this cluster specific.
330- env. insert ( "AIRFLOW__API_AUTH__JWT_SECRET" . into ( ) , EnvVar {
331- name : "AIRFLOW__API_AUTH__JWT_SECRET" . into ( ) ,
332- value : Some ( JWT_KEY . clone ( ) ) ,
333- ..Default :: default ( )
334- } ) ;
335-
336344 env
337345}
338346
@@ -343,6 +351,7 @@ pub fn build_airflow_template_envs(
343351 env_overrides : & HashMap < String , String > ,
344352 config : & ExecutorConfig ,
345353 git_sync_resources : & git_sync:: v1alpha1:: GitSyncResources ,
354+ resolved_product_image : & ResolvedProductImage ,
346355) -> Vec < EnvVar > {
347356 let mut env: BTreeMap < String , EnvVar > = BTreeMap :: new ( ) ;
348357 let secret = airflow. spec . cluster_config . credentials_secret . as_str ( ) ;
@@ -379,14 +388,47 @@ pub fn build_airflow_template_envs(
379388
380389 env. extend ( static_envs ( git_sync_resources) ) ;
381390
382- // It does not appear to be possible for kubernetesExecutors to work with
383- // multiple webserver rolegroups. For the celery case, each executor sets
384- // the execution server from the associated rolegroup, but for kubernetes
385- // workers this is not possible.
386- if let Some ( webserver_role) = airflow. spec . webservers . as_ref ( ) {
387- if let Some ( rolegroup) = webserver_role. role_groups . iter ( ) . next ( ) {
388- env. extend ( execution_server_env_vars ( airflow, rolegroup. 0 ) ) ;
391+ if resolved_product_image. product_version . starts_with ( "3." ) {
392+ // It does not appear to be possible for kubernetesExecutors to work with
393+ // multiple webserver rolegroups. For the celery case, each executor sets
394+ // the execution server from the associated rolegroup, but for kubernetes
395+ // workers this is not possible.
396+ if let Some ( webserver_role) = airflow. spec . webservers . as_ref ( ) {
397+ if let Some ( rolegroup) = webserver_role. role_groups . iter ( ) . next ( ) {
398+ env. extend ( execution_server_env_vars ( airflow, rolegroup. 0 ) ) ;
399+ }
400+ env. insert ( AIRFLOW_CORE_AUTH_MANAGER . into ( ) , EnvVar {
401+ name : AIRFLOW_CORE_AUTH_MANAGER . into ( ) ,
402+ value : Some (
403+ "airflow.providers.fab.auth_manager.fab_auth_manager.FabAuthManager"
404+ . to_string ( ) ,
405+ ) ,
406+ ..Default :: default ( )
407+ } ) ;
408+ env. insert ( AIRFLOW_API_AUTH_BACKENDS . into ( ) , EnvVar {
409+ name : AIRFLOW_API_AUTH_BACKENDS . into ( ) ,
410+ value : Some ( "airflow.api.auth.backend.session" . into ( ) ) ,
411+ ..Default :: default ( )
412+ } ) ;
413+ // As of 3.x a JWT key is required.
414+ // See https://airflow.apache.org/docs/apache-airflow/3.0.1/configurations-ref.html#jwt-secret
415+ // This must be random, but must also be consistent across api-services.
416+ // The key will be consistent for all clusters started by this
417+ // operator instance. TODO: Make this cluster specific.
418+ env. insert ( "AIRFLOW__API_AUTH__JWT_SECRET" . into ( ) , EnvVar {
419+ name : "AIRFLOW__API_AUTH__JWT_SECRET" . into ( ) ,
420+ value : Some ( JWT_KEY . clone ( ) ) ,
421+ ..Default :: default ( )
422+ } ) ;
389423 }
424+ } else {
425+ env. insert ( AIRFLOW_API_AUTH_BACKENDS . into ( ) , EnvVar {
426+ name : AIRFLOW_API_AUTH_BACKENDS . into ( ) ,
427+ value : Some (
428+ "airflow.api.auth.backend.basic_auth, airflow.api.auth.backend.session" . into ( ) ,
429+ ) ,
430+ ..Default :: default ( )
431+ } ) ;
390432 }
391433
392434 // _STACKABLE_POST_HOOK will contain a command to create a shutdown hook that will be
@@ -473,7 +515,7 @@ fn execution_server_env_vars(
473515 let mut env: BTreeMap < String , EnvVar > = BTreeMap :: new ( ) ;
474516
475517 if let Some ( name) = airflow. metadata . name . as_ref ( ) {
476- let webserver = format ! ( "{name}-webserver-{rolegroup}-metrics " , ) ;
518+ let webserver = format ! ( "{name}-webserver-{rolegroup}" , ) ;
477519 tracing:: debug!( "Webserver set [{webserver}]" ) ;
478520
479521 // These settings are new in 3.x and will have no affect with earlier versions.
0 commit comments