-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathfinalizer.rs
More file actions
46 lines (42 loc) · 1.75 KB
/
Copy pathfinalizer.rs
File metadata and controls
46 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::crd::Echo;
use kube::api::{Patch, PatchParams};
use kube::{Api, Client, Error};
use serde_json::{json, Value};
/// Adds a finalizer record into an `Echo` kind of resource. If the finalizer already exists,
/// this action has no effect.
///
/// # Arguments:
/// - `client` - Kubernetes client to modify the `Echo` resource with.
/// - `name` - Name of the `Echo` resource to modify. Existence is not verified
/// - `namespace` - Namespace where the `Echo` resource with given `name` resides.
///
/// Note: Does not check for resource's existence for simplicity.
pub async fn add(client: Client, name: &str, namespace: &str) -> Result<Echo, Error> {
let api: Api<Echo> = Api::namespaced(client, namespace);
let finalizer: Value = json!({
"metadata": {
"finalizers": ["echoes.example.com/finalizer"]
}
});
let patch: Patch<&Value> = Patch::Merge(&finalizer);
api.patch(name, &PatchParams::default(), &patch).await
}
/// Removes all finalizers from an `Echo` resource. If there are no finalizers already, this
/// action has no effect.
///
/// # Arguments:
/// - `client` - Kubernetes client to modify the `Echo` resource with.
/// - `name` - Name of the `Echo` resource to modify. Existence is not verified
/// - `namespace` - Namespace where the `Echo` resource with given `name` resides.
///
/// Note: Does not check for resource's existence for simplicity.
pub async fn delete(client: Client, name: &str, namespace: &str) -> Result<Echo, Error> {
let api: Api<Echo> = Api::namespaced(client, namespace);
let finalizer: Value = json!({
"metadata": {
"finalizers": null
}
});
let patch: Patch<&Value> = Patch::Merge(&finalizer);
api.patch(name, &PatchParams::default(), &patch).await
}