@@ -120,107 +120,107 @@ pub mod well_known {
120120 Label :: try_from ( ( STACKABLE_VENDOR_KEY , STACKABLE_VENDOR_VALUE ) )
121121 . expect ( "failed to parse hard-coded Stackable vendor label" )
122122 }
123- }
124-
125- /// Common sets of labels that apply for different use-cases.
126- pub mod sets {
127- use kube:: { Resource , ResourceExt } ;
128-
129- use crate :: kvp:: {
130- consts:: { K8S_APP_INSTANCE_KEY , K8S_APP_NAME_KEY } ,
131- ObjectLabels ,
132- } ;
133-
134- use super :: { well_known, Label , LabelError , Labels } ;
135-
136- /// Returns the recommended set of labels. The set includes these well-known
137- /// Kubernetes labels:
138- ///
139- /// - `app.kubernetes.io/role-group`
140- /// - `app.kubernetes.io/managed-by`
141- /// - `app.kubernetes.io/component`
142- /// - `app.kubernetes.io/instance`
143- /// - `app.kubernetes.io/version`
144- /// - `app.kubernetes.io/name`
145- ///
146- /// Additionally, it includes Stackable-specific labels. These are:
147- ///
148- /// - `stackable.tech/vendor`
149- ///
150- /// This function returns a result, because the parameter `object_labels`
151- /// can contain invalid data or can exceed the maximum allowed number of
152- /// characters.
153- pub fn recommended < R > ( object_labels : ObjectLabels < R > ) -> Result < Labels , LabelError >
154- where
155- R : Resource ,
156- {
157- // Well-known Kubernetes labels
158- let mut labels = role_group_selector (
159- object_labels. owner ,
160- object_labels. app_name ,
161- object_labels. role ,
162- object_labels. role_group ,
163- ) ?;
164-
165- labels. extend ( [
166- well_known:: managed_by ( object_labels. operator_name , object_labels. controller_name ) ?,
167- well_known:: version ( object_labels. app_version ) ?,
168- // Stackable-specific labels
169- well_known:: vendor_stackable ( ) ,
170- ] ) ;
171-
172- Ok ( labels)
173- }
174-
175- /// Returns the set of labels required to select the resource based on the
176- /// role group. The set contains role selector labels, see
177- /// [`role_selector`] for more details. Additionally, it contains
178- /// the `app.kubernetes.io/role-group` label with `role_group` as the value.
179- pub fn role_group_selector < R > (
180- owner : & R ,
181- app_name : & str ,
182- role : & str ,
183- role_group : & str ,
184- ) -> Result < Labels , LabelError >
185- where
186- R : Resource ,
187- {
188- let mut labels = role_selector ( owner, app_name, role) ?;
189- labels. extend ( [ well_known:: role_group ( role_group) ?] ) ;
190- Ok ( labels)
191- }
192-
193- /// Returns the set of labels required to select the resource based on the
194- /// role. The set contains the common labels, see [`common`] for
195- /// more details. Additionally, it contains the `app.kubernetes.io/component`
196- /// label with `role` as the value.
197- ///
198- /// This function returns a result, because the parameters `owner`, `app_name`,
199- /// and `role` can contain invalid data or can exceed the maximum allowed
200- /// number fo characters.
201- pub fn role_selector < R > ( owner : & R , app_name : & str , role : & str ) -> Result < Labels , LabelError >
202- where
203- R : Resource ,
204- {
205- let mut labels = common ( app_name, owner. name_any ( ) . as_str ( ) ) ?;
206- labels. extend ( [ well_known:: component ( role) ?] ) ;
207- Ok ( labels)
208- }
209123
210- /// Returns a common set of labels, which are required to identify resources
211- /// that belong to a certain owner object, for example a `ZookeeperCluster`.
212- /// The set contains these well-known labels:
213- ///
214- /// - `app.kubernetes.io/instance` and
215- /// - `app.kubernetes.io/name`
216- ///
217- /// This function returns a result, because the parameters `app_name` and
218- /// `app_instance` can contain invalid data or can exceed the maximum
219- /// allowed number of characters.
220- pub fn common ( app_name : & str , app_instance : & str ) -> Result < Labels , LabelError > {
221- Ok ( Labels :: from_iter ( [
222- Label :: try_from ( ( K8S_APP_INSTANCE_KEY , app_instance) ) ?,
223- Label :: try_from ( ( K8S_APP_NAME_KEY , app_name) ) ?,
224- ] ) )
124+ /// Common sets of labels that apply for different use-cases.
125+ pub mod sets {
126+ use kube:: { Resource , ResourceExt } ;
127+
128+ use crate :: kvp:: {
129+ consts:: { K8S_APP_INSTANCE_KEY , K8S_APP_NAME_KEY } ,
130+ ObjectLabels ,
131+ } ;
132+
133+ use super :: super :: { Label , LabelError , Labels } ;
134+
135+ /// Returns the recommended set of labels. The set includes these well-known
136+ /// Kubernetes labels:
137+ ///
138+ /// - `app.kubernetes.io/role-group`
139+ /// - `app.kubernetes.io/managed-by`
140+ /// - `app.kubernetes.io/component`
141+ /// - `app.kubernetes.io/instance`
142+ /// - `app.kubernetes.io/version`
143+ /// - `app.kubernetes.io/name`
144+ ///
145+ /// Additionally, it includes Stackable-specific labels. These are:
146+ ///
147+ /// - `stackable.tech/vendor`
148+ ///
149+ /// This function returns a result, because the parameter `object_labels`
150+ /// can contain invalid data or can exceed the maximum allowed number of
151+ /// characters.
152+ pub fn recommended < R > ( object_labels : ObjectLabels < R > ) -> Result < Labels , LabelError >
153+ where
154+ R : Resource ,
155+ {
156+ // Well-known Kubernetes labels
157+ let mut labels = role_group_selector (
158+ object_labels. owner ,
159+ object_labels. app_name ,
160+ object_labels. role ,
161+ object_labels. role_group ,
162+ ) ?;
163+
164+ labels. extend ( [
165+ super :: managed_by ( object_labels. operator_name , object_labels. controller_name ) ?,
166+ super :: version ( object_labels. app_version ) ?,
167+ // Stackable-specific labels
168+ super :: vendor_stackable ( ) ,
169+ ] ) ;
170+
171+ Ok ( labels)
172+ }
173+
174+ /// Returns the set of labels required to select the resource based on the
175+ /// role group. The set contains role selector labels, see
176+ /// [`role_selector`] for more details. Additionally, it contains
177+ /// the `app.kubernetes.io/role-group` label with `role_group` as the value.
178+ pub fn role_group_selector < R > (
179+ owner : & R ,
180+ app_name : & str ,
181+ role : & str ,
182+ role_group : & str ,
183+ ) -> Result < Labels , LabelError >
184+ where
185+ R : Resource ,
186+ {
187+ let mut labels = role_selector ( owner, app_name, role) ?;
188+ labels. extend ( [ super :: role_group ( role_group) ?] ) ;
189+ Ok ( labels)
190+ }
191+
192+ /// Returns the set of labels required to select the resource based on the
193+ /// role. The set contains the common labels, see [`common`] for
194+ /// more details. Additionally, it contains the `app.kubernetes.io/component`
195+ /// label with `role` as the value.
196+ ///
197+ /// This function returns a result, because the parameters `owner`, `app_name`,
198+ /// and `role` can contain invalid data or can exceed the maximum allowed
199+ /// number fo characters.
200+ pub fn role_selector < R > ( owner : & R , app_name : & str , role : & str ) -> Result < Labels , LabelError >
201+ where
202+ R : Resource ,
203+ {
204+ let mut labels = common ( app_name, owner. name_any ( ) . as_str ( ) ) ?;
205+ labels. extend ( [ super :: component ( role) ?] ) ;
206+ Ok ( labels)
207+ }
208+
209+ /// Returns a common set of labels, which are required to identify resources
210+ /// that belong to a certain owner object, for example a `ZookeeperCluster`.
211+ /// The set contains these well-known labels:
212+ ///
213+ /// - `app.kubernetes.io/instance` and
214+ /// - `app.kubernetes.io/name`
215+ ///
216+ /// This function returns a result, because the parameters `app_name` and
217+ /// `app_instance` can contain invalid data or can exceed the maximum
218+ /// allowed number of characters.
219+ pub fn common ( app_name : & str , app_instance : & str ) -> Result < Labels , LabelError > {
220+ Ok ( Labels :: from_iter ( [
221+ Label :: try_from ( ( K8S_APP_INSTANCE_KEY , app_instance) ) ?,
222+ Label :: try_from ( ( K8S_APP_NAME_KEY , app_name) ) ?,
223+ ] ) )
224+ }
225225 }
226226}
0 commit comments