@@ -39,8 +39,7 @@ pub enum Error {
39
39
/// # use k8s_openapi::api::core::v1::HTTPGetAction;
40
40
/// # use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
41
41
///
42
- /// let probe = ProbeBuilder::default()
43
- /// .with_http_get_action_helper(8080, None, None)
42
+ /// let probe = ProbeBuilder::http_get_port_scheme_path(8080, None, None)
44
43
/// .with_period(Duration::from_secs(10))
45
44
/// .build()
46
45
/// .expect("failed to build probe");
@@ -68,24 +67,9 @@ pub struct ProbeBuilder<Action, Period> {
68
67
termination_grace_period : Duration ,
69
68
}
70
69
71
- impl Default for ProbeBuilder < ( ) , ( ) > {
72
- fn default ( ) -> Self {
73
- Self {
74
- action : ( ) ,
75
- period : ( ) ,
76
- // The following values match the Kubernetes defaults
77
- success_threshold : 1 ,
78
- failure_threshold : 1 ,
79
- timeout : Duration :: from_secs ( 1 ) ,
80
- initial_delay : Duration :: from_secs ( 0 ) ,
81
- termination_grace_period : Duration :: from_secs ( 0 ) ,
82
- }
83
- }
84
- }
85
-
86
70
/// Available probes
87
71
///
88
- /// Only one probe can be configured at a time. For more details about each
72
+ /// Only one probe can be configured at a time. For more details about each
89
73
/// type, see [container-probes] documentation.
90
74
///
91
75
/// [container-probes]: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes
@@ -98,78 +82,69 @@ pub enum ProbeAction {
98
82
99
83
impl ProbeBuilder < ( ) , ( ) > {
100
84
/// This probe action executes the specified command
101
- pub fn with_exec_action_helper (
102
- self ,
85
+ pub fn exec_command (
103
86
command : impl IntoIterator < Item = impl Into < String > > ,
104
87
) -> ProbeBuilder < ProbeAction , ( ) > {
105
- self . with_exec_action ( ExecAction {
88
+ Self :: exec ( ExecAction {
106
89
command : Some ( command. into_iter ( ) . map ( Into :: into) . collect ( ) ) ,
107
90
} )
108
91
}
109
92
110
- /// There is a convenience helper: [`Self::with_exec_action_helper`].
111
- pub fn with_exec_action ( self , exec_action : ExecAction ) -> ProbeBuilder < ProbeAction , ( ) > {
112
- self . with_action ( ProbeAction :: Exec ( exec_action) )
113
- }
114
-
115
- pub fn with_grpc_action ( self , grpc_action : GRPCAction ) -> ProbeBuilder < ProbeAction , ( ) > {
116
- self . with_action ( ProbeAction :: Grpc ( grpc_action) )
117
- }
118
-
119
93
// Note: Ideally we also have a builder for `HTTPGetAction`, but that is lot's of effort we
120
94
// don't want to spend now.
121
95
/// This probe action does an HTTP GET request to the specified port. Optionally, you can
122
- /// configure the path, otherwise the Kubernetes default is used.
123
- pub fn with_http_get_action_helper (
124
- self ,
96
+ /// configure a scheme and path, otherwise the Kubernetes default is used.
97
+ pub fn http_get_port_scheme_path (
125
98
port : u16 ,
126
99
scheme : Option < String > ,
127
100
path : Option < String > ,
128
101
) -> ProbeBuilder < ProbeAction , ( ) > {
129
- self . with_http_get_action ( HTTPGetAction {
102
+ Self :: http_get ( HTTPGetAction {
130
103
path,
131
104
scheme,
132
105
port : IntOrString :: Int ( port. into ( ) ) ,
133
106
..Default :: default ( )
134
107
} )
135
108
}
136
109
137
- /// There is a convenience helper: [`Self::with_http_get_action_helper`].
138
- pub fn with_http_get_action (
139
- self ,
140
- http_get_action : HTTPGetAction ,
141
- ) -> ProbeBuilder < ProbeAction , ( ) > {
142
- self . with_action ( ProbeAction :: HttpGet ( http_get_action) )
110
+ /// Set's an [`ExecAction`] as probe.
111
+ ///
112
+ /// You likely want to use [`Self::exec_command`] whenever possible.
113
+ pub fn exec ( exec_action : ExecAction ) -> ProbeBuilder < ProbeAction , ( ) > {
114
+ Self :: action ( ProbeAction :: Exec ( exec_action) )
143
115
}
144
116
145
- pub fn with_tcp_socket_action (
146
- self ,
147
- tcp_socket_action : TCPSocketAction ,
148
- ) -> ProbeBuilder < ProbeAction , ( ) > {
149
- self . with_action ( ProbeAction :: TcpSocket ( tcp_socket_action) )
117
+ /// Set's an [`GRPCAction`] as probe.
118
+ pub fn grpc ( grpc_action : GRPCAction ) -> ProbeBuilder < ProbeAction , ( ) > {
119
+ Self :: action ( ProbeAction :: Grpc ( grpc_action) )
150
120
}
151
121
152
- /// Action-specific functions (e.g. [`Self::with_exec_action`] or [`Self::with_http_get_action`])
153
- /// are recommended instead.
154
- pub fn with_action ( self , action : ProbeAction ) -> ProbeBuilder < ProbeAction , ( ) > {
155
- let Self {
156
- action : ( ) ,
157
- period,
158
- success_threshold,
159
- failure_threshold,
160
- timeout,
161
- initial_delay,
162
- termination_grace_period,
163
- } = self ;
122
+ /// Set's an [`HTTPGetAction`] as probe.
123
+ ///
124
+ /// For simple cases, there is a a convenience helper: [`Self::http_get_port_scheme_path`].
125
+ pub fn http_get ( http_get_action : HTTPGetAction ) -> ProbeBuilder < ProbeAction , ( ) > {
126
+ Self :: action ( ProbeAction :: HttpGet ( http_get_action) )
127
+ }
128
+
129
+ /// Set's an [`TCPSocketAction`] as probe.
130
+ pub fn tcp_socket ( tcp_socket_action : TCPSocketAction ) -> ProbeBuilder < ProbeAction , ( ) > {
131
+ Self :: action ( ProbeAction :: TcpSocket ( tcp_socket_action) )
132
+ }
164
133
134
+ /// Incase you already have an [`ProbeAction`] enum variant you can pass that here.
135
+ ///
136
+ /// If not, it is recommended to use one of the specialized functions such as [`Self::exec`],
137
+ /// [`Self::grpc`], [`Self::http_get`] or [`Self::tcp_socket`] or their helper functions.
138
+ pub fn action ( action : ProbeAction ) -> ProbeBuilder < ProbeAction , ( ) > {
165
139
ProbeBuilder {
166
140
action,
167
- period,
168
- success_threshold,
169
- failure_threshold,
170
- timeout,
171
- initial_delay,
172
- termination_grace_period,
141
+ period : ( ) ,
142
+ // The following values match the Kubernetes defaults
143
+ success_threshold : 1 ,
144
+ failure_threshold : 1 ,
145
+ timeout : Duration :: from_secs ( 1 ) ,
146
+ initial_delay : Duration :: from_secs ( 0 ) ,
147
+ termination_grace_period : Duration :: from_secs ( 0 ) ,
173
148
}
174
149
}
175
150
}
@@ -316,8 +291,7 @@ mod tests {
316
291
317
292
#[ test]
318
293
fn test_probe_builder_minimal ( ) {
319
- let probe = ProbeBuilder :: default ( )
320
- . with_http_get_action_helper ( 8080 , None , None )
294
+ let probe = ProbeBuilder :: http_get_port_scheme_path ( 8080 , None , None )
321
295
. with_period ( Duration :: from_secs ( 10 ) )
322
296
. build ( )
323
297
. expect ( "Valid inputs must produce a Probe" ) ;
@@ -334,8 +308,7 @@ mod tests {
334
308
335
309
#[ test]
336
310
fn test_probe_builder_complex ( ) {
337
- let probe = ProbeBuilder :: default ( )
338
- . with_exec_action_helper ( [ "sleep" , "1" ] )
311
+ let probe = ProbeBuilder :: exec_command ( [ "sleep" , "1" ] )
339
312
. with_period ( Duration :: from_secs ( 5 ) )
340
313
. with_success_threshold ( 2 )
341
314
. with_failure_threshold_duration ( Duration :: from_secs ( 33 ) )
0 commit comments