-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
admission.rs
43 lines (41 loc) · 1.17 KB
/
admission.rs
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
use crate::with_temp_ns;
pub async fn accepts<F, T>(f: F)
where
F: FnOnce(String) -> T + Send + 'static,
T: Clone
+ Send
+ Sync
+ std::fmt::Debug
+ kube::Resource<Scope = kube::core::NamespaceResourceScope>
+ serde::de::DeserializeOwned
+ serde::Serialize,
T::DynamicType: Default,
{
with_temp_ns(|client, ns| async move {
let api = kube::Api::namespaced(client, &*ns);
let obj = f(ns);
let res = api.create(&kube::api::PostParams::default(), &obj).await;
res.expect("resource must apply");
})
.await;
}
pub async fn rejects<F, T>(f: F)
where
F: FnOnce(String) -> T + Send + 'static,
T: Clone
+ Send
+ Sync
+ std::fmt::Debug
+ kube::Resource<Scope = kube::core::NamespaceResourceScope>
+ serde::de::DeserializeOwned
+ serde::Serialize,
T::DynamicType: Default,
{
with_temp_ns(|client, ns| async move {
let api = kube::Api::namespaced(client, &*ns);
let obj = f(ns);
let res = api.create(&kube::api::PostParams::default(), &obj).await;
res.expect_err("resource must not apply");
})
.await;
}