Skip to content

Commit c99705d

Browse files
committed
feat(operator): Add new convenience functions to Label
This adds the following new associated functions to construct labels: - `Label::instance`: app.kubernetes.io/instance - `Label::name`: app.kubernetes.io/name - `Label::stackable_vendor`: stackable.tech/vendor=Stackable
1 parent dfd4e21 commit c99705d

File tree

1 file changed

+26
-1
lines changed
  • crates/stackable-operator/src/kvp/label

1 file changed

+26
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,31 @@ impl Label {
192192
let kvp = KeyValuePair::try_from((K8S_APP_VERSION_KEY, version))?;
193193
Ok(Self(kvp))
194194
}
195+
196+
/// Creates the `app.kubernetes.io/instance` label with `instance` as the value.
197+
///
198+
/// This function will return an error if `instance` violates the required Kubernetes
199+
/// restrictions.
200+
pub fn instance(instance: &str) -> Result<Self, LabelError> {
201+
let kvp = KeyValuePair::try_from((K8S_APP_INSTANCE_KEY, instance))?;
202+
Ok(Self(kvp))
203+
}
204+
205+
/// Creates the `app.kubernetes.io/name` label with `name` as the value.
206+
///
207+
/// This function will return an error if `name` violates the required Kubernetes restrictions.
208+
pub fn name(name: &str) -> Result<Self, LabelError> {
209+
let kvp = KeyValuePair::try_from((K8S_APP_NAME_KEY, name))?;
210+
Ok(Self(kvp))
211+
}
212+
213+
/// Creates the Stackable specific vendor label.
214+
///
215+
/// See [`STACKABLE_VENDOR_KEY`] and [`STACKABLE_VENDOR_VALUE`].
216+
pub fn stackable_vendor() -> Self {
217+
Self::try_from((STACKABLE_VENDOR_KEY, STACKABLE_VENDOR_VALUE))
218+
.expect("constant vendor label must be valid")
219+
}
195220
}
196221

197222
/// A validated set/list of Kubernetes labels.
@@ -388,7 +413,7 @@ impl Labels {
388413
labels.insert(version);
389414

390415
// Stackable-specific labels
391-
labels.parse_insert((STACKABLE_VENDOR_KEY, STACKABLE_VENDOR_VALUE))?;
416+
labels.insert(Label::stackable_vendor());
392417

393418
Ok(labels)
394419
}

0 commit comments

Comments
 (0)