Skip to content

Commit c16535f

Browse files
committed
resource name function rename and role parse test
1 parent 68a19c5 commit c16535f

8 files changed

Lines changed: 23 additions & 13 deletions

File tree

rust/operator-binary/src/controller.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl ValidatedCluster {
228228
}
229229
}
230230

231-
pub fn resource_names(
231+
pub fn role_group_resource_names(
232232
&self,
233233
role: &SupersetRole,
234234
role_group_name: &RoleGroupName,
@@ -242,7 +242,7 @@ impl ValidatedCluster {
242242

243243
/// Type-safe names for the per-cluster RBAC resources: the ServiceAccount shared by all
244244
/// Pods, its (namespaced) RoleBinding, and the operator-deployed ClusterRole it binds.
245-
pub fn rbac_resource_names(&self) -> role_utils::ResourceNames {
245+
pub fn cluster_resource_names(&self) -> role_utils::ResourceNames {
246246
role_utils::ResourceNames {
247247
cluster_name: self.name.clone(),
248248
product_name: product_name(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn build_rolegroup_config_map(
4949
validated
5050
.object_meta(
5151
validated
52-
.resource_names(role, role_group_name)
52+
.role_group_resource_names(role, role_group_name)
5353
.role_group_config_map()
5454
.to_string(),
5555
role,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn build_rolegroup_deployment(
6767
) -> Result<Deployment> {
6868
let merged_config = &rolegroup_config.config;
6969

70-
let resource_names = validated.resource_names(superset_role, role_group_name);
70+
let resource_names = validated.role_group_resource_names(superset_role, role_group_name);
7171
let recommended_object_labels = validated.recommended_labels(superset_role, role_group_name);
7272

7373
// The Celery process command, liveness probe and replica policy are the only differences
@@ -103,7 +103,7 @@ pub fn build_rolegroup_deployment(
103103
.affinity(&merged_config.affinity)
104104
.service_account_name(
105105
validated
106-
.rbac_resource_names()
106+
.cluster_resource_names()
107107
.service_account_name()
108108
.to_string(),
109109
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub(crate) fn build_vector_container(
253253
&Container::Vector.to_container_name(),
254254
&validated.image,
255255
vector_log_config,
256-
&validated.resource_names(superset_role, role_group_name),
256+
&validated.role_group_resource_names(superset_role, role_group_name),
257257
&CONFIG_VOLUME_NAME,
258258
&LOG_VOLUME_NAME,
259259
EnvVarSet::new(),

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
@@ -28,7 +28,7 @@ pub fn build_rolegroup_headless_service(
2828
metadata: validated
2929
.object_meta(
3030
validated
31-
.resource_names(role, role_group_name)
31+
.role_group_resource_names(role, role_group_name)
3232
.headless_service_name()
3333
.to_string(),
3434
role,
@@ -54,7 +54,7 @@ pub fn build_rolegroup_metrics_service(
5454
role: &SupersetRole,
5555
role_group_name: &RoleGroupName,
5656
) -> Service {
57-
let resource_names = validated.resource_names(role, role_group_name);
57+
let resource_names = validated.role_group_resource_names(role, role_group_name);
5858
Service {
5959
metadata: validated
6060
.object_meta(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn build_node_rolegroup_statefulset(
9797
) -> Result<StatefulSet> {
9898
let merged_config = &rolegroup_config.config;
9999

100-
let resource_names = validated.resource_names(superset_role, role_group_name);
100+
let resource_names = validated.role_group_resource_names(superset_role, role_group_name);
101101
let recommended_object_labels = validated.recommended_labels(superset_role, role_group_name);
102102
// Used for PVC templates that cannot be modified once they are deployed (a constant "none"
103103
// version keeps the labels stable across version upgrades).
@@ -119,7 +119,7 @@ pub fn build_node_rolegroup_statefulset(
119119
.affinity(&merged_config.affinity)
120120
.service_account_name(
121121
validated
122-
.rbac_resource_names()
122+
.cluster_resource_names()
123123
.service_account_name()
124124
.to_string(),
125125
);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,18 @@ impl v1alpha1::SupersetCluster {
604604
#[cfg(test)]
605605
mod tests {
606606
use stackable_operator::versioned::test_utils::RoundtripTestData;
607+
use strum::IntoEnumIterator;
607608

608-
use super::v1alpha1;
609+
use super::{SupersetRole, v1alpha1};
610+
611+
/// Locks the invariant behind the `expect` in [`SupersetRole::role_name`]: every
612+
/// `SupersetRole` variant (present and future) must serialise to a valid `RoleName`.
613+
#[test]
614+
fn every_superset_role_serialises_to_a_valid_role_name() {
615+
for role in SupersetRole::iter() {
616+
role.role_name();
617+
}
618+
}
609619

610620
impl RoundtripTestData for v1alpha1::SupersetClusterSpec {
611621
fn roundtrip_test_data() -> Vec<Self> {

0 commit comments

Comments
 (0)