Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8d9d190
Initial commit
Techassi Oct 31, 2023
e59b225
Fix failing doc tests
Techassi Oct 31, 2023
2173dc5
Start to add more doc comments
Techassi Oct 31, 2023
b7b1dfb
Finish doc comments
Techassi Nov 2, 2023
f624afb
Add KeyValuePairs, add TryFrom<(&str, &str)> impl
Techassi Nov 2, 2023
5216c00
Add BTreeMap helper functions
Techassi Nov 3, 2023
215d57c
Add FromIterator impl
Techassi Nov 3, 2023
e9ffbe1
Start to add more test cases
Techassi Nov 3, 2023
5724407
Add invalid kvp tests
Techassi Nov 6, 2023
601b658
Add key, key prefix, and key name tests
Techassi Nov 6, 2023
23587bd
Add value tests
Techassi Nov 6, 2023
9d820af
Rename max length constants
Techassi Nov 6, 2023
88af1ab
Add associated function `push`
Techassi Nov 7, 2023
0ad1691
Rename unit tests
Techassi Nov 21, 2023
46c232e
Introduce generic type parameter to allow different value impls
Techassi Nov 22, 2023
fe45642
Fix annotation macro, add unit test
Techassi Nov 22, 2023
281232c
Rename generic type param, fix rustdoc error
Techassi Nov 22, 2023
a4e20aa
Add doc comments to macros
Techassi Nov 22, 2023
8c2dc0f
Update changelog
Techassi Nov 23, 2023
a95f3ac
Add macros and full feature
Techassi Nov 23, 2023
8e15d10
Start to change KeyValuePairs from Vec to HashSet
Techassi Nov 23, 2023
d164bae
Merge branch 'main' into feat/kvp
Techassi Nov 24, 2023
41510c0
Implement serde serialize
Techassi Nov 24, 2023
b5eed4b
Implement serde deserialize
Techassi Nov 24, 2023
d45854e
Use BTreeSet instead of HashSet for deterministic ordering
Techassi Nov 24, 2023
162e1d9
Add common func, add serde tests, fix deserialization
Techassi Nov 24, 2023
d6d2a7b
Introduce newtype Label and Annotation structs
Techassi Nov 28, 2023
bd8061a
Add recommended label function
Techassi Nov 28, 2023
7c46bcd
Start to adjust other label handling code (wip)
Techassi Nov 29, 2023
b19801c
Continue label/annotation handling code
Techassi Dec 4, 2023
366dd48
Add final fixes without breaking changes
Techassi Dec 5, 2023
d4bcc1f
Merge branch 'main' into feat/kvp
Techassi Dec 5, 2023
21eee91
Add label and annotation error type aliases
Techassi Dec 5, 2023
b0e74d8
Remove unwraps in secret volume builder
Techassi Dec 5, 2023
4380b05
Remove unwraps from listener volume builder
Techassi Dec 5, 2023
b52db5b
Remove unwraps in object meta builder
Techassi Dec 5, 2023
e4728a9
Remove unwraps in PDB builder
Techassi Dec 5, 2023
d127186
Rename trait ValueExt to Value
Techassi Dec 5, 2023
139b973
Change deref target
Techassi Dec 5, 2023
b3a897e
Simplify key parsing
Techassi Dec 6, 2023
28f73c8
Remove unneeded annotation validation
Techassi Dec 6, 2023
7cc8522
Remove FromStr impl for KeyValuePair, Label, and Annotation
Techassi Dec 6, 2023
be4d3a9
Remove unwraps from ClusterResources
Techassi Dec 6, 2023
99a09ee
Add annotation doc comments
Techassi Dec 11, 2023
df924e1
Add label doc comments
Techassi Dec 11, 2023
5fcec5a
Add module doc comment, remove outdated struct comment
Techassi Dec 11, 2023
5a0a789
Update const names, add doc comments
Techassi Dec 12, 2023
7e6279d
Remove label and annotation macro
Techassi Dec 12, 2023
cfaffd4
Add const module doc comment
Techassi Dec 12, 2023
6dcb465
Update and move label selector to query string functionality
Techassi Dec 12, 2023
007b028
Fix rustdoc error
Techassi Dec 12, 2023
5bf9873
Move workspace member back
Techassi Dec 14, 2023
1e6979f
Add doc comments to ObjectLabels struct
Techassi Dec 14, 2023
bd3814c
Add missing doc comments
Techassi Dec 14, 2023
bd2816c
Remove Deserialize and Serialize support
Techassi Dec 15, 2023
af7e522
Rework contains and add contains_key function
Techassi Dec 15, 2023
6f7375c
Merge branch 'main' into feat/kvp
Techassi Dec 15, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add label doc comments
  • Loading branch information
Techassi committed Dec 11, 2023
commit df924e1b205d3c8b38566bad28c83fee28bec1e8
54 changes: 47 additions & 7 deletions src/kvp/label/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
//! This module provides various types and functions to construct valid
//! Kubernetes labels. Labels are key/value pairs, where the key must meet
//! certain requirementens regarding length and character set. The value can
//! contain a limited set of ASCII characters.
//!
//! Additionally, the [`Label`] struct provides various helper functions to
//! construct commonly used labels across the Stackable Data Platform, like
//! the role_group or component.
//!
//! See <https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/>
//! for more information on Kubernetes labels.
use std::{
collections::{BTreeMap, BTreeSet},
fmt::Display,
Expand All @@ -20,9 +31,20 @@ mod value;

pub use value::*;

/// This is an type alias for [`KeyValuePairsError<LabelValueError>`]. This
/// error is returned when an error occurs while manipulating [`Labels`].
pub type LabelsError = KeyValuePairsError<LabelValueError>;

/// This is an type alias for [`KeyValuePairError<LabelValueError>`]. This
/// error is returned when constructing a [`Label`].
pub type LabelError = KeyValuePairError<LabelValueError>;

/// [`Label`] is a specialized implementation of [`KeyValuePair`]. The
/// validation of the label value can fail due to multiple reasons. It can only
/// contain a limited set of ASCII characters.
///
/// See <https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/>
/// for more information on Kubernetes labels.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Label(KeyValuePair<LabelValue>);

Expand Down Expand Up @@ -69,14 +91,17 @@ impl Label {
}

/// Creates the `app.kubernetes.io/role-group` label with `role_group` as
/// the value. This function will return an error if `role` violates the
/// required Kubernetes restrictions.
/// the value. This function will return an error if `role_group` violates
/// the required Kubernetes restrictions.
pub fn role_group(role_group: &str) -> Result<Self, LabelError> {
let kvp = KeyValuePair::try_from((ROLE_GROUP_KEY, role_group))?;
Ok(Self(kvp))
}

// TODO (Techassi): Add doc comment
/// Creates the `app.kubernetes.io/managed-by` label with the formated
/// full controller name based on `operator_name` and `controller_name` as
/// the value. This function will return an error if the formatted controller
/// name violates the required Kubernetes restrictions.
pub fn managed_by(operator_name: &str, controller_name: &str) -> Result<Self, LabelError> {
let kvp = KeyValuePair::try_from((
MANAGED_BY_KEY,
Expand All @@ -85,13 +110,18 @@ impl Label {
Ok(Self(kvp))
}

// TODO (Techassi): Maybe use semver::Version, add doc comments
/// Creates the `app.kubernetes.io/version` label with `version` as the
/// value. This function will return an error if `role_group` violates the
/// required Kubernetes restrictions.
pub fn version(version: &str) -> Result<Self, LabelError> {
// NOTE (Techassi): Maybe use semver::Version
let kvp = KeyValuePair::try_from((VERSION_KEY, version))?;
Ok(Self(kvp))
}
}

/// [`Labels`] is a set of [`Label`]. It provides selected associated functions
/// to manipulate the set of labels, like inserting or extending.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Labels(KeyValuePairs<LabelValue>);

Expand Down Expand Up @@ -169,7 +199,7 @@ impl Labels {
/// - `app.kubernetes.io/version`
/// - `app.kubernetes.io/name`
///
/// This function returns a result, because the parameter`object_labels`
/// This function returns a result, because the parameter `object_labels`
/// can contain invalid data or can exceed the maximum allowed number of
/// characters.
pub fn recommended<R>(object_labels: ObjectLabels<R>) -> Result<Self, LabelError>
Expand All @@ -193,7 +223,10 @@ impl Labels {
Ok(labels)
}

// TODO (Techassi): Add doc comment
/// Returns the set of labels required to select the resource based on the
/// role group. The set contains role selector labels, see
/// [`Labels::role_selector`] for more details. Additionally, it contains
/// the `app.kubernetes.io/role-group` label with `role_group` as the value.
pub fn role_group_selector<R>(
owner: &R,
app_name: &str,
Expand All @@ -208,7 +241,14 @@ impl Labels {
Ok(labels)
}

// TODO (Techassi): Add doc comment
/// Returns the set of labels required to select the resource based on the
/// role. The set contains the common labels, see [`Labels::common`] for
/// more details. Additionally, it contains the `app.kubernetes.io/component`
/// label with `role` as the value.
///
/// This function returns a result, because the parameters `owner`, `app_name`,
/// and `role` can contain invalid data or can exceed the maximum allowed
/// number fo characters.
pub fn role_selector<R>(owner: &R, app_name: &str, role: &str) -> Result<Self, LabelError>
where
R: Resource,
Expand Down