k8s_openapi_ext/ext/
role_binding.rs

1use super::*;
2
3pub trait RoleBindingExt: super::ResourceBuilder {
4    fn new<T>(name: impl ToString, role: &T) -> Self
5    where
6        T: IsRole;
7
8    fn subjects(self, subjects: impl IntoIterator<Item = rbacv1::Subject>) -> Self;
9}
10
11impl RoleBindingExt for rbacv1::RoleBinding {
12    fn new<T>(name: impl ToString, role: &T) -> Self
13    where
14        T: IsRole,
15    {
16        let metadata = metadata(name);
17        let role_ref = rbacv1::RoleRef {
18            api_group: T::GROUP.to_string(),
19            kind: T::KIND.to_string(),
20            name: role.metadata().name.clone().unwrap_or_default(),
21        };
22        Self {
23            metadata,
24            role_ref,
25            // subjects: todo!(),
26            ..default()
27        }
28    }
29
30    fn subjects(self, subjects: impl IntoIterator<Item = rbacv1::Subject>) -> Self {
31        let subjects = Some(subjects.into_iter().collect());
32        Self { subjects, ..self }
33    }
34}
35
36// pub trait IsRole: Resource {}
37pub trait IsRole: openapi::Metadata<Ty = metav1::ObjectMeta> {}
38
39impl IsRole for rbacv1::Role {}
40impl IsRole for rbacv1::ClusterRole {}