Skip to content

Commit d04b987

Browse files
committed
Changed role_binding_name and service_account_name to not be public anymore.
Operators should not call these with potentially wrong parameters, but instead use `build_rbac_resources` to retrieve the objects and read the name from there.
1 parent 154ce7e commit d04b987

File tree

1 file changed

+13
-7
lines changed
  • crates/stackable-operator/src/commons

1 file changed

+13
-7
lines changed

crates/stackable-operator/src/commons/rbac.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ pub enum Error {
2828
}
2929

3030
/// Build RBAC objects for the product workloads.
31-
/// The `rbac_prefix` is meant to be the product name, for example: zookeeper, airflow, etc.
32-
/// and it is a assumed that a ClusterRole named `{rbac_prefix}-clusterrole` exists.
33-
/// 'rbac_prefix' is not used to build the names of the serviceAccount and roleBinding objects,
31+
/// The `product_name` is meant to be the product name, for example: zookeeper, airflow, etc.
32+
/// and it is a assumed that a ClusterRole named `{product_name}-clusterrole` exists.
33+
/// 'product_name' is not used to build the names of the serviceAccount and roleBinding objects,
3434
/// as this caused problems with multiple clusters of the same product within the same namespace
3535
/// see <https://stackable.atlassian.net/browse/SUP-148> for more details.
3636
/// Instead the names for these objects are created by reading the name from the cluster object
3737
/// and appending [-rolebinding|-serviceaccount] to create unique names instead of using the
3838
/// same objects for multiple clusters.
3939
pub fn build_rbac_resources<T: Clone + Resource<DynamicType = ()>>(
4040
resource: &T,
41-
rbac_prefix: &str,
41+
product_name: &str,
4242
labels: Labels,
4343
) -> Result<(ServiceAccount, RoleBinding)> {
4444
let sa_name = service_account_name(&resource.name_any());
@@ -67,7 +67,7 @@ pub fn build_rbac_resources<T: Clone + Resource<DynamicType = ()>>(
6767
.build(),
6868
role_ref: RoleRef {
6969
kind: "ClusterRole".to_string(),
70-
name: format!("{rbac_prefix}-clusterrole"),
70+
name: format!("{product_name}-clusterrole"),
7171
api_group: "rbac.authorization.k8s.io".to_string(),
7272
},
7373
subjects: Some(vec![Subject {
@@ -83,13 +83,19 @@ pub fn build_rbac_resources<T: Clone + Resource<DynamicType = ()>>(
8383

8484
/// Generate the service account name.
8585
/// The `rbac_prefix` is meant to be the product name, for example: zookeeper, airflow, etc.
86-
pub fn service_account_name(rbac_prefix: &str) -> String {
86+
/// This is private because operators should not use this function to calculate names for
87+
/// serviceAccount objects, but rather read the name from the objects returned by
88+
/// `build_rbac_resources` if they need the name.
89+
fn service_account_name(rbac_prefix: &str) -> String {
8790
format!("{rbac_prefix}-serviceaccount")
8891
}
8992

9093
/// Generate the role binding name.
9194
/// The `rbac_prefix` is meant to be the product name, for example: zookeeper, airflow, etc.
92-
pub fn role_binding_name(rbac_prefix: &str) -> String {
95+
/// This is private because operators should not use this function to calculate names for
96+
/// roleBinding objects, but rather read the name from the objects returned by
97+
/// `build_rbac_resources` if they need the name.
98+
fn role_binding_name(rbac_prefix: &str) -> String {
9399
format!("{rbac_prefix}-rolebinding")
94100
}
95101

0 commit comments

Comments
 (0)