pub async fn run_to_completion<PodState: Send + Sync + 'static>(
    client: &kube::Client,
    state: impl State<PodState>,
    pod_state: &mut PodState,
    pod: &Pod,
) {
    let api: Api<KubePod> = Api::namespaced(client.clone(), pod.namespace());

    let mut state: Box<dyn State<PodState>> = Box::new(state);

    loop {
        debug!("Pod {} entering state {:?}", pod.name(), state);

        match state.json_status(pod_state, &pod).await {
            Ok(patch) => {
                debug!("Pod {} status patch: {:?}", pod.name(), &patch);
                patch_status(&api, pod.name(), patch).await;
            }
            Err(e) => {
                warn!("Pod {} status patch returned error: {:?}", pod.name(), e);
            }
        }

        debug!("Pod {} executing state handler {:?}", pod.name(), state);
        let transition = { state.next(pod_state, &pod).await };

        state = match transition {
            Transition::Next(s) => {
                debug!("Pod {} transitioning to {:?}.", pod.name(), s.state);
                s.state
            }
            Transition::Complete(result) => match result {
                Ok(()) => {
                    debug!("Pod {} state machine exited without error", pod.name());
                    break;
                }
                Err(e) => {
                    error!(
                        "Pod {} state machine exited with error: {:?}",
                        pod.name(),
                        e
                    );
                    let patch = serde_json::json!(
                        {
                            "metadata": {
                                "resourceVersion": "",
                            },
                            "status": {
                                "phase": Phase::Failed,
                                "reason": format!("{:?}", e),
                            }
                        }
                    );
                    patch_status(&api, pod.name(), patch).await;
                    break;
                }
            },
        };
    }
}
/// Iteratively evaluate state machine until it returns Complete.
Iteratively evaluate state machine until it returns Complete.
Iteratively evaluate state machine until it returns Complete .
pub async fn run_to_completion<PodState: Send + Sync + 'static>(
    client: &kube::Client,
    state: impl State<PodState>,
    pod_state: &mut PodState,
    pod: &Pod,
) {
    let api: Api<KubePod> = Api::namespaced(client.clone(), pod.namespace());
    let mut state: Box<dyn State<PodState>> = Box::new(state);
    loop {
        debug!("Pod {} entering state {:?}", pod.name(), state);
        match state.json_status(pod_state, &pod).await {
            Ok(patch) => {
                debug!("Pod {} status patch: {:?}", pod.name(), &patch);
                patch_status(&api, pod.name(), patch).await;
            }
            Err(e) => {
                warn!("Pod {} status patch returned error: {:?}", pod.name(), e);
            }
        }
        debug!("Pod {} executing state handler {:?}", pod.name(), state);
        let transition = { state.next(pod_state, &pod).await };
        state = match transition {
            Transition::Next(s) => {
                debug!("Pod {} transitioning to {:?}.", pod.name(), s.state);
                s.state
            }
            Transition::Complete(result) => match result {
                Ok(()) => {
                    debug!("Pod {} state machine exited without error", pod.name());
                    break;
                }
                Err(e) => {
                    error!(
                        "Pod {} state machine exited with error: {:?}",
                        pod.name(),
                        e
                    );
                    let patch = serde_json::json!(
                        {
                            "metadata": {
                                "resourceVersion": "",
                            },
                            "status": {
                                "phase": Phase::Failed,
                                "reason": format!("{:?}", e),
                            }
                        }
                    );
                    patch_status(&api, pod.name(), patch).await;
                    break;
                }
            },
        };
    }
}
pub async fn run_to_completion < PodState : Send + Sync + ' static > ( client : & kube :: Client , state : impl State < PodState > , pod_state : & mut PodState , pod : & Pod , ) { let api : Api < KubePod > = Api :: namespaced ( client . clone ( ) , pod . namespace ( ) ) ; let mut state : Box < dyn State < PodState > > = Box :: new ( state ) ; loop { debug ! ( " " pod name ( ) state ) ; match state . json_status ( pod_state , & pod ) . await { Ok ( patch ) => { debug ! ( " " pod name ( ) patch ) ; patch_status ( & api , pod . name ( ) , patch ) . await ; } Err ( e ) => { warn ! ( " " pod name ( ) e ) ; } } debug ! ( " " pod name ( ) state ) ; let transition = { state . next ( pod_state , & pod ) . await } ; state = match transition { Transition :: Next ( s ) => { debug ! ( " " pod name ( ) s state ) ; s . state } Transition :: Complete ( result ) => match result { Ok ( ( ) ) => { debug ! ( " " pod name ( ) ) ; break ; } Err ( e ) => { error ! ( " " pod name ( ) e ) ; let patch = serde_json :: json ! ( { " " { " " " " } " " { " " Phase Failed " " format ( " " e ) } } ) ; patch_status ( & api , pod . name ( ) , patch ) . await ; break ; } } , } ; } }
Iteratively evaluate state machine until it returns Complete.
Iteratively evaluate state machine until it returns Complete .
client
&kube::Client
state
impl State<PodState>
pod_state
&mut PodState
pod
&Pod
client
&kube::Client
state
impl State<PodState>
pod_state
&mut PodState
pod
&Pod