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
15impl PodSpecExt for corev1::PodSpec {
16    fn container(container: corev1::Container) -> Self {
17        let containers = vec![container];
18        Self {
19            containers,
20            // active_deadline_seconds: todo!(),
21            // affinity: todo!(),
22            // automount_service_account_token: todo!(),
23            // dns_config: todo!(),
24            // dns_policy: todo!(),
25            // enable_service_links: todo!(),
26            // ephemeral_containers: todo!(),
27            // host_aliases: todo!(),
28            // host_ipc: todo!(),
29            // host_network: todo!(),
30            // host_pid: todo!(),
31            // hostname: todo!(),
32            // image_pull_secrets: todo!(),
33            // init_containers: todo!(),
34            // node_name: todo!(),
35            // node_selector: todo!(),
36            // overhead: todo!(),
37            // preemption_policy: todo!(),
38            // priority: todo!(),
39            // priority_class_name: todo!(),
40            // readiness_gates: todo!(),
41            // restart_policy: todo!(),
42            // runtime_class_name: todo!(),
43            // scheduler_name: todo!(),
44            // security_context: todo!(),
45            // service_account: todo!(),
46            // service_account_name: todo!(),
47            // set_hostname_as_fqdn: todo!(),
48            // share_process_namespace: todo!(),
49            // subdomain: todo!(),
50            // termination_grace_period_seconds: todo!(),
51            // tolerations: todo!(),
52            // topology_spread_constraints: todo!(),
53            // volumes: todo!(),
54            ..default()
55        }
56    }
57
58    fn containers(containers: impl IntoIterator<Item = corev1::Container>) -> Self {
59        let containers = Vec::from_iter(containers);
60        Self {
61            containers,
62            ..default()
63        }
64    }
65
66    fn service_account_name(self, name: impl ToString) -> Self {
67        let service_account_name = Some(name.to_string());
68        Self {
69            service_account_name,
70            ..self
71        }
72    }
73
74    fn image_pull_secret(self, name: impl ToString) -> Self {
75        let image_pull_secret_name = corev1::LocalObjectReference::new(name);
76        let image_pull_secrets = Some(vec![image_pull_secret_name]);
77        Self {
78            image_pull_secrets,
79            ..self
80        }
81    }
82
83    fn volumes(self, volumes: impl IntoIterator<Item = corev1::Volume>) -> Self {
84        let volumes = Some(volumes.into_iter().collect());
85        Self { volumes, ..self }
86    }
87}