anowell / kubeclient-rs

Kubernetes API client in Rust
MIT License
30 stars 12 forks source link

examples: add a new example list-pods #5

Closed dongsupark closed 6 years ago

dongsupark commented 6 years ago

This example list-pods is equivalent to running kubectl get pods. Make use of $KUBECONFIG env variable like get-secret and list-nodes. If the variable is not set or is empty, we fall back to "admin.conf" like previously. The namespace "default" is used.

Also update existing examples to handle $KUBECONFIG.

anowell commented 6 years ago

Thanks. This all looks great at first read. I'll try this out and get it merged this weekend.

I do find the functional style of getting env vars with fallbacks to be a bit of an eyesore, and I do wonder if this:

let filename = env::var("KUBECONFIG").ok();
let filename = filename
    .as_ref()
    .map(String::as_str)
    .and_then(|s| if s.is_empty() { None } else { Some(s) })
    .unwrap_or("admin.conf");
let kube = Kubernetes::load_conf(filename)?;

is cleaner with somethinglike this:

let kube = match env:var("KUBECONFIG") {
    Some(ref filename) if !filename.is_empty() => Kubernetes::load_conf(filename)?,
    _ => Kubernetes::load_conf("admin.conf")?,
};

but really this just feels like a place where Rust could use some ergonomics love around mixing &'static str and String.

dongsupark commented 6 years ago

Thanks!