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
use super::*;
pub trait RoleBindingExt: super::ResourceBuilder {
fn new<T: IsRole>(name: impl ToString, role: &T) -> Self;
fn subjects(self, subjects: impl IntoIterator<Item = rbacv1::Subject>) -> Self;
}
impl RoleBindingExt for rbacv1::RoleBinding {
fn new<T: IsRole>(name: impl ToString, role: &T) -> Self
where
T: IsRole,
{
let metadata = metadata(name);
let role_ref = rbacv1::RoleRef {
api_group: T::GROUP.to_string(),
kind: T::KIND.to_string(),
name: role.metadata().name.clone().unwrap_or_default(),
};
Self {
metadata,
role_ref,
..default()
}
}
fn subjects(self, subjects: impl IntoIterator<Item = rbacv1::Subject>) -> Self {
let subjects = Some(subjects.into_iter().collect());
Self { subjects, ..self }
}
}
pub trait IsRole: openapi::Metadata<Ty = metav1::ObjectMeta> {}
impl IsRole for rbacv1::Role {}
impl IsRole for rbacv1::ClusterRole {}