pub async fn apply_resource<K: k8s_openapi::Resource + Serialize>(
    name: &str,
    data: K,
    ns: &str,
) -> Result<bool> {
    use std::{
        fs::{self, File},
        io::Write,
        path::Path,
    };

    // Write it to a temporary file:
    let datafile = format!("{}.crd.gen.yml", name);
    let pth = Path::new(".").join(&datafile);
    debug!("Writing {} CRD for {} to {}", K::KIND, name, pth.display());
    let mut f = File::create(&pth)?;
    let encoded = serde_yaml::to_string(&data)?;
    writeln!(f, "{}", encoded)?;
    debug!(
        "Wrote {} CRD for {} to {}: \n{}",
        K::KIND,
        name,
        pth.display(),
        encoded
    );

    // Apply it using kubectl apply
    debug!("Applying {} CRD for {}", K::KIND, name);
    let applyargs = vec![
        format!("-n={}", ns),
        "apply".into(),
        "-f".into(),
        datafile.clone(),
    ];
    debug!("applying {} : {:?}", name, applyargs);
    let (out, status) = kout(applyargs.clone()).await?;
    print!("{}", out); // always print kube output from this
    if !status {
        bail!("subprocess failure from kubectl: {:?}", applyargs);
    }
    let changed = if out.contains("configured") || out.contains("created") {
        true
    } else if out.contains("unchanged") {
        false
    } else {
        bail!("unrecognized apply result: {}", out)
    };
    let _ = fs::remove_file(&datafile); // try to remove temporary file
    Ok(changed)
}
/// Apply the kube object an applyable file
///
/// CRDs itself, Manifest and Config typically.
/// Returns whether or not the file was configured
Apply the kube object an applyable file
CRDs itself, Manifest and Config typically.
Returns whether or not the file was configured
Apply the kube object an applyable file CRDs itself Manifest and Config typically . Returns whether or not the file was configured
pub async fn apply_resource<K: k8s_openapi::Resource + Serialize>(
    name: &str,
    data: K,
    ns: &str,
) -> Result<bool> {
    use std::{
        fs::{self, File},
        io::Write,
        path::Path,
    };
    // Write it to a temporary file:
    let datafile = format!("{}.crd.gen.yml", name);
    let pth = Path::new(".").join(&datafile);
    debug!("Writing {} CRD for {} to {}", K::KIND, name, pth.display());
    let mut f = File::create(&pth)?;
    let encoded = serde_yaml::to_string(&data)?;
    writeln!(f, "{}", encoded)?;
    debug!(
        "Wrote {} CRD for {} to {}: \n{}",
        K::KIND,
        name,
        pth.display(),
        encoded
    );
    // Apply it using kubectl apply
    debug!("Applying {} CRD for {}", K::KIND, name);
    let applyargs = vec![
        format!("-n={}", ns),
        "apply".into(),
        "-f".into(),
        datafile.clone(),
    ];
    debug!("applying {} : {:?}", name, applyargs);
    let (out, status) = kout(applyargs.clone()).await?;
    print!("{}", out); // always print kube output from this
    if !status {
        bail!("subprocess failure from kubectl: {:?}", applyargs);
    }
    let changed = if out.contains("configured") || out.contains("created") {
        true
    } else if out.contains("unchanged") {
        false
    } else {
        bail!("unrecognized apply result: {}", out)
    };
    let _ = fs::remove_file(&datafile); // try to remove temporary file
    Ok(changed)
}
pub async fn apply_resource < K : k8s_openapi :: Resource + Serialize > ( name : & str , data : K , ns : & str , ) -> Result < bool > { use std :: { fs :: { self , File } , io :: Write , path :: Path , } ; // Write it to a temporary file: let datafile = format ! ( " " name ) ; let pth = Path :: new ( " " ) . join ( & datafile ) ; debug ! ( " " K KIND name pth display ( ) ) ; let mut f = File :: create ( & pth ) ? ; let encoded = serde_yaml :: to_string ( & data ) ? ; writeln ! ( f " " encoded ) ? ; debug ! ( " \n " K KIND name pth display ( ) encoded ) ; // Apply it using kubectl apply debug ! ( " " K KIND name ) ; let applyargs = vec ! [ format ( " " ns ) " " into ( ) " " into ( ) datafile clone ( ) ] ; debug ! ( " " name applyargs ) ; let ( out , status ) = kout ( applyargs . clone ( ) ) . await ? ; print ! ( " " out ) ; // always print kube output from this if ! status { bail ! ( " " applyargs ) ; } let changed = if out . contains ( " " ) || out . contains ( " " ) { true } else if out . contains ( " " ) { false } else { bail ! ( " " out ) } ; let _ = fs :: remove_file ( & datafile ) ; // try to remove temporary file Ok ( changed ) }
Apply the kube object an applyable file
CRDs itself, Manifest and Config typically.
Apply the kube object an applyable file CRDs itself Manifest and Config typically .
name
&str
data
K
ns
&str
name
&str
data
K
ns
&str