Skip to content

Commit c97d2da

Browse files
committed
rename resource names functions, add role parse test
1 parent 0efc549 commit c97d2da

6 files changed

Lines changed: 27 additions & 10 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl ContainerConfig {
237237

238238
// HDFS main container
239239
let main_container_config = Self::from(*role);
240-
let resource_names = cluster.resource_names(role, role_group_name);
240+
let resource_names = cluster.role_group_resource_names(role, role_group_name);
241241
let object_name = resource_names.qualified_role_group_name().to_string();
242242
let merged_config = &rolegroup_config.config;
243243

@@ -285,7 +285,7 @@ impl ContainerConfig {
285285
log_config,
286286
vector_aggregator_config_map_name,
287287
},
288-
&cluster.resource_names(role, role_group_name),
288+
&cluster.role_group_resource_names(role, role_group_name),
289289
&VECTOR_CONFIG_VOLUME_NAME,
290290
&VECTOR_LOG_VOLUME_NAME,
291291
EnvVarSet::new(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub(crate) fn rolegroup_metadata(
192192
) -> ObjectMetaBuilder {
193193
cluster.object_meta(
194194
cluster
195-
.resource_names(role, role_group_name)
195+
.role_group_resource_names(role, role_group_name)
196196
.qualified_role_group_name()
197197
.to_string(),
198198
cluster.recommended_labels(role, role_group_name),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ stackable_operator::constant!(NONE_ROLE_GROUP_NAME: RoleGroupName = "none");
2020
pub fn build_service_account(cluster: &ValidatedCluster) -> ServiceAccount {
2121
rbac::build_service_account(
2222
cluster,
23-
&cluster.rbac_resource_names(),
23+
&cluster.cluster_resource_names(),
2424
rbac_labels(cluster),
2525
)
2626
}
@@ -30,7 +30,7 @@ pub fn build_service_account(cluster: &ValidatedCluster) -> ServiceAccount {
3030
pub fn build_role_binding(cluster: &ValidatedCluster) -> RoleBinding {
3131
rbac::build_role_binding(
3232
cluster,
33-
&cluster.rbac_resource_names(),
33+
&cluster.cluster_resource_names(),
3434
rbac_labels(cluster),
3535
)
3636
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub(crate) fn rolegroup_metrics_service(
106106
metadata: cluster
107107
.object_meta(
108108
cluster
109-
.resource_names(role, role_group_name)
109+
.role_group_resource_names(role, role_group_name)
110110
.metrics_service_name()
111111
.to_string(),
112112
cluster.recommended_labels(role, role_group_name),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn build_rolegroup_statefulset(
7070
.affinity(&merged_config.affinity)
7171
.service_account_name(
7272
validated
73-
.rbac_resource_names()
73+
.cluster_resource_names()
7474
.service_account_name()
7575
.to_string(),
7676
)

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ impl ValidatedCluster {
155155

156156
/// Type-safe names for the per-cluster RBAC resources: the ServiceAccount shared by all
157157
/// Pods, its (namespaced) RoleBinding, and the operator-deployed ClusterRole it binds.
158-
pub fn rbac_resource_names(&self) -> role_utils::ResourceNames {
158+
pub fn cluster_resource_names(&self) -> role_utils::ResourceNames {
159159
role_utils::ResourceNames {
160160
cluster_name: self.name.clone(),
161161
product_name: product_name(),
162162
}
163163
}
164164

165165
/// Type-safe names for the resources of the given role group.
166-
pub(crate) fn resource_names(
166+
pub(crate) fn role_group_resource_names(
167167
&self,
168168
role: &HdfsNodeRole,
169169
role_group_name: &RoleGroupName,
@@ -238,7 +238,7 @@ impl ValidatedCluster {
238238
role_group_name: &RoleGroupName,
239239
) -> ServiceName {
240240
ServiceName::from_str(
241-
self.resource_names(role, role_group_name)
241+
self.role_group_resource_names(role, role_group_name)
242242
.qualified_role_group_name()
243243
.as_ref(),
244244
)
@@ -379,3 +379,20 @@ impl ValidatedClusterConfig {
379379
pub struct ValidatedRoleConfig {
380380
pub pdb: stackable_operator::commons::pdb::PdbConfig,
381381
}
382+
383+
#[cfg(test)]
384+
mod tests {
385+
use strum::IntoEnumIterator;
386+
387+
use super::ValidatedCluster;
388+
use crate::crd::HdfsNodeRole;
389+
390+
/// Locks the invariant behind the `expect` in [`ValidatedCluster::role_name`]: every
391+
/// `HdfsNodeRole` variant (present and future) must serialise to a valid `RoleName`.
392+
#[test]
393+
fn every_hdfs_node_role_serialises_to_a_valid_role_name() {
394+
for role in HdfsNodeRole::iter() {
395+
ValidatedCluster::role_name(&role);
396+
}
397+
}
398+
}

0 commit comments

Comments
 (0)