k8s_openapi_ext/ext/
pod_spec.rs1use super::*;
2
3pub trait PodSpecExt {
4 fn container(container: corev1::Container) -> Self;
7
8 fn containers(containers: impl IntoIterator<Item = corev1::Container>) -> Self;
11
12 fn service_account_name(self, name: impl ToString) -> Self;
15
16 fn image_pull_secret(self, name: impl ToString) -> Self;
19
20 fn volumes(self, volumes: impl IntoIterator<Item = corev1::Volume>) -> Self;
23
24 fn node_selector(
27 self,
28 node_selector: impl IntoIterator<Item = (impl ToString, impl ToString)>,
29 ) -> Self;
30
31 fn affinity(self, affinity: impl Into<Option<corev1::Affinity>>) -> Self;
34
35 fn tolerations(self, tolerations: impl IntoIterator<Item = corev1::Toleration>) -> Self;
38}
39
40impl PodSpecExt for corev1::PodSpec {
41 fn container(container: corev1::Container) -> Self {
42 let containers = vec![container];
43 Self {
44 containers,
45 ..default()
80 }
81 }
82
83 fn containers(containers: impl IntoIterator<Item = corev1::Container>) -> Self {
84 let containers = Vec::from_iter(containers);
85 Self {
86 containers,
87 ..default()
88 }
89 }
90
91 fn service_account_name(self, name: impl ToString) -> Self {
92 let service_account_name = Some(name.to_string());
93 Self {
94 service_account_name,
95 ..self
96 }
97 }
98
99 fn image_pull_secret(mut self, name: impl ToString) -> Self {
100 let secret = corev1::LocalObjectReference::new(name);
101 self.image_pull_secrets.get_or_insert_default().push(secret);
102 self
103 }
104
105 fn volumes(mut self, volumes: impl IntoIterator<Item = corev1::Volume>) -> Self {
106 self.volumes.get_or_insert_default().extend(volumes);
107 self
108 }
109
110 fn node_selector(
111 mut self,
112 node_selector: impl IntoIterator<Item = (impl ToString, impl ToString)>,
113 ) -> Self {
114 let node_selector = node_selector
115 .into_iter()
116 .map(|(key, value)| (key.to_string(), value.to_string()));
117 self.node_selector
118 .get_or_insert_default()
119 .extend(node_selector);
120 self
121 }
122
123 fn affinity(self, affinity: impl Into<Option<corev1::Affinity>>) -> Self {
124 let affinity = affinity.into();
125 Self { affinity, ..self }
126 }
127
128 fn tolerations(mut self, tolerations: impl IntoIterator<Item = corev1::Toleration>) -> Self {
129 self.tolerations.get_or_insert_default().extend(tolerations);
130 self
131 }
132}