Skip to content

Commit 90a6c6e

Browse files
committed
Add legacy name of serviceAccount to roleBinding as well for better transition period.
1 parent d04b987 commit 90a6c6e

File tree

1 file changed

+26
-12
lines changed
  • crates/stackable-operator/src/commons

1 file changed

+26
-12
lines changed

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,22 @@ pub enum Error {
3030
/// Build RBAC objects for the product workloads.
3131
/// The `product_name` is meant to be the product name, for example: zookeeper, airflow, etc.
3232
/// 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,
34-
/// as this caused problems with multiple clusters of the same product within the same namespace
35-
/// see <https://stackable.atlassian.net/browse/SUP-148> for more details.
36-
/// Instead the names for these objects are created by reading the name from the cluster object
37-
/// and appending [-rolebinding|-serviceaccount] to create unique names instead of using the
38-
/// same objects for multiple clusters.
33+
3934
pub fn build_rbac_resources<T: Clone + Resource<DynamicType = ()>>(
4035
resource: &T,
36+
// 'product_name' is not used to build the names of the serviceAccount and roleBinding objects,
37+
// as this caused problems with multiple clusters of the same product within the same namespace
38+
// see <https://stackable.atlassian.net/browse/SUP-148> for more details.
39+
// Instead the names for these objects are created by reading the name from the cluster object
40+
// and appending [-rolebinding|-serviceaccount] to create unique names instead of using the
41+
// same objects for multiple clusters.
4142
product_name: &str,
4243
labels: Labels,
4344
) -> Result<(ServiceAccount, RoleBinding)> {
4445
let sa_name = service_account_name(&resource.name_any());
46+
// We add the legacy serviceAccount name to the binding here for at least one
47+
// release cycle, so that the switchover during the upgrade can be smoother.
48+
let legacy_sa_name = service_account_name(product_name);
4549
let service_account = ServiceAccount {
4650
metadata: ObjectMetaBuilder::new()
4751
.name_and_namespace(resource)
@@ -70,12 +74,22 @@ pub fn build_rbac_resources<T: Clone + Resource<DynamicType = ()>>(
7074
name: format!("{product_name}-clusterrole"),
7175
api_group: "rbac.authorization.k8s.io".to_string(),
7276
},
73-
subjects: Some(vec![Subject {
74-
kind: "ServiceAccount".to_string(),
75-
name: sa_name,
76-
namespace: resource.namespace(),
77-
..Subject::default()
78-
}]),
77+
subjects: Some(vec![
78+
Subject {
79+
kind: "ServiceAccount".to_string(),
80+
name: sa_name,
81+
namespace: resource.namespace(),
82+
..Subject::default()
83+
},
84+
// We add the legacy serviceAccount name to the binding here for at least one
85+
// release cycle, so that the switchover during the upgrade can be smoother.
86+
Subject {
87+
kind: "ServiceAccount".to_string(),
88+
name: legacy_sa_name,
89+
namespace: resource.namespace(),
90+
..Subject::default()
91+
},
92+
]),
7993
};
8094

8195
Ok((service_account, role_binding))

0 commit comments

Comments
 (0)