Skip to content

Commit aba6663

Browse files
committed
chore: Cleanup
1 parent 98bdabf commit aba6663

File tree

3 files changed

+93
-102
lines changed

3 files changed

+93
-102
lines changed

crates/stackable-operator/src/cluster_resources.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ impl ClusterResources {
474474
Ok(labels)
475475
}
476476

477+
// TODO (@Techassi): T should guarantee (by it's type) that required labels are set.
477478
/// Adds a resource to the cluster resources.
478479
///
479480
/// The resource will be patched and the patched resource will be returned.

crates/stackable-operator/src/kvp/annotation/mod.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
//! This module provides various types and functions to construct valid Kubernetes
2-
//! annotations. Annotations are key/value pairs, where the key must meet certain
3-
//! requirementens regarding length and character set. The value can contain
4-
//! **any** valid UTF-8 data.
1+
//! This module provides various types and functions to construct valid Kubernetes annotations.
2+
//! Annotations are key/value pairs, where the key must meet certain requirements regarding length
3+
//! and character set. The value can contain **any** valid UTF-8 data.
54
//!
6-
//! Additionally, the [`Annotation`] struct provides various helper functions to
7-
//! construct commonly used annotations across the Stackable Data Platform, like
8-
//! the secret scope or class.
5+
//! Additionally, the [`Annotation`] struct provides various helper functions to construct commonly
6+
//! used annotations across the Stackable Data Platform, like the secret scope or class.
97
//!
10-
//! See <https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/>
11-
//! for more information on Kubernetes annotations.
8+
//! See [the documentation][1] for more information on Kubernetes annotations.
9+
//!
10+
//! [1]: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
1211
use std::convert::Infallible;
1312

1413
use crate::kvp::{KeyValuePair, KeyValuePairError, KeyValuePairs};
@@ -17,26 +16,21 @@ mod value;
1716

1817
pub use value::*;
1918

20-
/// A type alias for errors returned when construction or manipulation of a set
21-
/// of annotations fails.
19+
/// A type alias for errors returned when construction or manipulation of a set of annotations fails.
2220
pub type AnnotationError = KeyValuePairError<Infallible>;
2321

24-
/// A specialized implementation of a key/value pair representing Kubernetes
25-
/// annotations.
22+
/// A specialized implementation of a key/value pair representing Kubernetes annotations.
23+
///
24+
/// The validation of the annotation value can **never** fail, as [`str`] is guaranteed to only
25+
/// contain valid UTF-8 data - which is the only requirement for a valid Kubernetes annotation value.
2626
///
27-
/// The validation of the annotation value can **never** fail, as [`str`] is
28-
/// guaranteed to only contain valid UTF-8 data - which is the only
29-
/// requirement for a valid Kubernetes annotation value.
27+
/// See [the documentation][1] for more information on Kubernetes annotations.
3028
///
31-
/// See <https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/>
32-
/// for more information on Kubernetes annotations.
29+
/// [1]: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
3330
pub type Annotation = KeyValuePair<AnnotationValue>;
3431

3532
/// A validated set/list of Kubernetes annotations.
3633
///
37-
/// It provides selected associated functions to manipulate the set of
38-
/// annotations, like inserting or extending.
39-
///
4034
/// ## Examples
4135
///
4236
/// ### Converting a BTreeMap into a list of labels

crates/stackable-operator/src/kvp/label/mod.rs

Lines changed: 77 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
//! This module provides various types and functions to construct valid
2-
//! Kubernetes labels. Labels are key/value pairs, where the key must meet
3-
//! certain requirementens regarding length and character set. The value can
4-
//! contain a limited set of ASCII characters.
1+
//! This module provides various types and functions to construct valid Kubernetes labels. Labels
2+
//! are key/value pairs, where the key must meet certain requirements regarding length and character
3+
//! set. The value can contain a limited set of ASCII characters.
54
//!
6-
//! Additionally, the [`Label`] struct provides various helper functions to
7-
//! construct commonly used labels across the Stackable Data Platform, like
8-
//! the role_group or component.
5+
//! Additionally, the [`Label`] struct provides various helper functions to construct commonly used
6+
//! labels across the Stackable Data Platform, like the `role_group` or `component`.
97
//!
10-
//! See <https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/>
11-
//! for more information on Kubernetes labels.
8+
//! See <https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/> for more
9+
//! information on Kubernetes labels.
1210
1311
use crate::kvp::{KeyValuePair, KeyValuePairError, KeyValuePairs};
1412

@@ -18,30 +16,26 @@ mod value;
1816
pub use selector::*;
1917
pub use value::*;
2018

21-
/// A type alias for errors returned when construction or manipulation of a set
22-
/// of labels fails.
19+
/// A type alias for errors returned when construction or manipulation of a set of labels fails.
2320
pub type LabelError = KeyValuePairError<LabelValueError>;
2421

25-
/// A specialized implementation of a key/value pair representing Kubernetes
26-
/// labels.
22+
/// A specialized implementation of a key/value pair representing Kubernetes labels.
2723
///
2824
/// ```
2925
/// # use stackable_operator::kvp::Label;
3026
/// let label = Label::try_from(("stackable.tech/vendor", "Stackable")).unwrap();
3127
/// assert_eq!(label.to_string(), "stackable.tech/vendor=Stackable");
3228
/// ```
3329
///
34-
/// The validation of the label value can fail due to multiple reasons. It can
35-
/// only contain a limited set and combination of ASCII characters. See
36-
/// <https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/>
37-
/// for more information on Kubernetes labels.
30+
/// The validation of the label value can fail due to multiple reasons. It can only contain a
31+
/// limited set and combination of ASCII characters. See [the documentation][1] for more information
32+
/// on Kubernetes labels.
33+
///
34+
/// [1]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
3835
pub type Label = KeyValuePair<LabelValue>;
3936

4037
/// A validated set/list of Kubernetes labels.
4138
///
42-
/// It provides selected associated functions to manipulate the set of labels,
43-
/// like inserting or extending.
44-
///
4539
/// ## Examples
4640
///
4741
/// ### Converting a BTreeMap into a list of labels
@@ -72,88 +66,89 @@ pub type Labels = KeyValuePairs<LabelValue>;
7266

7367
/// Well-known labels used by other tools or standard conventions.
7468
pub mod well_known {
75-
use crate::{
76-
kvp::consts::{
77-
K8S_APP_COMPONENT_KEY, K8S_APP_MANAGED_BY_KEY, K8S_APP_ROLE_GROUP_KEY,
78-
K8S_APP_VERSION_KEY, STACKABLE_VENDOR_KEY, STACKABLE_VENDOR_VALUE,
79-
},
80-
utils::format_full_controller_name,
81-
};
82-
83-
use super::{Label, LabelError};
84-
85-
/// Creates the `app.kubernetes.io/component` label with `role` as the
86-
/// value. This function will return an error if `role` violates the required
87-
/// Kubernetes restrictions.
88-
pub fn component(component: &str) -> Result<Label, LabelError> {
89-
Label::try_from((K8S_APP_COMPONENT_KEY, component))
90-
}
69+
use crate::utils::format_full_controller_name;
9170

92-
/// Creates the `app.kubernetes.io/role-group` label with `role_group` as
93-
/// the value. This function will return an error if `role_group` violates
94-
/// the required Kubernetes restrictions.
95-
pub fn role_group(role_group: &str) -> Result<Label, LabelError> {
96-
Label::try_from((K8S_APP_ROLE_GROUP_KEY, role_group))
71+
use super::{Label, LabelError, Labels};
72+
73+
/// Creates the `app.kubernetes.io/component` label.
74+
///
75+
/// It is used to specify the component within the architecture, e.g. `database`.
76+
///
77+
/// This function will return an error if `role` violates the required Kubernetes restrictions.
78+
pub fn component(component: &str) -> Result<Label, LabelError> {
79+
Label::try_from(("app.kubernetes.io/component", component))
9780
}
9881

99-
/// Creates the `app.kubernetes.io/managed-by` label with the formated
100-
/// full controller name based on `operator_name` and `controller_name` as
101-
/// the value. This function will return an error if the formatted controller
102-
/// name violates the required Kubernetes restrictions.
82+
/// Creates the `app.kubernetes.io/managed-by` label with the formatted full controller name as
83+
/// a value.
84+
///
85+
/// The controller name is based on `operator_name` and `controller_name`. It is used to
86+
/// indicate what tool is being used to manage the operation of an application, e.g. `helm`.
87+
///
88+
/// This function will return an error if the formatted controller name violates the required
89+
/// Kubernetes restrictions.
10390
pub fn managed_by(operator_name: &str, controller_name: &str) -> Result<Label, LabelError> {
10491
Label::try_from((
105-
K8S_APP_MANAGED_BY_KEY,
92+
"app.kubernetes.io/managed-by",
10693
format_full_controller_name(operator_name, controller_name).as_str(),
10794
))
10895
}
10996

110-
/// Creates the `app.kubernetes.io/version` label with `version` as the
111-
/// value. This function will return an error if `role_group` violates the
112-
/// required Kubernetes restrictions.
97+
/// Creates the `app.kubernetes.io/version` label.
98+
///
99+
/// It is used to indicate the current version of the application. The value can represent a
100+
/// semantic version or a revision, e.g. `5.7.21`.
101+
///
102+
/// This function will return an error if `role_group` violates the required Kubernetes
103+
/// restrictions.
113104
pub fn version(version: &str) -> Result<Label, LabelError> {
114-
Label::try_from((K8S_APP_VERSION_KEY, version))
105+
Label::try_from(("app.kubernetes.io/version", version))
115106
}
116107

117-
/// Creates the `stackable.tech/vendor: Stackable` label, tagging the object as
118-
/// created by a Stackable operator.
108+
/// Creates the `stackable.tech/vendor: Stackable` label, tagging the object as created by a
109+
/// Stackable operator.
119110
pub fn vendor_stackable() -> Label {
120-
Label::try_from((STACKABLE_VENDOR_KEY, STACKABLE_VENDOR_VALUE))
111+
Label::try_from(("stackable.tech/vendor", "Stackable"))
121112
.expect("failed to parse hard-coded Stackable vendor label")
122113
}
123114

115+
/// Creates the `stackable.tech/role-group` label.
116+
///
117+
/// This function will return an error if `role_group` violates the required Kubernetes
118+
/// restrictions.
119+
pub fn role_group(role_group: &str) -> Result<Label, LabelError> {
120+
Label::try_from(("stackable.tech/role-group", role_group))
121+
}
122+
124123
/// Common sets of labels that apply for different use-cases.
125124
pub mod sets {
126125
use kube::{Resource, ResourceExt};
127126

128-
use crate::kvp::{
129-
consts::{K8S_APP_INSTANCE_KEY, K8S_APP_NAME_KEY},
130-
ObjectLabels,
131-
};
127+
use crate::kvp::ObjectLabels;
132128

133-
use super::super::{Label, LabelError, Labels};
129+
use super::{Label, LabelError, Labels};
134130

135-
/// Returns the recommended set of labels. The set includes these well-known
136-
/// Kubernetes labels:
131+
/// Returns the recommended set of labels.
132+
///
133+
/// The set includes these well-known Kubernetes labels:
137134
///
138-
/// - `app.kubernetes.io/role-group`
139135
/// - `app.kubernetes.io/managed-by`
140136
/// - `app.kubernetes.io/component`
141137
/// - `app.kubernetes.io/instance`
142138
/// - `app.kubernetes.io/version`
143139
/// - `app.kubernetes.io/name`
144140
///
145-
/// Additionally, it includes Stackable-specific labels. These are:
141+
/// Additionally, it includes these Stackable-specific labels:
146142
///
143+
/// - `stackable.tech/role-group`
147144
/// - `stackable.tech/vendor`
148145
///
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.
146+
/// This function returns a [`Result`], because the parameter `object_labels` can contain
147+
/// invalid data or can exceed the maximum allowed number of characters.
152148
pub fn recommended<R>(object_labels: ObjectLabels<R>) -> Result<Labels, LabelError>
153149
where
154150
R: Resource,
155151
{
156-
// Well-known Kubernetes labels
157152
let mut labels = role_group_selector(
158153
object_labels.owner,
159154
object_labels.app_name,
@@ -171,10 +166,11 @@ pub mod well_known {
171166
Ok(labels)
172167
}
173168

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.
169+
/// Returns the set of labels required to select the resource based on the role group.
170+
///
171+
/// The set contains role selector labels, see [`role_selector`] for more details.
172+
/// Additionally, it contains the `stackable.tech/role-group` label with `role_group` as the
173+
/// value.
178174
pub fn role_group_selector<R>(
179175
owner: &R,
180176
app_name: &str,
@@ -189,10 +185,10 @@ pub mod well_known {
189185
Ok(labels)
190186
}
191187

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.
188+
/// Returns the set of labels required to select the resource based on the role.
189+
///
190+
/// The set contains the common labels, see [`common`] for more details. Additionally, it
191+
/// contains the `app.kubernetes.io/component` label with `role` as the value.
196192
///
197193
/// This function returns a result, because the parameters `owner`, `app_name`,
198194
/// and `role` can contain invalid data or can exceed the maximum allowed
@@ -206,20 +202,20 @@ pub mod well_known {
206202
Ok(labels)
207203
}
208204

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`.
205+
/// Returns a common set of labels, which are required to identify resources that belong to
206+
/// a certain owner object, for example a `ZookeeperCluster`.
207+
///
211208
/// The set contains these well-known labels:
212209
///
213210
/// - `app.kubernetes.io/instance` and
214211
/// - `app.kubernetes.io/name`
215212
///
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.
213+
/// This function returns a result, because the parameters `app_name` and `app_instance` can
214+
/// contain invalid data or can exceed the maximum allowed number of characters.
219215
pub fn common(app_name: &str, app_instance: &str) -> Result<Labels, LabelError> {
220216
Ok(Labels::from_iter([
221-
Label::try_from((K8S_APP_INSTANCE_KEY, app_instance))?,
222-
Label::try_from((K8S_APP_NAME_KEY, app_name))?,
217+
Label::try_from(("app.kubernetes.io/instance", app_instance))?,
218+
Label::try_from(("app.kubernetes.io/name", app_name))?,
223219
]))
224220
}
225221
}

0 commit comments

Comments
 (0)