1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use super::*;
pub trait PodSpecExt {
/// Build `corev1::PodSpec` with this container
///
fn container(container: corev1::Container) -> Self;
/// Build `corev1::PodSpec` with these containers
///
fn containers(containers: impl IntoIterator<Item = corev1::Container>) -> Self;
/// Set service account name
///
fn service_account_name(self, name: impl ToString) -> Self;
/// Add image pull secret
///
fn image_pull_secret(self, name: impl ToString) -> Self;
/// Add `volumes`
///
fn volumes(self, volumes: impl IntoIterator<Item = corev1::Volume>) -> Self;
/// Add node selector
///
fn node_selector(
self,
node_selector: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self;
/// Set affinity
///
fn affinity(self, affinity: impl Into<Option<corev1::Affinity>>) -> Self;
/// Add tolerations
///
fn tolerations(self, tolerations: impl IntoIterator<Item = corev1::Toleration>) -> Self;
}
impl PodSpecExt for corev1::PodSpec {
fn container(container: corev1::Container) -> Self {
let containers = vec![container];
Self {
containers,
// active_deadline_seconds: todo!(),
// affinity: todo!(),
// automount_service_account_token: todo!(),
// dns_config: todo!(),
// dns_policy: todo!(),
// enable_service_links: todo!(),
// ephemeral_containers: todo!(),
// host_aliases: todo!(),
// host_ipc: todo!(),
// host_network: todo!(),
// host_pid: todo!(),
// hostname: todo!(),
// image_pull_secrets: todo!(),
// init_containers: todo!(),
// node_name: todo!(),
// node_selector: todo!(),
// overhead: todo!(),
// preemption_policy: todo!(),
// priority: todo!(),
// priority_class_name: todo!(),
// readiness_gates: todo!(),
// restart_policy: todo!(),
// runtime_class_name: todo!(),
// scheduler_name: todo!(),
// security_context: todo!(),
// service_account: todo!(),
// service_account_name: todo!(),
// set_hostname_as_fqdn: todo!(),
// share_process_namespace: todo!(),
// subdomain: todo!(),
// termination_grace_period_seconds: todo!(),
// tolerations: todo!(),
// topology_spread_constraints: todo!(),
// volumes: todo!(),
..default()
}
}
fn containers(containers: impl IntoIterator<Item = corev1::Container>) -> Self {
let containers = Vec::from_iter(containers);
Self {
containers,
..default()
}
}
fn service_account_name(self, name: impl ToString) -> Self {
let service_account_name = Some(name.to_string());
Self {
service_account_name,
..self
}
}
fn image_pull_secret(mut self, name: impl ToString) -> Self {
let secret = corev1::LocalObjectReference::new(name);
self.image_pull_secrets.get_or_insert_default().push(secret);
self
}
fn volumes(mut self, volumes: impl IntoIterator<Item = corev1::Volume>) -> Self {
self.volumes.get_or_insert_default().extend(volumes);
self
}
fn node_selector(
mut self,
node_selector: impl IntoIterator<Item = (impl ToString, impl ToString)>,
) -> Self {
let node_selector = node_selector
.into_iter()
.map(|(key, value)| (key.to_string(), value.to_string()));
self.node_selector
.get_or_insert_default()
.extend(node_selector);
self
}
fn affinity(self, affinity: impl Into<Option<corev1::Affinity>>) -> Self {
let affinity = affinity.into();
Self { affinity, ..self }
}
fn tolerations(mut self, tolerations: impl IntoIterator<Item = corev1::Toleration>) -> Self {
self.tolerations.get_or_insert_default().extend(tolerations);
self
}
}