@@ -30,18 +30,22 @@ pub enum Error {
30
30
/// Build RBAC objects for the product workloads.
31
31
/// The `product_name` is meant to be the product name, for example: zookeeper, airflow, etc.
32
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,
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
+
39
34
pub fn build_rbac_resources < T : Clone + Resource < DynamicType = ( ) > > (
40
35
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.
41
42
product_name : & str ,
42
43
labels : Labels ,
43
44
) -> Result < ( ServiceAccount , RoleBinding ) > {
44
45
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) ;
45
49
let service_account = ServiceAccount {
46
50
metadata : ObjectMetaBuilder :: new ( )
47
51
. name_and_namespace ( resource)
@@ -70,12 +74,22 @@ pub fn build_rbac_resources<T: Clone + Resource<DynamicType = ()>>(
70
74
name : format ! ( "{product_name}-clusterrole" ) ,
71
75
api_group : "rbac.authorization.k8s.io" . to_string ( ) ,
72
76
} ,
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
+ ] ) ,
79
93
} ;
80
94
81
95
Ok ( ( service_account, role_binding) )
0 commit comments