/// Generate for delete custom spu operation and return result.
Generate for delete custom spu operation and return result.
Generate for delete custom spu operation and return result .
pub async fn delete_custom_spu<C>(
    ctx: &PublicContext<C>,
    spu: &SpuKV,
) -> Result<FlvResponseMessage, Error>
where
    C: MetadataClient,
{
    let spu_name = spu.name();
    // must be Custom Spu
    if !spu.is_custom() {
        return Ok(FlvResponseMessage::new(
            spu_name.clone(),
            FlvErrorCode::SpuError,
            Some("expected 'Custom' spu, found 'Managed' spu".to_owned()),
        ));
    }
    // have have KV context
    let item_ctx = match &spu.kv_ctx().item_ctx {
        Some(ctx) => ctx,
        None => {
            return Ok(FlvResponseMessage::new(
                spu_name.clone(),
                FlvErrorCode::SpuError,
                Some("missing Kv context".to_owned()),
            ))
        }
    };
    // delete custom spec and return result
    let item = item_ctx.as_input();
    match ctx.k8_client().delete_item::<K8SpuSpec, _>(&item).await {
        Ok(_) => Ok(FlvResponseMessage::new_ok(spu_name.clone())),
        Err(err) => Ok(FlvResponseMessage::new(
            spu_name.clone(),
            FlvErrorCode::SpuError,
            Some(err.to_string()),
        )),
    }
}
pub async fn delete_custom_spu < C > ( ctx : & PublicContext < C > , spu : & SpuKV , ) -> Result < FlvResponseMessage , Error > where C : MetadataClient , { let spu_name = spu . name ( ) ; // must be Custom Spu if ! spu . is_custom ( ) { return Ok ( FlvResponseMessage :: new ( spu_name . clone ( ) , FlvErrorCode :: SpuError , Some ( " " . to_owned ( ) ) , ) ) ; } // have have KV context let item_ctx = match & spu . kv_ctx ( ) . item_ctx { Some ( ctx ) => ctx , None => { return Ok ( FlvResponseMessage :: new ( spu_name . clone ( ) , FlvErrorCode :: SpuError , Some ( " " . to_owned ( ) ) , ) ) } } ; // delete custom spec and return result let item = item_ctx . as_input ( ) ; match ctx . k8_client ( ) . delete_item :: < K8SpuSpec , _ > ( & item ) . await { Ok ( _ ) => Ok ( FlvResponseMessage :: new_ok ( spu_name . clone ( ) ) ) , Err ( err ) => Ok ( FlvResponseMessage :: new ( spu_name . clone ( ) , FlvErrorCode :: SpuError , Some ( err . to_string ( ) ) , ) ) , } }
Generate for delete custom spu operation and return result.
Generate for delete custom spu operation and return result .
ctx
&PublicContext<C>
spu
&SpuKV