Skip to content

Commit 178fdad

Browse files
committed
rename resource names functions
1 parent ed92cb4 commit 178fdad

7 files changed

Lines changed: 22 additions & 13 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ stackable_operator::constant!(pub(crate) PLACEHOLDER_DISCOVERY_ROLE_GROUP: RoleG
2727

2828
// Placeholder role-group name used for the recommended labels of the role-level `Listener`
2929
// (which is not tied to a single role group).
30-
stackable_operator::constant!(pub(crate) PLACEHOLDER_LISTENER_ROLE_GROUP: RoleGroupName = "none");
30+
stackable_operator::constant!(pub(crate) NONE_ROLE_GROUP_NAME: RoleGroupName = "none");
3131

3232
pub mod authentication;
3333
pub mod graceful_shutdown;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub fn build_rolegroup_config_map(
151151
role_group_name: &RoleGroupName,
152152
rg: &DruidRoleGroupConfig,
153153
) -> Result<ConfigMap> {
154-
let resource_names = cluster.resource_names(role, role_group_name);
154+
let resource_names = cluster.role_group_resource_names(role, role_group_name);
155155
let cluster_config = &cluster.cluster_config;
156156
let druid_tls_security = &cluster_config.druid_tls_security;
157157
let druid_auth_config = &cluster_config.druid_auth_config;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use stackable_operator::{
1515

1616
use crate::{
1717
controller::{
18-
build::{PLACEHOLDER_LISTENER_ROLE_GROUP, security::listener_ports},
18+
build::{NONE_ROLE_GROUP_NAME, security::listener_ports},
1919
validate::ValidatedCluster,
2020
},
2121
crd::{
@@ -52,7 +52,7 @@ pub fn build_group_listener(
5252
.object_meta(
5353
listener_group_name.to_string(),
5454
druid_role,
55-
&PLACEHOLDER_LISTENER_ROLE_GROUP,
55+
&NONE_ROLE_GROUP_NAME,
5656
)
5757
.build(),
5858
spec: listener::v1alpha1::ListenerSpec {

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
@@ -22,7 +22,7 @@ pub fn build_rolegroup_headless_service(
2222
metadata: cluster
2323
.object_meta(
2424
cluster
25-
.resource_names(druid_role, role_group_name)
25+
.role_group_resource_names(druid_role, role_group_name)
2626
.headless_service_name()
2727
.to_string(),
2828
druid_role,
@@ -59,7 +59,7 @@ pub fn build_rolegroup_metrics_service(
5959
metadata: cluster
6060
.object_meta(
6161
cluster
62-
.resource_names(druid_role, role_group_name)
62+
.role_group_resource_names(druid_role, role_group_name)
6363
.metrics_service_name()
6464
.to_string(),
6565
druid_role,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn build_rolegroup_statefulset(
115115
rg: &DruidRoleGroupConfig,
116116
) -> Result<StatefulSet> {
117117
let merged_rolegroup_config = &rg.config;
118-
let resource_names = cluster.resource_names(role, role_group_name);
118+
let resource_names = cluster.role_group_resource_names(role, role_group_name);
119119
// Everything below used to be threaded in as separate parameters; it all lives on the
120120
// `ValidatedCluster` now.
121121
let resolved_product_image = &cluster.image;
@@ -319,7 +319,7 @@ pub fn build_rolegroup_statefulset(
319319
.metadata(metadata)
320320
.service_account_name(
321321
cluster
322-
.rbac_resource_names()
322+
.cluster_resource_names()
323323
.service_account_name()
324324
.to_string(),
325325
)

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,15 @@ impl ValidatedCluster {
281281

282282
/// Type-safe names for the per-cluster RBAC resources: the ServiceAccount shared by all
283283
/// Pods, its (namespaced) RoleBinding, and the operator-deployed ClusterRole it binds.
284-
pub fn rbac_resource_names(&self) -> role_utils::ResourceNames {
284+
pub fn cluster_resource_names(&self) -> role_utils::ResourceNames {
285285
role_utils::ResourceNames {
286286
cluster_name: self.name.clone(),
287287
product_name: product_name(),
288288
}
289289
}
290290

291291
/// Type-safe names for the resources of the given role's role group.
292-
pub(crate) fn resource_names(
292+
pub(crate) fn role_group_resource_names(
293293
&self,
294294
role: &DruidRole,
295295
role_group_name: &RoleGroupName,
@@ -614,7 +614,7 @@ mod tests {
614614
use strum::IntoEnumIterator;
615615

616616
use super::{
617-
Error,
617+
Error, ValidatedCluster,
618618
test_support::{MINIMAL_DRUID_YAML, druid_from_yaml},
619619
validate,
620620
};
@@ -718,4 +718,13 @@ mod tests {
718718
"expected a ClusterIdentity error when the cluster has no uid"
719719
);
720720
}
721+
722+
/// Locks the invariant behind the `expect` in [`ValidatedCluster::role_name`]: every
723+
/// `DruidRole` variant (present and future) must serialise to a valid `RoleName`.
724+
#[test]
725+
fn every_druid_role_serialises_to_a_valid_role_name() {
726+
for role in DruidRole::iter() {
727+
ValidatedCluster::role_name(&role);
728+
}
729+
}
721730
}

0 commit comments

Comments
 (0)