k8s_openapi_ext/ext/
pod_template_spec.rs1use super::*;
2
3pub trait PodTemplateSpecExt: Sized {
4 fn new() -> Self;
5
6 fn label(self, key: impl ToString, value: impl ToString) -> Self {
7 self.labels([(key, value)])
8 }
9
10 fn labels(self, labels: impl IntoIterator<Item = (impl ToString, impl ToString)>) -> Self;
11
12 fn app_name(self, name: impl ToString) -> Self {
15 self.labels([(label::APP_NAME, name)])
16 }
17
18 fn app_instance(self, instance: impl ToString) -> Self {
21 self.labels([(label::APP_INSTANCE, instance)])
22 }
23
24 fn app_version(self, version: impl ToString) -> Self {
27 self.labels([(label::APP_VERSION, version)])
28 }
29
30 fn app_component(self, component: impl ToString) -> Self {
33 self.labels([(label::APP_COMPONENT, component)])
34 }
35
36 fn app_part_of(self, part_of: impl ToString) -> Self {
39 self.labels([(label::APP_PART_OF, part_of)])
40 }
41
42 fn app_managed_by(self, managed_by: impl ToString) -> Self {
45 self.labels([(label::APP_MANAGED_BY, managed_by)])
46 }
47
48 fn pod_spec(self, spec: corev1::PodSpec) -> Self;
49}
50
51impl PodTemplateSpecExt for corev1::PodTemplateSpec {
52 fn new() -> Self {
53 Self {
54 metadata: None,
55 spec: None,
56 }
57 }
58
59 fn labels(mut self, labels: impl IntoIterator<Item = (impl ToString, impl ToString)>) -> Self {
60 let labels = labels
61 .into_iter()
62 .map(|(key, value)| (key.to_string(), value.to_string()));
63 self.metadata
64 .get_or_insert_default()
65 .labels
66 .get_or_insert_default()
67 .extend(labels);
68 self
69 }
70
71 fn pod_spec(self, spec: corev1::PodSpec) -> Self {
72 Self {
73 spec: Some(spec),
74 ..self
75 }
76 }
77}
78
79impl HasSpec for corev1::PodTemplateSpec {
80 type Spec = corev1::PodSpec;
81
82 fn spec_mut(&mut self) -> &mut Self::Spec {
83 self.spec.get_or_insert_default()
84 }
85}