k8s_openapi_ext/ext/
daemon_set.rs

1use super::*;
2
3pub trait DaemonSetExt: super::ResourceBuilder {
4    fn new(name: impl ToString) -> Self;
5    fn with_labels(
6        name: impl ToString,
7        labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
8    ) -> Self;
9
10    fn spec(self, spec: appsv1::DaemonSetSpec) -> Self;
11
12    fn min_ready_seconds(self, seconds: i32) -> Self;
13
14    fn revision_history_limit(self, limit: i32) -> Self;
15
16    fn selector(self, selector: metav1::LabelSelector) -> Self;
17
18    fn match_labels(
19        self,
20        match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
21    ) -> Self;
22
23    fn update_strategy(self, strategy: appsv1::DaemonSetUpdateStrategy) -> Self;
24
25    fn template(self, template: corev1::PodTemplateSpec) -> Self;
26
27    fn pod(self, pod: corev1::PodSpec) -> Self;
28}
29
30impl DaemonSetExt for appsv1::DaemonSet {
31    fn new(name: impl ToString) -> Self {
32        let metadata = metadata(name);
33        Self {
34            metadata,
35            // spec: todo!(),
36            // status: todo!(),
37            ..default()
38        }
39    }
40
41    fn with_labels(
42        name: impl ToString,
43        labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
44    ) -> Self {
45        Self::new(name).labels(labels)
46    }
47
48    fn spec(self, spec: appsv1::DaemonSetSpec) -> Self {
49        Self {
50            spec: Some(spec),
51            ..self
52        }
53    }
54
55    fn min_ready_seconds(mut self, seconds: i32) -> Self {
56        self.spec_mut().min_ready_seconds.replace(seconds);
57        self
58    }
59
60    fn revision_history_limit(mut self, limit: i32) -> Self {
61        self.spec_mut().revision_history_limit.replace(limit);
62        self
63    }
64
65    fn selector(mut self, selector: metav1::LabelSelector) -> Self {
66        self.spec_mut().selector = selector;
67        self
68    }
69
70    fn match_labels(
71        self,
72        match_labels: impl IntoIterator<Item = (impl ToString, impl ToString)>,
73    ) -> Self {
74        let mut spec = self.spec.unwrap_or_default();
75        spec.selector = spec.selector.match_labels(match_labels);
76        Self {
77            spec: Some(spec),
78            ..self
79        }
80    }
81
82    fn update_strategy(mut self, strategy: appsv1::DaemonSetUpdateStrategy) -> Self {
83        self.spec_mut().update_strategy.replace(strategy);
84        self
85    }
86
87    fn template(mut self, template: corev1::PodTemplateSpec) -> Self {
88        self.spec_mut().template = template;
89        self
90    }
91
92    fn pod(mut self, pod_spec: corev1::PodSpec) -> Self {
93        self.spec_mut().template.spec.replace(pod_spec);
94        self
95    }
96}
97
98impl HasSpec for appsv1::DaemonSet {
99    type Spec = appsv1::DaemonSetSpec;
100
101    fn spec_mut(&mut self) -> &mut Self::Spec {
102        self.spec.get_or_insert_default()
103    }
104}