pub async fn port_forward(mf: &Manifest) -> Result<()> {
    let access_request = AccessReviewRequest {
        namespace: mf.namespace.clone(),
        verb: "create".into(),
        resource: "pods".into(),
        subresource: Some("portforward".into()),
    };

    if !kani(access_request).await? {
        bail!("Current token does not have authorization to port-forward")
    };

    // TODO: kubectl auth can-i create pods/portforward first
    let port_offset = 7777;
    let mut ps: Vec<_> = mf.ports.iter().map(|mp| mp.port).collect();

    if let Some(p) = mf.httpPort {
        if ps.iter().find(|&&mp| mp == p).is_none() {
            ps.push(p);
        }
    };

    if ps.is_empty() {
        bail!("{} does not expose any port to port-forward to", mf.name)
    };

    let ports = ps.iter().enumerate().map(|(i, &port)| {
        let localport: u32 = if port <= 1024 {
            port_offset + i as u32
        } else {
            port
        };
        debug!(
            "Port forwarding kube deployment {}:{} to localhost:{}",
            mf.name, port, localport
        );
        (port, localport)
    });

    // kubectl port-forward deployment/${name} localport:httpPort
    let mut pfargs = vec![
        format!("-n={}", mf.namespace),
        "port-forward".into(),
        format!("{}/{}", mf.workload.to_string(), mf.name),
    ];

    for (port, localport) in ports {
        pfargs.push(format!("{}:{}", localport, port));
    }

    kexec(pfargs).await?;
    Ok(())
}
/// Port forward a port to localhost
///
/// Useful because we have autocomplete on manifest names in shipcat
Port forward a port to localhost
Useful because we have autocomplete on manifest names in shipcat
Port forward a port to localhost Useful because we have autocomplete on manifest names in shipcat
pub async fn port_forward(mf: &Manifest) -> Result<()> {
    let access_request = AccessReviewRequest {
        namespace: mf.namespace.clone(),
        verb: "create".into(),
        resource: "pods".into(),
        subresource: Some("portforward".into()),
    };
    if !kani(access_request).await? {
        bail!("Current token does not have authorization to port-forward")
    };
    // TODO: kubectl auth can-i create pods/portforward first
    let port_offset = 7777;
    let mut ps: Vec<_> = mf.ports.iter().map(|mp| mp.port).collect();
    if let Some(p) = mf.httpPort {
        if ps.iter().find(|&&mp| mp == p).is_none() {
            ps.push(p);
        }
    };
    if ps.is_empty() {
        bail!("{} does not expose any port to port-forward to", mf.name)
    };
    let ports = ps.iter().enumerate().map(|(i, &port)| {
        let localport: u32 = if port <= 1024 {
            port_offset + i as u32
        } else {
            port
        };
        debug!(
            "Port forwarding kube deployment {}:{} to localhost:{}",
            mf.name, port, localport
        );
        (port, localport)
    });
    // kubectl port-forward deployment/${name} localport:httpPort
    let mut pfargs = vec![
        format!("-n={}", mf.namespace),
        "port-forward".into(),
        format!("{}/{}", mf.workload.to_string(), mf.name),
    ];
    for (port, localport) in ports {
        pfargs.push(format!("{}:{}", localport, port));
    }
    kexec(pfargs).await?;
    Ok(())
}
pub async fn port_forward ( mf : & Manifest ) -> Result < ( ) > { let access_request = AccessReviewRequest { namespace : mf . namespace . clone ( ) , verb : " " . into ( ) , resource : " " . into ( ) , subresource : Some ( " " . into ( ) ) , } ; if ! kani ( access_request ) . await ? { bail ! ( " " ) } ; // TODO: kubectl auth can-i create pods/portforward first let port_offset = 7777 ; let mut ps : Vec < _ > = mf . ports . iter ( ) . map ( | mp | mp . port ) . collect ( ) ; if let Some ( p ) = mf . httpPort { if ps . iter ( ) . find ( | & & mp | mp == p ) . is_none ( ) { ps . push ( p ) ; } } ; if ps . is_empty ( ) { bail ! ( " " mf name ) } ; let ports = ps . iter ( ) . enumerate ( ) . map ( | ( i , & port ) | { let localport : u32 = if port <= 1024 { port_offset + i as u32 } else { port } ; debug ! ( " " mf name port localport ) ; ( port , localport ) } ) ; // kubectl port-forward deployment/${name} localport:httpPort let mut pfargs = vec ! [ format ( " " mf namespace ) " " into ( ) format ( " " mf workload to_string ( ) mf name ) ] ; for ( port , localport ) in ports { pfargs . push ( format ! ( " " localport port ) ) ; } kexec ( pfargs ) . await ? ; Ok ( ( ) ) }
Port forward a port to localhost
Useful because we have autocomplete on manifest names in shipcat
Port forward a port to localhost Useful because we have autocomplete on manifest names in shipcat
mf
&Manifest
mf
&Manifest