@@ -13,7 +13,8 @@ use stackable_operator::{
1313 } ,
1414 k8s_openapi:: api:: {
1515 apps:: v1:: DaemonSet ,
16- core:: v1:: { ConfigMap , Service } ,
16+ core:: v1:: { ConfigMap , Service , ServiceAccount } ,
17+ rbac:: v1:: RoleBinding ,
1718 } ,
1819 kube:: { Resource as KubeResource , api:: ObjectMeta } ,
1920 kvp:: Labels ,
@@ -22,7 +23,7 @@ use stackable_operator::{
2223 HasName , HasUid , NameIsValidLabelValue ,
2324 kvp:: label:: { recommended_labels, role_group_selector, role_selector} ,
2425 role_group_utils:: ResourceNames ,
25- role_utils:: { GenericCommonConfig , RoleGroupConfig } ,
26+ role_utils:: { self , GenericCommonConfig , RoleGroupConfig } ,
2627 types:: {
2728 kubernetes:: { NamespaceName , Uid } ,
2829 operator:: {
@@ -55,6 +56,9 @@ pub struct ValidatedCluster {
5556 pub name : ClusterName ,
5657 pub namespace : NamespaceName ,
5758 pub uid : Uid ,
59+ /// The product version as a valid label value, for the recommended `app.kubernetes.io/version`
60+ /// label. Derived from the resolved image's app-version label value.
61+ pub product_version : ProductVersion ,
5862 pub image : ResolvedProductImage ,
5963 pub cluster_config : ValidatedClusterConfig ,
6064 pub role_group_configs : BTreeMap < OpaRole , BTreeMap < RoleGroupName , OpaRoleGroupConfig > > ,
@@ -69,6 +73,9 @@ impl ValidatedCluster {
6973 cluster_config : ValidatedClusterConfig ,
7074 role_group_configs : BTreeMap < OpaRole , BTreeMap < RoleGroupName , OpaRoleGroupConfig > > ,
7175 ) -> Self {
76+ let product_version = ProductVersion :: from_str ( & image. app_version_label_value )
77+ . expect ( "the app version label value is a valid product version" ) ;
78+
7279 let metadata = ObjectMeta {
7380 name : Some ( name. to_string ( ) ) ,
7481 namespace : Some ( namespace. to_string ( ) ) ,
@@ -80,6 +87,7 @@ impl ValidatedCluster {
8087 name,
8188 namespace,
8289 uid,
90+ product_version,
8391 image,
8492 cluster_config,
8593 role_group_configs,
@@ -102,6 +110,15 @@ impl ValidatedCluster {
102110 . expect ( "the server role name is a valid role name" )
103111 }
104112
113+ /// Type-safe names for the per-cluster RBAC resources: the ServiceAccount shared by all
114+ /// Pods, its (namespaced) RoleBinding, and the operator-deployed ClusterRole it binds.
115+ pub fn rbac_resource_names ( & self ) -> role_utils:: ResourceNames {
116+ role_utils:: ResourceNames {
117+ cluster_name : self . name . clone ( ) ,
118+ product_name : product_name ( ) ,
119+ }
120+ }
121+
105122 /// Type-safe names for the resources of a given role group.
106123 pub ( crate ) fn resource_names ( & self , role_group_name : & RoleGroupName ) -> ResourceNames {
107124 ResourceNames {
@@ -111,27 +128,33 @@ impl ValidatedCluster {
111128 }
112129 }
113130
114- /// The product version as a type-safe label value.
115- ///
116- /// `app_version_label_value` is constructed to be a valid label value, so it is also a valid
117- /// [`ProductVersion`].
118- fn product_version ( & self ) -> ProductVersion {
119- ProductVersion :: from_str ( & self . image . app_version_label_value )
120- . expect ( "the app version label value is a valid product version" )
131+ pub fn recommended_labels ( & self , role_group_name : & RoleGroupName ) -> Labels {
132+ self . recommended_labels_for ( & Self :: role_name ( ) , role_group_name)
121133 }
122134
123- /// Recommended labels for a role-group resource.
124- ///
125- /// For role-level or cluster-level resources (e.g. the role `Service` or the discovery
126- /// `ConfigMap`) pass a placeholder role-group name such as `global` or `discovery`.
127- pub fn recommended_labels ( & self , role_group_name : & RoleGroupName ) -> Labels {
135+ /// Recommended labels for a resource that is not tied to a concrete role,
136+ /// using a free-form role/role-group label value.
137+ pub fn recommended_labels_for (
138+ & self ,
139+ role_name : & RoleName ,
140+ role_group_name : & RoleGroupName ,
141+ ) -> Labels {
142+ self . recommended_labels_with ( & self . product_version , role_name, role_group_name)
143+ }
144+
145+ fn recommended_labels_with (
146+ & self ,
147+ product_version : & ProductVersion ,
148+ role_name : & RoleName ,
149+ role_group_name : & RoleGroupName ,
150+ ) -> Labels {
128151 recommended_labels (
129152 self ,
130153 & product_name ( ) ,
131- & self . product_version ( ) ,
154+ product_version,
132155 & operator_name ( ) ,
133156 & controller_name ( ) ,
134- & Self :: role_name ( ) ,
157+ role_name,
135158 role_group_name,
136159 )
137160 }
@@ -246,6 +269,8 @@ pub struct KubernetesResources {
246269 pub daemon_sets : Vec < DaemonSet > ,
247270 pub services : Vec < Service > ,
248271 pub config_maps : Vec < ConfigMap > ,
272+ pub service_accounts : Vec < ServiceAccount > ,
273+ pub role_bindings : Vec < RoleBinding > ,
249274}
250275
251276/// Cluster-wide settings resolved once during validation, so the build steps no longer need the
0 commit comments