Skip to content

Commit 4d1ff73

Browse files
committed
use Label struct for label
1 parent e71437a commit 4d1ff73

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

rust/stackable-cockpit/src/platform/demo/spec.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use snafu::{OptionExt, ResultExt, Snafu};
3+
use stackable_operator::kvp::{Label, LabelError};
34
use tracing::{Span, debug, info, instrument, warn};
45
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
56
#[cfg(feature = "openapi")]
@@ -59,6 +60,9 @@ pub enum Error {
5960

6061
#[snafu(display("failed to delete object"))]
6162
DeleteObject { source: k8s::Error },
63+
64+
#[snafu(display("failed to build label"))]
65+
BuildLabel { source: LabelError },
6266
}
6367

6468
impl InstallManifestsExt for DemoSpec {}
@@ -245,8 +249,8 @@ impl DemoSpec {
245249
// Delete remaining objects not namespace scoped
246250
client
247251
.delete_all_objects_with_label(
248-
"stackable.tech/demo",
249-
&uninstall_parameters.demo_name,
252+
Label::try_from(("stackable.tech/demo", &uninstall_parameters.demo_name))
253+
.context(BuildLabelSnafu)?,
250254
None,
251255
)
252256
.await

rust/stackable-cockpit/src/platform/stack/spec.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use serde::{Deserialize, Serialize};
22
use serde_yaml::Mapping;
33
use snafu::{OptionExt, ResultExt, Snafu};
4+
use stackable_operator::kvp::{Label, LabelError};
45
use tracing::{Span, debug, info, instrument, log::warn};
56
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
67
#[cfg(feature = "openapi")]
@@ -74,6 +75,9 @@ pub enum Error {
7475

7576
#[snafu(display("failed to delete object"))]
7677
DeleteObject { source: k8s::Error },
78+
79+
#[snafu(display("failed to build label"))]
80+
BuildLabel { source: LabelError },
7781
}
7882

7983
/// This struct describes a stack with the v2 spec
@@ -243,8 +247,8 @@ impl StackSpec {
243247
// Delete remaining objects not namespace scoped
244248
client
245249
.delete_all_objects_with_label(
246-
"stackable.tech/stack",
247-
&uninstall_parameters.stack_name,
250+
Label::try_from(("stackable.tech/stack", &uninstall_parameters.stack_name))
251+
.context(BuildLabelSnafu)?,
248252
None,
249253
)
250254
.await

rust/stackable-cockpit/src/utils/k8s/client.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use stackable_operator::{
1818
core::{DynamicObject, GroupVersionKind, ObjectList, ObjectMeta, TypeMeta},
1919
discovery::{self, ApiCapabilities, ApiResource, Scope},
2020
},
21-
kvp::Labels,
21+
kvp::{Label, Labels},
2222
};
2323
use tokio::{
2424
sync::RwLock,
@@ -323,8 +323,7 @@ impl Client {
323323
/// If no namespace is provided, deletes all clusterwide objects with the given label.
324324
pub async fn delete_all_objects_with_label(
325325
&self,
326-
label_key: &str,
327-
label_value: &str,
326+
label: Label,
328327
namespace: Option<&str>,
329328
) -> Result<(), Error> {
330329
let api_resources = self
@@ -353,8 +352,8 @@ impl Client {
353352

354353
if let Some(objectlist) = objects {
355354
for object in objectlist {
356-
if let Some(value) = object.labels().get(label_key) {
357-
if value.eq(label_value) {
355+
if let Some(value) = object.labels().get(&label.key().to_string()) {
356+
if value.eq(&label.value().to_string()) {
358357
self.delete_object(
359358
&object.metadata.name.unwrap(),
360359
&api_resource,

0 commit comments

Comments
 (0)