fn try_from(pod: Pod) -> Result<PodSummary> {
        let mut name = "unknown name";
        let mut age = Duration::seconds(0);
        let mut phase = "unknown phase".to_string();
        let mut version = "unknown ver".to_string();

        if let Some(meta) = &pod.metadata {
            name = match &meta.name {
                Some(n) => n,
                None => bail!("missing metadata.name on pod {:?}", pod),
            };
            let ts = match &meta.creation_timestamp {
                Some(t) => t.0,
                None => bail!("missing metadata.creation_timestamp on pod {}", name),
            };
            age = Utc::now().signed_duration_since(ts);
        }

        let mut running = 0;
        let mut containers = 0;
        let mut restarts = 0;
        if let Some(status) = pod.status {
            phase = match status.phase {
                Some(p) => p,
                None => bail!("missing status.phase on pod {}", name),
            };
            for s in status.container_statuses.unwrap_or_default() {
                running += if s.ready { 1 } else { 0 };
                containers += 1;
                restarts = std::cmp::max(restarts, s.restart_count);
            }
        }
        if let Some(spec) = pod.spec {
            let main_container = &spec.containers[0];
            version = short_ver(
                main_container
                    .image
                    .as_ref()
                    .unwrap()
                    .split(':')
                    .collect::<Vec<_>>()[1],
            );
        }
        Ok(PodSummary {
            name: name.to_string(),
            age,
            phase,
            version,
            running,
            containers,
            restarts,
        })
    }
/// Helper to convert the openapi Pod to the useful info
Helper to convert the openapi Pod to the useful info
Helper to convert the openapi Pod to the useful info
fn try_from(pod: Pod) -> Result<PodSummary> {
        let mut name = "unknown name";
        let mut age = Duration::seconds(0);
        let mut phase = "unknown phase".to_string();
        let mut version = "unknown ver".to_string();
        if let Some(meta) = &pod.metadata {
            name = match &meta.name {
                Some(n) => n,
                None => bail!("missing metadata.name on pod {:?}", pod),
            };
            let ts = match &meta.creation_timestamp {
                Some(t) => t.0,
                None => bail!("missing metadata.creation_timestamp on pod {}", name),
            };
            age = Utc::now().signed_duration_since(ts);
        }
        let mut running = 0;
        let mut containers = 0;
        let mut restarts = 0;
        if let Some(status) = pod.status {
            phase = match status.phase {
                Some(p) => p,
                None => bail!("missing status.phase on pod {}", name),
            };
            for s in status.container_statuses.unwrap_or_default() {
                running += if s.ready { 1 } else { 0 };
                containers += 1;
                restarts = std::cmp::max(restarts, s.restart_count);
            }
        }
        if let Some(spec) = pod.spec {
            let main_container = &spec.containers[0];
            version = short_ver(
                main_container
                    .image
                    .as_ref()
                    .unwrap()
                    .split(':')
                    .collect::<Vec<_>>()[1],
            );
        }
        Ok(PodSummary {
            name: name.to_string(),
            age,
            phase,
            version,
            running,
            containers,
            restarts,
        })
    }
fn try_from ( pod : Pod ) -> Result < PodSummary > { let mut name = " " ; let mut age = Duration :: seconds ( 0 ) ; let mut phase = " " . to_string ( ) ; let mut version = " " . to_string ( ) ; if let Some ( meta ) = & pod . metadata { name = match & meta . name { Some ( n ) => n , None => bail ! ( " " pod ) , } ; let ts = match & meta . creation_timestamp { Some ( t ) => t . 0 , None => bail ! ( " " name ) , } ; age = Utc :: now ( ) . signed_duration_since ( ts ) ; } let mut running = 0 ; let mut containers = 0 ; let mut restarts = 0 ; if let Some ( status ) = pod . status { phase = match status . phase { Some ( p ) => p , None => bail ! ( " " name ) , } ; for s in status . container_statuses . unwrap_or_default ( ) { running += if s . ready { 1 } else { 0 } ; containers += 1 ; restarts = std :: cmp :: max ( restarts , s . restart_count ) ; } } if let Some ( spec ) = pod . spec { let main_container = & spec . containers [ 0 ] ; version = short_ver ( main_container . image . as_ref ( ) . unwrap ( ) . split ( ':' ) . collect :: < Vec < _ > > ( ) [ 1 ] , ) ; } Ok ( PodSummary { name : name . to_string ( ) , age , phase , version , running , containers , restarts , } ) }
Helper to convert the openapi Pod to the useful info
Helper to convert the openapi Pod to the useful info
pod
Pod
pod
Pod