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 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 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 ..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}