k8s_openapi_ext/ext/
service_port.rs

1use super::*;
2
3pub trait ServicePortExt {
4    /// Construct new `ServicePort`
5    ///
6    fn new(name: impl ToString, port: i32) -> Self;
7
8    /// Set targetPort
9    ///
10    fn target_port(self, port: impl ToIntOrString) -> Self;
11
12    /// Set protocol
13    ///
14    fn protocol(self, protocol: impl ToString) -> Self;
15
16    /// Create UDP ServicePort
17    ///
18    fn udp(name: impl ToString, port: i32) -> Self
19    where
20        Self: std::marker::Sized,
21    {
22        Self::new(name, port).protocol("UDP")
23    }
24
25    /// Create SCTP ServicePort
26    ///
27    fn sctp(name: impl ToString, port: i32) -> Self
28    where
29        Self: std::marker::Sized,
30    {
31        Self::new(name, port).protocol("SCTP")
32    }
33}
34
35impl ServicePortExt for corev1::ServicePort {
36    fn new(name: impl ToString, port: i32) -> Self {
37        let name = Some(name.to_string());
38        Self {
39            name,
40            port,
41            // app_protocol: todo!(),
42            // node_port: todo!(),
43            // protocol: todo!(),
44            // target_port: todo!(),
45            ..default()
46        }
47    }
48
49    fn target_port(self, port: impl ToIntOrString) -> Self {
50        let target_port = Some(port.to_int_or_string());
51        Self {
52            target_port,
53            ..self
54        }
55    }
56
57    fn protocol(self, protocol: impl ToString) -> Self {
58        let protocol = Some(protocol.to_string());
59        Self { protocol, ..self }
60    }
61}