Skip to content

Commit b264e5c

Browse files
committed
refactor: provide name to ValidatedRoleGroupConfig
1 parent 5475664 commit b264e5c

6 files changed

Lines changed: 37 additions & 52 deletions

File tree

rust/operator-binary/src/controller/build/config_map.rs

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Build per-rolegroup `ConfigMap` for the NiFi cluster.
22
3-
use snafu::{OptionExt, ResultExt, Snafu};
3+
use snafu::{ResultExt, Snafu};
44
use stackable_operator::{
55
builder::{configmap::ConfigMapBuilder, meta::ObjectMetaBuilder},
66
k8s_openapi::api::core::v1::ConfigMap,
@@ -9,18 +9,15 @@ use stackable_operator::{
99
v2::{builder::meta::ownerreference_from_resource, types::operator::RoleGroupName},
1010
};
1111

12-
use crate::{
13-
controller::{
14-
ValidatedCluster,
15-
build::{
16-
properties::{
17-
ConfigFileName, authorizers, bootstrap_conf, login_identity_providers,
18-
nifi_properties, product_logging, security_properties, state_management_xml,
19-
},
20-
proxy_hosts,
12+
use crate::controller::{
13+
ValidatedCluster, ValidatedRoleGroupConfig,
14+
build::{
15+
properties::{
16+
ConfigFileName, authorizers, bootstrap_conf, login_identity_providers, nifi_properties,
17+
product_logging, security_properties, state_management_xml,
2118
},
19+
proxy_hosts,
2220
},
23-
crd::NifiRole,
2421
};
2522

2623
#[derive(Debug, Snafu)]
@@ -54,9 +51,6 @@ pub enum Error {
5451
InvalidNifiAuthenticationConfig {
5552
source: crate::security::authentication::Error,
5653
},
57-
58-
#[snafu(display("the cluster has no rolegroup [{role_group}] in role [{role}]"))]
59-
MissingRoleGroup { role: String, role_group: String },
6054
}
6155

6256
type Result<T, E = Error> = std::result::Result<T, E>;
@@ -67,20 +61,11 @@ type Result<T, E = Error> = std::result::Result<T, E>;
6761
/// All NiFi configuration is sourced from `cluster`.
6862
pub fn build_rolegroup_config_map(
6963
cluster: &ValidatedCluster,
70-
role_group_name: &RoleGroupName,
64+
rg: &ValidatedRoleGroupConfig,
7165
cluster_info: &KubernetesClusterInfo,
7266
) -> Result<ConfigMap> {
7367
tracing::debug!("building rolegroup ConfigMap");
7468

75-
let rg = cluster
76-
.role_group_configs
77-
.get(&NifiRole::Node)
78-
.and_then(|groups| groups.get(role_group_name))
79-
.with_context(|| MissingRoleGroupSnafu {
80-
role: NifiRole::Node.to_string(),
81-
role_group: role_group_name.to_string(),
82-
})?;
83-
8469
let proxy_hosts = proxy_hosts::compute_proxy_hosts(cluster, cluster_info);
8570

8671
let mut cm_builder = ConfigMapBuilder::new();
@@ -91,12 +76,12 @@ pub fn build_rolegroup_config_map(
9176
.name_and_namespace(cluster)
9277
.name(
9378
cluster
94-
.resource_names(role_group_name)
79+
.resource_names(&rg.name)
9580
.role_group_config_map()
9681
.to_string(),
9782
)
9883
.ownerreference(ownerreference_from_resource(cluster, None, Some(true)))
99-
.with_labels(cluster.recommended_labels(role_group_name))
84+
.with_labels(cluster.recommended_labels(&rg.name))
10085
.build(),
10186
)
10287
.add_data(
@@ -108,7 +93,7 @@ pub fn build_rolegroup_config_map(
10893
ConfigFileName::NifiProperties.to_string(),
10994
nifi_properties::build(cluster, rg, &proxy_hosts).with_context(|_| {
11095
BuildNifiPropertiesSnafu {
111-
rolegroup: role_group_name.clone(),
96+
rolegroup: rg.name.clone(),
11297
}
11398
})?,
11499
)
@@ -128,7 +113,7 @@ pub fn build_rolegroup_config_map(
128113
.add_data(
129114
ConfigFileName::SecurityProperties.to_string(),
130115
security_properties::build(rg).with_context(|_| JvmSecurityPropertiesSnafu {
131-
rolegroup: role_group_name.clone(),
116+
rolegroup: rg.name.clone(),
132117
})?,
133118
);
134119

@@ -146,6 +131,6 @@ pub fn build_rolegroup_config_map(
146131
cm_builder
147132
.build()
148133
.with_context(|_| BuildRoleGroupConfigSnafu {
149-
rolegroup: role_group_name.clone(),
134+
rolegroup: rg.name.clone(),
150135
})
151136
}

rust/operator-binary/src/controller/build/properties/security_properties.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ mod tests {
3535
};
3636

3737
fn make_rg(overrides: Option<BTreeMap<String, String>>) -> ValidatedRoleGroupConfig {
38-
use stackable_operator::v2::role_utils::JavaCommonConfig;
38+
use std::str::FromStr as _;
39+
40+
use stackable_operator::v2::{
41+
role_utils::JavaCommonConfig, types::operator::RoleGroupName,
42+
};
3943
ValidatedRoleGroupConfig {
44+
name: RoleGroupName::from_str("default").expect("valid role-group name"),
4045
replicas: 1,
4146
config: NifiConfig::default(),
4247
config_overrides: NifiConfigOverrides {

rust/operator-binary/src/controller/build/resource/statefulset.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ use stackable_operator::{
4343
pod::container::{EnvVarSet, new_container_builder},
4444
},
4545
product_logging::framework::vector_container,
46-
types::{
47-
kubernetes::{ContainerName, VolumeName},
48-
operator::RoleGroupName,
49-
},
46+
types::kubernetes::{ContainerName, VolumeName},
5047
},
5148
};
5249

@@ -67,7 +64,7 @@ use crate::{
6764
},
6865
crd::{
6966
BALANCE_PORT, BALANCE_PORT_NAME, Container, HTTPS_PORT, HTTPS_PORT_NAME, METRICS_PORT,
70-
METRICS_PORT_NAME, NifiConfig, NifiRole, NifiRoleType, PROTOCOL_PORT, PROTOCOL_PORT_NAME,
67+
METRICS_PORT_NAME, NifiRole, NifiRoleType, PROTOCOL_PORT, PROTOCOL_PORT_NAME,
7168
STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR,
7269
authorization::NifiAccessPolicyProvider,
7370
constants::{NIFI_CONFIG_DIRECTORY, NIFI_PYTHON_WORKING_DIRECTORY},
@@ -165,7 +162,6 @@ stackable_operator::constant!(VECTOR_LOG_VOLUME_NAME: VolumeName = "log");
165162
pub(crate) async fn build_node_rolegroup_statefulset(
166163
cluster: &ValidatedCluster,
167164
cluster_info: &KubernetesClusterInfo,
168-
role_group_name: &RoleGroupName,
169165
role: &NifiRoleType,
170166
rg: &ValidatedRoleGroupConfig,
171167
rolling_update_supported: bool,
@@ -182,7 +178,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
182178
let git_sync_resources = &rg.git_sync_resources;
183179

184180
// Type-safe names for this role group's resources (StatefulSet, ConfigMap, headless Service).
185-
let resource_names = cluster.resource_names(role_group_name);
181+
let resource_names = cluster.resource_names(&rg.name);
186182

187183
// The validated, merged `NifiConfig` is the single source of truth; the ConfigMap builder
188184
// sources the same `rg.config`.
@@ -459,7 +455,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
459455

460456
let mut pod_builder = PodBuilder::new();
461457

462-
let recommended_object_labels = cluster.recommended_labels(role_group_name);
458+
let recommended_object_labels = cluster.recommended_labels(&rg.name);
463459

464460
add_graceful_shutdown_config(merged_config, &mut pod_builder).context(GracefulShutdownSnafu)?;
465461

@@ -616,8 +612,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
616612
KEYSTORE_VOLUME_NAME,
617613
[
618614
crate::controller::build::resource::service::metrics_service_name(
619-
cluster,
620-
role_group_name,
615+
cluster, &rg.name,
621616
),
622617
build_reporting_task_service_name(&nifi_cluster_name),
623618
],
@@ -675,7 +670,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
675670
pod_management_policy: Some("Parallel".to_string()),
676671
replicas,
677672
selector: LabelSelector {
678-
match_labels: Some(cluster.role_group_selector(role_group_name).into()),
673+
match_labels: Some(cluster.role_group_selector(&rg.name).into()),
679674
..LabelSelector::default()
680675
},
681676
service_name: Some(resource_names.headless_service_name().to_string()),
@@ -688,11 +683,7 @@ pub(crate) async fn build_node_rolegroup_statefulset(
688683
},
689684
..StatefulSetUpdateStrategy::default()
690685
}),
691-
volume_claim_templates: Some(get_volume_claim_templates(
692-
cluster,
693-
role_group_name,
694-
merged_config,
695-
)?),
686+
volume_claim_templates: Some(get_volume_claim_templates(cluster, rg)?),
696687
..StatefulSetSpec::default()
697688
}),
698689
status: None,
@@ -701,9 +692,9 @@ pub(crate) async fn build_node_rolegroup_statefulset(
701692

702693
fn get_volume_claim_templates(
703694
cluster: &ValidatedCluster,
704-
role_group_name: &RoleGroupName,
705-
merged_config: &NifiConfig,
695+
rg: &ValidatedRoleGroupConfig,
706696
) -> Result<Vec<PersistentVolumeClaim>> {
697+
let merged_config = &rg.config;
707698
let authorization_config = &cluster.cluster_config.authorization;
708699
let mut pvcs = vec![
709700
merged_config.resources.storage.content_repo.build_pvc(
@@ -730,7 +721,7 @@ fn get_volume_claim_templates(
730721

731722
// Used for PVC templates that cannot be modified once they are deployed, so the version label
732723
// is set to the placeholder `none` to keep the labels stable across version upgrades.
733-
let unversioned_recommended_labels = cluster.recommended_labels_unversioned(role_group_name);
724+
let unversioned_recommended_labels = cluster.recommended_labels_unversioned(&rg.name);
734725

735726
// listener endpoints will use persistent volumes
736727
// so that load balancers can hard-code the target addresses and

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ pub(crate) mod validate;
5353
/// [`with_validated_config`](stackable_operator::v2::role_utils::with_validated_config) in the
5454
/// [`validate`] step; downstream builders consume this rather than the raw `NifiCluster`.
5555
pub struct ValidatedRoleGroupConfig {
56+
/// The role-group name (the key under which this config is stored in
57+
/// [`ValidatedCluster::role_group_configs`]). Carried here so builders that consume the config
58+
/// don't also need the name threaded through as a separate parameter.
59+
pub name: RoleGroupName,
5660
/// The desired number of replicas (defaulted to 1 during validation).
5761
///
5862
/// The StatefulSet replica count is sourced from the raw role-group spec in `nifi_controller`

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ pub(crate) fn build_role_group_configs(
259259
.context(BuildGitSyncResourcesSnafu)?;
260260

261261
groups.insert(
262-
role_group_name,
262+
role_group_name.clone(),
263263
ValidatedRoleGroupConfig {
264+
name: role_group_name,
264265
replicas: validated.replicas.unwrap_or(1),
265266
config,
266267
config_overrides,

rust/operator-binary/src/nifi_controller.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub async fn reconcile_nifi(
295295

296296
let rg_configmap = build::config_map::build_rolegroup_config_map(
297297
&validated_cluster,
298-
role_group_name,
298+
rg,
299299
&client.kubernetes_cluster_info,
300300
)
301301
.context(BuildRoleGroupConfigMapSnafu {
@@ -313,7 +313,6 @@ pub async fn reconcile_nifi(
313313
let rg_statefulset = build_node_rolegroup_statefulset(
314314
&validated_cluster,
315315
&client.kubernetes_cluster_info,
316-
role_group_name,
317316
role,
318317
rg,
319318
rolling_upgrade_supported,

0 commit comments

Comments
 (0)