k8s_openapi_ext/ext/
pod_spec.rs

1use super::*;
2
3pub trait PodSpecExt {
4    fn container(container: corev1::Container) -> Self;
5
6    fn containers(containers: impl IntoIterator<Item = corev1::Container>) -> Self;
7
8    fn service_account_name(self, name: impl ToString) -> Self;
9
10    fn image_pull_secret(self, name: impl ToString) -> Self;
11
12    fn volumes(self, volumes: impl IntoIterator<Item = corev1::Volume>) -> Self;
13
14    fn node_selector(
15        self,
16        node_selector: impl IntoIterator<Item = (impl ToString, impl ToString)>,
17    ) -> Self;
18}
19
20impl PodSpecExt for corev1::PodSpec {
21    fn container(container: corev1::Container) -> Self {
22        let containers = vec![container];
23        Self {
24            containers,
25            // active_deadline_seconds: todo!(),
26            // affinity: todo!(),
27            // automount_service_account_token: todo!(),
28            // dns_config: todo!(),
29            // dns_policy: todo!(),
30            // enable_service_links: todo!(),
31            // ephemeral_containers: todo!(),
32            // host_aliases: todo!(),
33            // host_ipc: todo!(),
34            // host_network: todo!(),
35            // host_pid: todo!(),
36            // hostname: todo!(),
37            // image_pull_secrets: todo!(),
38            // init_containers: todo!(),
39            // node_name: todo!(),
40            // node_selector: todo!(),
41            // overhead: todo!(),
42            // preemption_policy: todo!(),
43            // priority: todo!(),
44            // priority_class_name: todo!(),
45            // readiness_gates: todo!(),
46            // restart_policy: todo!(),
47            // runtime_class_name: todo!(),
48            // scheduler_name: todo!(),
49            // security_context: todo!(),
50            // service_account: todo!(),
51            // service_account_name: todo!(),
52            // set_hostname_as_fqdn: todo!(),
53            // share_process_namespace: todo!(),
54            // subdomain: todo!(),
55            // termination_grace_period_seconds: todo!(),
56            // tolerations: todo!(),
57            // topology_spread_constraints: todo!(),
58            // volumes: todo!(),
59            ..default()
60        }
61    }
62
63    fn containers(containers: impl IntoIterator<Item = corev1::Container>) -> Self {
64        let containers = Vec::from_iter(containers);
65        Self {
66            containers,
67            ..default()
68        }
69    }
70
71    fn service_account_name(self, name: impl ToString) -> Self {
72        let service_account_name = Some(name.to_string());
73        Self {
74            service_account_name,
75            ..self
76        }
77    }
78
79    fn image_pull_secret(self, name: impl ToString) -> Self {
80        let image_pull_secret_name = corev1::LocalObjectReference::new(name);
81        let image_pull_secrets = Some(vec![image_pull_secret_name]);
82        Self {
83            image_pull_secrets,
84            ..self
85        }
86    }
87
88    fn volumes(self, volumes: impl IntoIterator<Item = corev1::Volume>) -> Self {
89        let volumes = Some(volumes.into_iter().collect());
90        Self { volumes, ..self }
91    }
92
93    fn node_selector(
94        self,
95        node_selector: impl IntoIterator<Item = (impl ToString, impl ToString)>,
96    ) -> Self {
97        let node_selector = Some(
98            node_selector
99                .into_iter()
100                .map(|(key, value)| (key.to_string(), value.to_string()))
101                .collect(),
102        );
103        Self {
104            node_selector,
105            ..self
106        }
107    }
108}