@@ -79,14 +79,12 @@ where
7979/// use k8s_openapi::api::core::v1::Pod;
8080/// fn my_custom_condition(my_cond: &str) -> impl Condition<Pod> + '_ {
8181/// move |obj: Option<&Pod>| {
82- /// if let Some(pod) = &obj {
83- /// if let Some(status) = &pod.status {
84- /// if let Some(conds) = &status.conditions {
85- /// if let Some(pcond) = conds.iter().find(|c| c.type_ == my_cond) {
86- /// return pcond.status == "True";
87- /// }
88- /// }
89- /// }
82+ /// if let Some(pod) = &obj
83+ /// && let Some(status) = &pod.status
84+ /// && let Some(conds) = &status.conditions
85+ /// && let Some(pcond) = conds.iter().find(|c| c.type_ == my_cond)
86+ /// {
87+ /// return pcond.status == "True";
9088/// }
9189/// false
9290/// }
@@ -196,14 +194,12 @@ pub mod conditions {
196194 #[ must_use]
197195 pub fn is_crd_established ( ) -> impl Condition < CustomResourceDefinition > {
198196 |obj : Option < & CustomResourceDefinition > | {
199- if let Some ( o) = obj {
200- if let Some ( s) = & o. status {
201- if let Some ( conds) = & s. conditions {
202- if let Some ( pcond) = conds. iter ( ) . find ( |c| c. type_ == "Established" ) {
203- return pcond. status == "True" ;
204- }
205- }
206- }
197+ if let Some ( o) = obj
198+ && let Some ( s) = & o. status
199+ && let Some ( conds) = & s. conditions
200+ && let Some ( pcond) = conds. iter ( ) . find ( |c| c. type_ == "Established" )
201+ {
202+ return pcond. status == "True" ;
207203 }
208204 false
209205 }
@@ -213,12 +209,11 @@ pub mod conditions {
213209 #[ must_use]
214210 pub fn is_pod_running ( ) -> impl Condition < Pod > {
215211 |obj : Option < & Pod > | {
216- if let Some ( pod) = & obj {
217- if let Some ( status) = & pod. status {
218- if let Some ( phase) = & status. phase {
219- return phase == "Running" ;
220- }
221- }
212+ if let Some ( pod) = & obj
213+ && let Some ( status) = & pod. status
214+ && let Some ( phase) = & status. phase
215+ {
216+ return phase == "Running" ;
222217 }
223218 false
224219 }
@@ -228,14 +223,12 @@ pub mod conditions {
228223 #[ must_use]
229224 pub fn is_job_completed ( ) -> impl Condition < Job > {
230225 |obj : Option < & Job > | {
231- if let Some ( job) = & obj {
232- if let Some ( s) = & job. status {
233- if let Some ( conds) = & s. conditions {
234- if let Some ( pcond) = conds. iter ( ) . find ( |c| c. type_ == "Complete" ) {
235- return pcond. status == "True" ;
236- }
237- }
238- }
226+ if let Some ( job) = & obj
227+ && let Some ( s) = & job. status
228+ && let Some ( conds) = & s. conditions
229+ && let Some ( pcond) = conds. iter ( ) . find ( |c| c. type_ == "Complete" )
230+ {
231+ return pcond. status == "True" ;
239232 }
240233 false
241234 }
@@ -248,16 +241,14 @@ pub mod conditions {
248241 #[ must_use]
249242 pub fn is_deployment_completed ( ) -> impl Condition < Deployment > {
250243 |obj : Option < & Deployment > | {
251- if let Some ( depl) = & obj {
252- if let Some ( s) = & depl. status {
253- if let Some ( conds) = & s. conditions {
254- if let Some ( dcond) = conds. iter ( ) . find ( |c| {
255- c. type_ == "Progressing" && c. reason == Some ( "NewReplicaSetAvailable" . to_string ( ) )
256- } ) {
257- return dcond. status == "True" ;
258- }
259- }
260- }
244+ if let Some ( depl) = & obj
245+ && let Some ( s) = & depl. status
246+ && let Some ( conds) = & s. conditions
247+ && let Some ( dcond) = conds. iter ( ) . find ( |c| {
248+ c. type_ == "Progressing" && c. reason == Some ( "NewReplicaSetAvailable" . to_string ( ) )
249+ } )
250+ {
251+ return dcond. status == "True" ;
261252 }
262253 false
263254 }
@@ -267,20 +258,19 @@ pub mod conditions {
267258 #[ must_use]
268259 pub fn is_service_loadbalancer_provisioned ( ) -> impl Condition < Service > {
269260 |obj : Option < & Service > | {
270- if let Some ( svc) = & obj {
261+ if let Some ( svc) = & obj
262+ && let Some ( spec) = & svc. spec
263+ {
271264 // ignore services that are not type LoadBalancer (return true immediately)
272- if let Some ( spec) = & svc. spec {
273- if spec. type_ != Some ( "LoadBalancer" . to_string ( ) ) {
274- return true ;
275- }
276- // carry on if this is a LoadBalancer service
277- if let Some ( s) = & svc. status {
278- if let Some ( lbs) = & s. load_balancer {
279- if let Some ( ings) = & lbs. ingress {
280- return ings. iter ( ) . all ( |ip| ip. ip . is_some ( ) || ip. hostname . is_some ( ) ) ;
281- }
282- }
283- }
265+ if spec. type_ != Some ( "LoadBalancer" . to_string ( ) ) {
266+ return true ;
267+ }
268+ // carry on if this is a LoadBalancer service
269+ if let Some ( s) = & svc. status
270+ && let Some ( lbs) = & s. load_balancer
271+ && let Some ( ings) = & lbs. ingress
272+ {
273+ return ings. iter ( ) . all ( |ip| ip. ip . is_some ( ) || ip. hostname . is_some ( ) ) ;
284274 }
285275 }
286276 false
@@ -291,14 +281,12 @@ pub mod conditions {
291281 #[ must_use]
292282 pub fn is_ingress_provisioned ( ) -> impl Condition < Ingress > {
293283 |obj : Option < & Ingress > | {
294- if let Some ( ing) = & obj {
295- if let Some ( s) = & ing. status {
296- if let Some ( lbs) = & s. load_balancer {
297- if let Some ( ings) = & lbs. ingress {
298- return ings. iter ( ) . all ( |ip| ip. ip . is_some ( ) || ip. hostname . is_some ( ) ) ;
299- }
300- }
301- }
284+ if let Some ( ing) = & obj
285+ && let Some ( s) = & ing. status
286+ && let Some ( lbs) = & s. load_balancer
287+ && let Some ( ings) = & lbs. ingress
288+ {
289+ return ings. iter ( ) . all ( |ip| ip. ip . is_some ( ) || ip. hostname . is_some ( ) ) ;
302290 }
303291 false
304292 }
0 commit comments