< 返回版块

luckoop 发表于 2024-03-18 18:45

#[tokio::test] async fn pod_test1() { let a = containers_info::<apps_v1::Deployment>().await.unwrap(); }

async fn containers_info<T>() -> Result<(), Box<dyn std::error::Error>> 
where 
T: Resource + DeserializeOwned + Debug + Clone,
T::DynamicType: Default,
{
    let kube_client = get_kube_client().await.unwrap();
    let kube_items: Api<T> = Api::all(kube_client);
    let lp = ListParams::default().fields(*SYSTEM_NAMESPACES);
    for item in kube_items.list(&lp).await? {
        let namespace = item.meta().namespace.as_ref().unwrap();
        let name = item.meta().name.as_ref().unwrap();            
        let container_type = T::kind(&T::DynamicType::default()).to_string();
        let spec = item.spec();
    }
    Ok(()) 
}

使用泛型的方法是为了减少重复代码,但是貌似不能输出spec中的字段, 但如果指定Api<apps_v1::Deployment> = Api::all(kube_client),则没有这个问题,请教大佬怎么解决

评论区

写评论

还没有评论

1 共 0 条评论, 1 页