k8s_openapi_ext/ext/
cluster_role.rs1use super::*;
2
3pub trait ClusterRoleExt: super::ResourceBuilder {
4 fn new(name: impl ToString) -> Self;
5
6 fn aggregation_rule(self, selectors: impl IntoIterator<Item = metav1::LabelSelector>) -> Self;
7
8 fn rules(self, rules: impl IntoIterator<Item = rbacv1::PolicyRule>) -> Self;
9}
10
11impl ClusterRoleExt for rbacv1::ClusterRole {
12 fn new(name: impl ToString) -> Self {
13 let metadata = metadata(name);
14 Self {
15 metadata,
16 ..default()
19 }
20 }
21
22 fn aggregation_rule(self, selectors: impl IntoIterator<Item = metav1::LabelSelector>) -> Self {
23 let cluster_role_selectors = Some(selectors.into_iter().collect());
24 let aggregation_rule = Some(rbacv1::AggregationRule {
25 cluster_role_selectors,
26 });
27 Self {
28 aggregation_rule,
29 ..self
30 }
31 }
32
33 fn rules(self, rules: impl IntoIterator<Item = rbacv1::PolicyRule>) -> Self {
34 let rules = Some(rules.into_iter().collect());
35 Self { rules, ..self }
36 }
37}