Skip to content

Commit 6db46c1

Browse files
committed
assume single role in ValidatedHiveCluster
1 parent 55ed469 commit 6db46c1

2 files changed

Lines changed: 88 additions & 98 deletions

File tree

rust/operator-binary/src/controller.rs

Lines changed: 76 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -382,112 +382,108 @@ pub async fn reconcile_hive(
382382

383383
let mut ss_cond_builder = StatefulSetConditionBuilder::default();
384384

385-
for (hive_role, role_group_configs) in &validated.role_groups {
386-
if let Some(role_config) = validated.role_configs.get(hive_role) {
387-
add_pdbs(
388-
&role_config.pdb,
389-
hive,
390-
hive_role,
391-
client,
392-
&mut cluster_resources,
393-
)
394-
.await
395-
.context(FailedToCreatePdbSnafu)?;
396-
}
385+
for (rolegroup_name, validated_rg_config) in &validated.role_groups {
386+
let rolegroup = hive.metastore_rolegroup_ref(rolegroup_name);
397387

398-
for (rolegroup_name, validated_rg_config) in role_group_configs {
399-
let rolegroup = hive.metastore_rolegroup_ref(rolegroup_name);
400-
401-
let rg_metrics_service =
402-
build_rolegroup_metrics_service(hive, &validated.image, &rolegroup)
403-
.context(ServiceConfigurationSnafu)?;
404-
405-
let rg_headless_service =
406-
build_rolegroup_headless_service(hive, &validated.image, &rolegroup)
407-
.context(ServiceConfigurationSnafu)?;
408-
409-
let rg_configmap = build_metastore_rolegroup_config_map(
410-
hive,
411-
&hive_namespace,
412-
&validated.image,
413-
&rolegroup,
414-
&validated_rg_config.product_config_properties,
415-
&dereferenced.metadata_database_connection_details,
416-
dereferenced.s3_connection_spec.as_ref(),
417-
&validated_rg_config.merged_config,
418-
&client.kubernetes_cluster_info,
419-
dereferenced.hive_opa_config.as_ref(),
420-
)?;
421-
let rg_statefulset = build_metastore_rolegroup_statefulset(
422-
hive,
423-
hive_role,
424-
&validated.image,
425-
&rolegroup,
426-
&validated_rg_config.product_config_properties,
427-
&dereferenced.metadata_database_connection_details,
428-
dereferenced.s3_connection_spec.as_ref(),
429-
&validated_rg_config.merged_config,
430-
&rbac_sa.name_any(),
431-
dereferenced.hive_opa_config.as_ref(),
432-
)?;
388+
let rg_metrics_service =
389+
build_rolegroup_metrics_service(hive, &validated.image, &rolegroup)
390+
.context(ServiceConfigurationSnafu)?;
433391

434-
cluster_resources
435-
.add(client, rg_metrics_service)
436-
.await
437-
.context(ApplyRoleGroupServiceSnafu {
438-
rolegroup: rolegroup.clone(),
439-
})?;
392+
let rg_headless_service =
393+
build_rolegroup_headless_service(hive, &validated.image, &rolegroup)
394+
.context(ServiceConfigurationSnafu)?;
395+
396+
let rg_configmap = build_metastore_rolegroup_config_map(
397+
hive,
398+
&hive_namespace,
399+
&validated.image,
400+
&rolegroup,
401+
&validated_rg_config.product_config_properties,
402+
&dereferenced.metadata_database_connection_details,
403+
dereferenced.s3_connection_spec.as_ref(),
404+
&validated_rg_config.merged_config,
405+
&client.kubernetes_cluster_info,
406+
dereferenced.hive_opa_config.as_ref(),
407+
)?;
408+
let rg_statefulset = build_metastore_rolegroup_statefulset(
409+
hive,
410+
&HiveRole::MetaStore,
411+
&validated.image,
412+
&rolegroup,
413+
&validated_rg_config.product_config_properties,
414+
&dereferenced.metadata_database_connection_details,
415+
dereferenced.s3_connection_spec.as_ref(),
416+
&validated_rg_config.merged_config,
417+
&rbac_sa.name_any(),
418+
dereferenced.hive_opa_config.as_ref(),
419+
)?;
420+
421+
cluster_resources
422+
.add(client, rg_metrics_service)
423+
.await
424+
.context(ApplyRoleGroupServiceSnafu {
425+
rolegroup: rolegroup.clone(),
426+
})?;
427+
428+
cluster_resources
429+
.add(client, rg_headless_service)
430+
.await
431+
.context(ApplyRoleGroupServiceSnafu {
432+
rolegroup: rolegroup.clone(),
433+
})?;
440434

435+
cluster_resources
436+
.add(client, rg_configmap)
437+
.await
438+
.context(ApplyRoleGroupConfigSnafu {
439+
rolegroup: rolegroup.clone(),
440+
})?;
441+
442+
// Note: The StatefulSet needs to be applied after all ConfigMaps and Secrets it mounts
443+
// to prevent unnecessary Pod restarts.
444+
// See https://github.com/stackabletech/commons-operator/issues/111 for details.
445+
ss_cond_builder.add(
441446
cluster_resources
442-
.add(client, rg_headless_service)
447+
.add(client, rg_statefulset)
443448
.await
444-
.context(ApplyRoleGroupServiceSnafu {
445-
rolegroup: rolegroup.clone(),
446-
})?;
447-
448-
cluster_resources.add(client, rg_configmap).await.context(
449-
ApplyRoleGroupConfigSnafu {
449+
.context(ApplyRoleGroupStatefulSetSnafu {
450450
rolegroup: rolegroup.clone(),
451-
},
452-
)?;
453-
454-
// Note: The StatefulSet needs to be applied after all ConfigMaps and Secrets it mounts
455-
// to prevent unnecessary Pod restarts.
456-
// See https://github.com/stackabletech/commons-operator/issues/111 for details.
457-
ss_cond_builder.add(
458-
cluster_resources
459-
.add(client, rg_statefulset)
460-
.await
461-
.context(ApplyRoleGroupStatefulSetSnafu {
462-
rolegroup: rolegroup.clone(),
463-
})?,
464-
);
465-
}
451+
})?,
452+
);
466453
}
467454

468455
// std's SipHasher is deprecated, and DefaultHasher is unstable across Rust releases.
469456
// We don't /need/ stability, but it's still nice to avoid spurious changes where possible.
470457
let mut discovery_hash = FnvHasher::with_key(0);
471458

472-
let hive_role = HiveRole::MetaStore;
473-
if let Some(role_config) = validated.role_configs.get(&hive_role) {
459+
if let Some(role_config) = validated.role_config {
460+
add_pdbs(
461+
&role_config.pdb,
462+
hive,
463+
&HiveRole::MetaStore,
464+
client,
465+
&mut cluster_resources,
466+
)
467+
.await
468+
.context(FailedToCreatePdbSnafu)?;
469+
474470
let role_listener: Listener = build_role_listener(
475471
hive,
476472
&validated.image,
477-
&hive_role,
473+
&HiveRole::MetaStore,
478474
&role_config.listener_class,
479475
)
480476
.context(ListenerConfigurationSnafu)?;
481477
let listener = cluster_resources.add(client, role_listener).await.context(
482478
ApplyGroupListenerSnafu {
483-
role: hive_role.to_string(),
479+
role: HiveRole::MetaStore.to_string(),
484480
},
485481
)?;
486482

487483
for discovery_cm in discovery::build_discovery_configmaps(
488484
hive,
489485
hive,
490-
hive_role,
486+
HiveRole::MetaStore,
491487
&validated.image,
492488
None,
493489
listener,

rust/operator-binary/src/controller/validate.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ pub struct ValidatedRoleGroupConfig {
5959
#[derive(Clone, Debug)]
6060
pub struct ValidatedHiveCluster {
6161
pub image: ResolvedProductImage,
62-
pub role_groups: BTreeMap<HiveRole, BTreeMap<String, ValidatedRoleGroupConfig>>,
63-
pub role_configs: BTreeMap<HiveRole, ValidatedRoleConfig>,
62+
pub role_groups: BTreeMap<String, ValidatedRoleGroupConfig>,
63+
pub role_config: Option<ValidatedRoleConfig>,
6464
}
6565

6666
pub fn validate_cluster(
@@ -103,31 +103,27 @@ pub fn validate_cluster(
103103
)
104104
.context(InvalidProductConfigSnafu)?;
105105

106-
let mut role_groups = BTreeMap::new();
107-
let mut role_configs = BTreeMap::new();
108-
109106
let metastore_config = validated_config
110107
.get(&HiveRole::MetaStore.to_string())
111108
.map(Cow::Borrowed)
112109
.unwrap_or_default();
113110

114111
let hive_role = HiveRole::MetaStore;
115112

116-
if let Some(HiveMetastoreRoleConfig {
113+
let role_config = if let Some(HiveMetastoreRoleConfig {
117114
common: GenericRoleConfig {
118115
pod_disruption_budget: pdb,
119116
},
120117
listener_class,
121118
}) = hive.role_config(&hive_role)
122119
{
123-
role_configs.insert(
124-
hive_role.clone(),
125-
ValidatedRoleConfig {
126-
pdb: pdb.clone(),
127-
listener_class: listener_class.clone(),
128-
},
129-
);
130-
}
120+
Some(ValidatedRoleConfig {
121+
pdb: pdb.clone(),
122+
listener_class: listener_class.clone(),
123+
})
124+
} else {
125+
None
126+
};
131127

132128
let mut group_configs = BTreeMap::new();
133129
for (rolegroup_name, rolegroup_config) in metastore_config.iter() {
@@ -146,11 +142,9 @@ pub fn validate_cluster(
146142
);
147143
}
148144

149-
role_groups.insert(hive_role, group_configs);
150-
151145
Ok(ValidatedHiveCluster {
152146
image: resolved_product_image,
153-
role_groups,
154-
role_configs,
147+
role_groups: group_configs,
148+
role_config,
155149
})
156150
}

0 commit comments

Comments
 (0)