@@ -63,6 +63,7 @@ use crate::{
6363 } ,
6464 discovery:: { self , build_discovery_configmap} ,
6565 event:: { build_invalid_replica_message, publish_warning_event} ,
66+ labels:: add_stackable_labels,
6667 operations:: {
6768 graceful_shutdown:: { self , add_graceful_shutdown_config} ,
6869 pdb:: add_pdbs,
@@ -222,6 +223,9 @@ pub enum Error {
222223 #[ snafu( display( "failed to build cluster resources label" ) ) ]
223224 BuildClusterResourcesLabel { source : LabelError } ,
224225
226+ #[ snafu( display( "failed to build stackable label" ) ) ]
227+ BuildStackableLabel { source : LabelError } ,
228+
225229 #[ snafu( display( "failed to build role-group volume claim templates from config" ) ) ]
226230 BuildRoleGroupVolumeClaimTemplates { source : container:: Error } ,
227231
@@ -320,9 +324,13 @@ pub async fn reconcile_hdfs(
320324 let ( rbac_sa, rbac_rolebinding) = build_rbac_resources (
321325 hdfs,
322326 APP_NAME ,
323- cluster_resources
324- . get_required_labels ( )
325- . context ( BuildClusterResourcesLabelSnafu ) ?,
327+ add_stackable_labels (
328+ cluster_resources
329+ . get_required_labels ( )
330+ . context ( BuildClusterResourcesLabelSnafu ) ?,
331+ hdfs. metadata . labels . clone ( ) ,
332+ )
333+ . context ( BuildStackableLabelSnafu ) ?,
326334 )
327335 . context ( BuildRbacResourcesSnafu ) ?;
328336
@@ -383,12 +391,6 @@ pub async fn reconcile_hdfs(
383391 }
384392
385393 for ( rolegroup_name, rolegroup_config) in group_config. iter ( ) {
386- let merged_config = role
387- . merged_config ( hdfs, rolegroup_name)
388- . context ( ConfigMergeSnafu ) ?;
389-
390- let env_overrides = rolegroup_config. get ( & PropertyNameKind :: Env ) ;
391-
392394 let rolegroup_ref = hdfs. rolegroup_ref ( role_name, rolegroup_name) ;
393395
394396 let rg_service =
@@ -398,6 +400,26 @@ pub async fn reconcile_hdfs(
398400 rolegroup_metrics_service ( hdfs, & role, & rolegroup_ref, & resolved_product_image)
399401 . context ( BuildServiceSnafu ) ?;
400402
403+ let rg_service_name = rg_service. name_any ( ) ;
404+ let rg_metrics_service_name = rg_metrics_service. name_any ( ) ;
405+
406+ cluster_resources
407+ . add ( client, rg_service)
408+ . await
409+ . with_context ( |_| ApplyRoleGroupServiceSnafu {
410+ name : rg_service_name,
411+ } ) ?;
412+ cluster_resources
413+ . add ( client, rg_metrics_service)
414+ . await
415+ . with_context ( |_| ApplyRoleGroupServiceSnafu {
416+ name : rg_metrics_service_name,
417+ } ) ?;
418+
419+ let merged_config = role
420+ . merged_config ( hdfs, rolegroup_name)
421+ . context ( ConfigMergeSnafu ) ?;
422+
401423 // We need to split the creation and the usage of the "metadata" variable in two statements.
402424 // to avoid the compiler error "E0716 (temporary value dropped while borrowed)".
403425 let mut metadata = ObjectMetaBuilder :: new ( ) ;
@@ -415,7 +437,11 @@ pub async fn reconcile_hdfs(
415437 & rolegroup_ref. role ,
416438 & rolegroup_ref. role_group ,
417439 ) )
418- . context ( ObjectMetaSnafu ) ?;
440+ . context ( ObjectMetaSnafu ) ?
441+ . with_labels (
442+ add_stackable_labels ( Labels :: new ( ) , hdfs. metadata . labels . clone ( ) )
443+ . context ( BuildStackableLabelSnafu ) ?,
444+ ) ;
419445
420446 let rg_configmap = rolegroup_config_map (
421447 hdfs,
@@ -429,6 +455,17 @@ pub async fn reconcile_hdfs(
429455 & hdfs_opa_config,
430456 ) ?;
431457
458+ let rg_configmap_name = rg_configmap. name_any ( ) ;
459+
460+ cluster_resources
461+ . add ( client, rg_configmap. clone ( ) )
462+ . await
463+ . with_context ( |_| ApplyRoleGroupConfigMapSnafu {
464+ name : rg_configmap_name,
465+ } ) ?;
466+
467+ let env_overrides = rolegroup_config. get ( & PropertyNameKind :: Env ) ;
468+
432469 let rg_statefulset = rolegroup_statefulset (
433470 hdfs,
434471 & client. kubernetes_cluster_info ,
@@ -442,29 +479,6 @@ pub async fn reconcile_hdfs(
442479 & rbac_sa,
443480 ) ?;
444481
445- let rg_service_name = rg_service. name_any ( ) ;
446- let rg_metrics_service_name = rg_metrics_service. name_any ( ) ;
447-
448- cluster_resources
449- . add ( client, rg_service)
450- . await
451- . with_context ( |_| ApplyRoleGroupServiceSnafu {
452- name : rg_service_name,
453- } ) ?;
454- cluster_resources
455- . add ( client, rg_metrics_service)
456- . await
457- . with_context ( |_| ApplyRoleGroupServiceSnafu {
458- name : rg_metrics_service_name,
459- } ) ?;
460- let rg_configmap_name = rg_configmap. name_any ( ) ;
461- cluster_resources
462- . add ( client, rg_configmap. clone ( ) )
463- . await
464- . with_context ( |_| ApplyRoleGroupConfigMapSnafu {
465- name : rg_configmap_name,
466- } ) ?;
467-
468482 // Note: The StatefulSet needs to be applied after all ConfigMaps and Secrets it mounts
469483 // to prevent unnecessary Pod restarts.
470484 // See https://github.com/stackabletech/commons-operator/issues/111 for details.
@@ -865,7 +879,11 @@ fn rolegroup_statefulset(
865879 env_overrides,
866880 & hdfs. spec . cluster_config . zookeeper_config_map_name ,
867881 namenode_podrefs,
868- & rolegroup_selector_labels,
882+ & add_stackable_labels (
883+ rolegroup_selector_labels. clone ( ) ,
884+ hdfs. metadata . labels . clone ( ) ,
885+ )
886+ . context ( BuildStackableLabelSnafu ) ?,
869887 )
870888 . context ( FailedToCreateContainerAndVolumeConfigurationSnafu ) ?;
871889
@@ -881,8 +899,15 @@ fn rolegroup_statefulset(
881899 }
882900
883901 // The same comment regarding labels is valid here as it is for the ContainerConfig::add_containers_and_volumes() call above.
884- let pvcs = ContainerConfig :: volume_claim_templates ( merged_config, & rolegroup_selector_labels)
885- . context ( BuildRoleGroupVolumeClaimTemplatesSnafu ) ?;
902+ let pvcs = ContainerConfig :: volume_claim_templates (
903+ merged_config,
904+ & add_stackable_labels (
905+ rolegroup_selector_labels. clone ( ) ,
906+ hdfs. metadata . labels . clone ( ) ,
907+ )
908+ . context ( BuildStackableLabelSnafu ) ?,
909+ )
910+ . context ( BuildRoleGroupVolumeClaimTemplatesSnafu ) ?;
886911
887912 let statefulset_spec = StatefulSetSpec {
888913 pod_management_policy : Some ( "OrderedReady" . to_string ( ) ) ,
0 commit comments