k8s_openapi_ext/ext/
service_port.rs1use super::*;
2
3pub trait ServicePortExt {
4 fn new(name: impl ToString, port: i32) -> Self;
7
8 fn target_port(self, port: impl ToIntOrString) -> Self;
11
12 fn protocol(self, protocol: impl ToString) -> Self;
15
16 fn tcp(name: impl ToString, port: i32) -> Self
19 where
20 Self: Sized,
21 {
22 Self::new(name, port).protocol("TCP")
23 }
24
25 fn udp(name: impl ToString, port: i32) -> Self
28 where
29 Self: Sized,
30 {
31 Self::new(name, port).protocol("UDP")
32 }
33
34 fn sctp(name: impl ToString, port: i32) -> Self
37 where
38 Self: Sized,
39 {
40 Self::new(name, port).protocol("SCTP")
41 }
42}
43
44impl ServicePortExt for corev1::ServicePort {
45 fn new(name: impl ToString, port: i32) -> Self {
46 let name = Some(name.to_string());
47 Self {
48 name,
49 port,
50 ..default()
55 }
56 }
57
58 fn target_port(self, port: impl ToIntOrString) -> Self {
59 let target_port = Some(port.to_int_or_string());
60 Self {
61 target_port,
62 ..self
63 }
64 }
65
66 fn protocol(self, protocol: impl ToString) -> Self {
67 let protocol = Some(protocol.to_string());
68 Self { protocol, ..self }
69 }
70}