k8s_openapi_ext/ext/
node.rs

1use super::*;
2
3/// Extension trait for `corev1::Node`.
4/// Fluent builders and mutable accessors
5///
6pub trait NodeExt: ResourceBuilder {
7    /// Creates new `corev1::Node object with given `name`
8    ///
9    fn new(name: impl ToString) -> Self;
10
11    /// Sets node taints
12    ///
13    fn taints(self, taints: impl IntoIterator<Item = corev1::Taint>) -> Self;
14
15    /// Marks node as unschedulable
16    ///
17    fn unschedulable(self) -> Self;
18}
19
20impl NodeExt for corev1::Node {
21    fn new(name: impl ToString) -> Self {
22        let metadata = metadata(name);
23        Self {
24            metadata,
25            // spec: todo!(),
26            // status: todo!(),
27            ..default()
28        }
29    }
30
31    fn taints(mut self, taints: impl IntoIterator<Item = corev1::Taint>) -> Self {
32        let taints = taints.into_iter().collect();
33        self.spec_mut().taints = Some(taints);
34        self
35    }
36
37    fn unschedulable(mut self) -> Self {
38        self.spec_mut().unschedulable = Some(true);
39        self
40    }
41}
42
43impl HasSpec for corev1::Node {
44    type Spec = corev1::NodeSpec;
45
46    fn spec_mut(&mut self) -> &mut Self::Spec {
47        self.spec.get_or_insert_with(default)
48    }
49}