k8s_openapi_ext/ext/
pod.rs1use super::*;
2
3pub trait PodExt {
4 fn new(name: impl ToString) -> Self;
7
8 fn with_labels(
11 name: impl ToString,
12 labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
13 ) -> Self;
14
15 fn spec(self, spec: corev1::PodSpec) -> Self;
18
19 fn container(self, container: corev1::Container) -> Self;
22
23 fn containers(self, containers: impl IntoIterator<Item = corev1::Container>) -> Self;
26}
27
28impl PodExt for corev1::Pod {
29 fn new(name: impl ToString) -> Self {
30 let metadata = metadata(name);
31 Self {
32 metadata,
33 ..default()
36 }
37 }
38
39 fn with_labels(
40 name: impl ToString,
41 labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
42 ) -> Self {
43 Self::new(name).labels(labels)
44 }
45
46 fn spec(self, spec: corev1::PodSpec) -> Self {
47 Self {
48 spec: Some(spec),
49 ..self
50 }
51 }
52
53 fn container(mut self, container: corev1::Container) -> Self {
54 self.spec_mut().containers = vec![container];
55 self
56 }
57
58 fn containers(mut self, containers: impl IntoIterator<Item = corev1::Container>) -> Self {
59 self.spec_mut().containers = containers.into_iter().collect();
60 self
61 }
62}
63
64impl HasSpec for corev1::Pod {
65 type Spec = corev1::PodSpec;
66
67 fn spec_mut(&mut self) -> &mut Self::Spec {
68 self.spec.get_or_insert_with(default)
69 }
70}