Skip to content

Commit e71437a

Browse files
committed
delete namespace function
1 parent c187cff commit e71437a

File tree

3 files changed

+18
-38
lines changed

3 files changed

+18
-38
lines changed

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use serde::{Deserialize, Serialize};
22
use snafu::{OptionExt, ResultExt, Snafu};
3-
use stackable_operator::kube::api::{ApiResource, GroupVersionKind};
43
use tracing::{Span, debug, info, instrument, warn};
54
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
65
#[cfg(feature = "openapi")]
@@ -239,15 +238,7 @@ impl DemoSpec {
239238

240239
// Delete demo namespace
241240
client
242-
.delete_object(
243-
&uninstall_parameters.demo_namespace,
244-
&ApiResource::from_gvk(&GroupVersionKind {
245-
group: "".to_owned(),
246-
version: "v1".to_owned(),
247-
kind: "Namespace".to_owned(),
248-
}),
249-
None,
250-
)
241+
.delete_namespace(uninstall_parameters.demo_namespace)
251242
.await
252243
.context(DeleteObjectSnafu)?;
253244

@@ -269,15 +260,7 @@ impl DemoSpec {
269260
.context(UninstallReleaseSnafu)?;
270261

271262
client
272-
.delete_object(
273-
&uninstall_parameters.operator_namespace,
274-
&ApiResource::from_gvk(&GroupVersionKind {
275-
group: "".to_owned(),
276-
version: "v1".to_owned(),
277-
kind: "Namespace".to_owned(),
278-
}),
279-
None,
280-
)
263+
.delete_namespace(uninstall_parameters.operator_namespace)
281264
.await
282265
.context(DeleteObjectSnafu)?;
283266
}

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use serde_yaml::Mapping;
33
use snafu::{OptionExt, ResultExt, Snafu};
4-
use stackable_operator::kube::api::{ApiResource, GroupVersionKind};
54
use tracing::{Span, debug, info, instrument, log::warn};
65
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
76
#[cfg(feature = "openapi")]
@@ -237,15 +236,7 @@ impl StackSpec {
237236

238237
// Delete stack namespace
239238
client
240-
.delete_object(
241-
&uninstall_parameters.stack_namespace,
242-
&ApiResource::from_gvk(&GroupVersionKind {
243-
group: "".to_owned(),
244-
version: "v1".to_owned(),
245-
kind: "Namespace".to_owned(),
246-
}),
247-
None,
248-
)
239+
.delete_namespace(uninstall_parameters.stack_namespace)
249240
.await
250241
.context(DeleteObjectSnafu)?;
251242

@@ -265,15 +256,7 @@ impl StackSpec {
265256
.await?;
266257

267258
client
268-
.delete_object(
269-
&uninstall_parameters.operator_namespace,
270-
&ApiResource::from_gvk(&GroupVersionKind {
271-
group: "".to_owned(),
272-
version: "v1".to_owned(),
273-
kind: "Namespace".to_owned(),
274-
}),
275-
None,
276-
)
259+
.delete_namespace(uninstall_parameters.operator_namespace)
277260
.await
278261
.context(DeleteObjectSnafu)?;
279262
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,20 @@ impl Client {
601601
Ok(())
602602
}
603603

604+
/// Deletes a [`Namespace`] with `name` in the cluster.
605+
pub async fn delete_namespace(&self, name: String) -> Result<()> {
606+
self.delete_object(
607+
&name,
608+
&ApiResource::from_gvk(&GroupVersionKind {
609+
group: "".to_owned(),
610+
version: "v1".to_owned(),
611+
kind: "Namespace".to_owned(),
612+
}),
613+
None,
614+
)
615+
.await
616+
}
617+
604618
/// Creates a [`Namespace`] only if not already present in the current cluster.
605619
pub async fn create_namespace_if_needed(&self, name: String) -> Result<()> {
606620
if self.get_namespace(&name).await?.is_none() {

0 commit comments

Comments
 (0)