k8s_openapi_ext/ext/
configmap.rs1use super::*;
2
3pub trait ConfigMapExt: ResourceBuilder {
7 fn new(name: impl ToString) -> Self;
10
11 fn immutable(self, yes: bool) -> Self;
14
15 fn binary_data(self, data: impl IntoIterator<Item = (impl ToString, ByteString)>) -> Self;
18
19 fn data(self, data: impl IntoIterator<Item = (impl ToString, impl ToString)>) -> Self;
22
23 fn data_mut(&mut self) -> &mut BTreeMap<String, String>;
27
28 fn binary_data_mut(&mut self) -> &mut BTreeMap<String, ByteString>;
32}
33
34impl ConfigMapExt for corev1::ConfigMap {
35 fn new(name: impl ToString) -> Self {
36 let metadata = metadata(name);
37 Self {
38 metadata,
39 ..default()
43 }
44 }
45
46 fn immutable(self, yes: bool) -> Self {
47 let immutable = Some(yes);
48 Self { immutable, ..self }
49 }
50
51 fn binary_data(self, data: impl IntoIterator<Item = (impl ToString, ByteString)>) -> Self {
52 let data = data
53 .into_iter()
54 .map(|(key, value)| (key.to_string(), value))
55 .collect();
56 Self {
57 binary_data: Some(data),
58 ..self
59 }
60 }
61
62 fn data(self, data: impl IntoIterator<Item = (impl ToString, impl ToString)>) -> Self {
63 let data = data
64 .into_iter()
65 .map(|(key, value)| (key.to_string(), value.to_string()))
66 .collect();
67 Self {
68 data: Some(data),
69 ..self
70 }
71 }
72
73 fn data_mut(&mut self) -> &mut BTreeMap<String, String> {
74 self.data.get_or_insert_with(default)
75 }
76
77 fn binary_data_mut(&mut self) -> &mut BTreeMap<String, ByteString> {
78 self.binary_data.get_or_insert_with(default)
79 }
80}