pub async fn try_delete_instance(
    kube_interface: &dyn KubeInterface,
    instance_name: &str,
    instance_namespace: &str,
) -> Result<(), anyhow::Error> {
    for x in 0..MAX_INSTANCE_UPDATE_TRIES {
        match kube_interface
            .delete_instance(instance_name, instance_namespace)
            .await
        {
            Ok(()) => {
                log::trace!("try_delete_instance - deleted Instance {}", instance_name);
                break;
            }
            Err(e) => {
                if let Some(ae) = e.downcast_ref::<kube::error::ErrorResponse>() {
                    if ae.code == ERROR_NOT_FOUND {
                        log::trace!(
                            "try_delete_instance - discovered Instance {} already deleted",
                            instance_name
                        );
                        break;
                    }
                }
                log::error!(
                    "try_delete_instance - tried to delete Instance {} but still exists. {} retries left.",
                    instance_name, MAX_INSTANCE_UPDATE_TRIES - x - 1
                );
                if x == MAX_INSTANCE_UPDATE_TRIES - 1 {
                    return Err(e);
                }
            }
        }
        random_delay().await;
    }
    Ok(())
}
/// This deletes an Instance unless it has already been deleted by another node
/// or fails after multiple retries.
This deletes an Instance unless it has already been deleted by another node
or fails after multiple retries.
This deletes an Instance unless it has already been deleted by another node or fails after multiple retries .
pub async fn try_delete_instance(
    kube_interface: &dyn KubeInterface,
    instance_name: &str,
    instance_namespace: &str,
) -> Result<(), anyhow::Error> {
    for x in 0..MAX_INSTANCE_UPDATE_TRIES {
        match kube_interface
            .delete_instance(instance_name, instance_namespace)
            .await
        {
            Ok(()) => {
                log::trace!("try_delete_instance - deleted Instance {}", instance_name);
                break;
            }
            Err(e) => {
                if let Some(ae) = e.downcast_ref::<kube::error::ErrorResponse>() {
                    if ae.code == ERROR_NOT_FOUND {
                        log::trace!(
                            "try_delete_instance - discovered Instance {} already deleted",
                            instance_name
                        );
                        break;
                    }
                }
                log::error!(
                    "try_delete_instance - tried to delete Instance {} but still exists. {} retries left.",
                    instance_name, MAX_INSTANCE_UPDATE_TRIES - x - 1
                );
                if x == MAX_INSTANCE_UPDATE_TRIES - 1 {
                    return Err(e);
                }
            }
        }
        random_delay().await;
    }
    Ok(())
}
pub async fn try_delete_instance ( kube_interface : & dyn KubeInterface , instance_name : & str , instance_namespace : & str , ) -> Result < ( ) , anyhow :: Error > { for x in 0 .. MAX_INSTANCE_UPDATE_TRIES { match kube_interface . delete_instance ( instance_name , instance_namespace ) . await { Ok ( ( ) ) => { log :: trace ! ( " " instance_name ) ; break ; } Err ( e ) => { if let Some ( ae ) = e . downcast_ref :: < kube :: error :: ErrorResponse > ( ) { if ae . code == ERROR_NOT_FOUND { log :: trace ! ( " " instance_name ) ; break ; } } log :: error ! ( " " instance_name MAX_INSTANCE_UPDATE_TRIES x 1 ) ; if x == MAX_INSTANCE_UPDATE_TRIES - 1 { return Err ( e ) ; } } } random_delay ( ) . await ; } Ok ( ( ) ) }
This deletes an Instance unless it has already been deleted by another node
or fails after multiple retries.
This deletes an Instance unless it has already been deleted by another node or fails after multiple retries .
kube_interface
&dyn KubeInterface
instance_name
&str
instance_namespace
&str
kube_interface
&dyn KubeInterface
instance_name
&str
instance_namespace
&str