@@ -39,8 +39,7 @@ pub enum Error {
3939/// # use k8s_openapi::api::core::v1::HTTPGetAction;
4040/// # use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
4141///
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)
4443/// .with_period(Duration::from_secs(10))
4544/// .build()
4645/// .expect("failed to build probe");
@@ -68,24 +67,9 @@ pub struct ProbeBuilder<Action, Period> {
6867 termination_grace_period : Duration ,
6968}
7069
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-
8670/// Available probes
8771///
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
8973/// type, see [container-probes] documentation.
9074///
9175/// [container-probes]: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes
@@ -98,78 +82,69 @@ pub enum ProbeAction {
9882
9983impl ProbeBuilder < ( ) , ( ) > {
10084 /// This probe action executes the specified command
101- pub fn with_exec_action_helper (
102- self ,
85+ pub fn exec_command (
10386 command : impl IntoIterator < Item = impl Into < String > > ,
10487 ) -> ProbeBuilder < ProbeAction , ( ) > {
105- self . with_exec_action ( ExecAction {
88+ Self :: exec ( ExecAction {
10689 command : Some ( command. into_iter ( ) . map ( Into :: into) . collect ( ) ) ,
10790 } )
10891 }
10992
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-
11993 // Note: Ideally we also have a builder for `HTTPGetAction`, but that is lot's of effort we
12094 // don't want to spend now.
12195 /// 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 (
12598 port : u16 ,
12699 scheme : Option < String > ,
127100 path : Option < String > ,
128101 ) -> ProbeBuilder < ProbeAction , ( ) > {
129- self . with_http_get_action ( HTTPGetAction {
102+ Self :: http_get ( HTTPGetAction {
130103 path,
131104 scheme,
132105 port : IntOrString :: Int ( port. into ( ) ) ,
133106 ..Default :: default ( )
134107 } )
135108 }
136109
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) )
143115 }
144116
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) )
150120 }
151121
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+ }
164133
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 , ( ) > {
165139 ProbeBuilder {
166140 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 ) ,
173148 }
174149 }
175150}
@@ -316,8 +291,7 @@ mod tests {
316291
317292 #[ test]
318293 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 )
321295 . with_period ( Duration :: from_secs ( 10 ) )
322296 . build ( )
323297 . expect ( "Valid inputs must produce a Probe" ) ;
@@ -334,8 +308,7 @@ mod tests {
334308
335309 #[ test]
336310 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" ] )
339312 . with_period ( Duration :: from_secs ( 5 ) )
340313 . with_success_threshold ( 2 )
341314 . with_failure_threshold_duration ( Duration :: from_secs ( 33 ) )
0 commit comments