Skip to content

Commit e658036

Browse files
committed
rename resource names functions, add role parse test
1 parent 35d29a5 commit e658036

5 files changed

Lines changed: 26 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn build_rolegroup_config_map(
111111
let cm_metadata = cluster
112112
.object_meta(
113113
cluster
114-
.resource_names(role, role_group_name)
114+
.role_group_resource_names(role, role_group_name)
115115
.role_group_config_map()
116116
.to_string(),
117117
role,

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn build_rolegroup_service(
3535
metadata: cluster
3636
.object_meta(
3737
cluster
38-
.resource_names(hbase_role, role_group_name)
38+
.role_group_resource_names(hbase_role, role_group_name)
3939
.headless_service_name()
4040
.to_string(),
4141
hbase_role,
@@ -77,7 +77,7 @@ pub fn build_rolegroup_metrics_service(
7777
metadata: cluster
7878
.object_meta(
7979
cluster
80-
.resource_names(hbase_role, role_group_name)
80+
.role_group_resource_names(hbase_role, role_group_name)
8181
.metrics_service_name()
8282
.to_string(),
8383
hbase_role,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn build_rolegroup_statefulset(
110110
let resolved_product_image = &cluster.image;
111111
let merged_config = &validated_rg_config.config.config;
112112
let logging = &validated_rg_config.config.logging;
113-
let resource_names = cluster.resource_names(hbase_role, role_group_name);
113+
let resource_names = cluster.role_group_resource_names(hbase_role, role_group_name);
114114
let https_enabled = cluster.has_https_enabled();
115115

116116
let ports = hbase_role
@@ -240,7 +240,7 @@ pub fn build_rolegroup_statefulset(
240240
.context(AddVolumeSnafu)?
241241
.service_account_name(
242242
cluster
243-
.rbac_resource_names()
243+
.cluster_resource_names()
244244
.service_account_name()
245245
.to_string(),
246246
)

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ impl ValidatedCluster {
138138

139139
/// Type-safe names for the per-cluster RBAC resources: the ServiceAccount shared by all
140140
/// Pods, its (namespaced) RoleBinding, and the operator-deployed ClusterRole it binds.
141-
pub fn rbac_resource_names(&self) -> role_utils::ResourceNames {
141+
pub fn cluster_resource_names(&self) -> role_utils::ResourceNames {
142142
role_utils::ResourceNames {
143143
cluster_name: self.name.clone(),
144144
product_name: product_name(),
145145
}
146146
}
147147

148148
/// Type-safe names for the resources of a given role group.
149-
pub(crate) fn resource_names(
149+
pub(crate) fn role_group_resource_names(
150150
&self,
151151
hbase_role: &HbaseRole,
152152
role_group_name: &RoleGroupName,
@@ -323,3 +323,20 @@ pub type HbaseRoleGroupConfig = stackable_operator::v2::role_utils::RoleGroupCon
323323
stackable_operator::v2::role_utils::JavaCommonConfig,
324324
v1alpha1::HbaseConfigOverrides,
325325
>;
326+
327+
#[cfg(test)]
328+
mod tests {
329+
use strum::IntoEnumIterator;
330+
331+
use super::ValidatedCluster;
332+
use crate::crd::HbaseRole;
333+
334+
/// Locks the invariant behind the `expect` in [`ValidatedCluster::role_name`]: every
335+
/// `HbaseRole` variant (present and future) must serialise to a valid `RoleName`.
336+
#[test]
337+
fn every_hbase_role_serialises_to_a_valid_role_name() {
338+
for role in HbaseRole::iter() {
339+
ValidatedCluster::role_name(&role);
340+
}
341+
}
342+
}

0 commit comments

Comments
 (0)