anowell / kubeclient-rs

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

Allow ListQuery to be instantiated. #8

Closed ndenev closed 6 years ago

ndenev commented 6 years ago

I couldn't find another way to instantiate ListQuery from code that uses kubeclient-rs as the fields are private. Instead of making them public, implement simple constructor so it can be used like so:

    let query = ListQuery::new().label_selector("app=my-great-app");
    let pods = kube.pods().namespace("my-namespace").list(Some(&query));
anowell commented 6 years ago

This is basically just an alternate syntax for:

let query = ListQuery::default().label_selector("app=my-great-app");

I should probably document an example of using this to help make it more discoverable, but is there any particular reason this Default merits a new alias and not others?

Personally, I'm wondering if that exact construction will be common enough to merit supporting ListQuery::with_label("app=my-great-app"); or maybe listing could expose APIs more like this:

list_all()
list_with_label(label: &str)
list(query: ListQuery)

I certainly feel like querying based on label far exceeds other queries, but definitely open to opinions.

ndenev commented 6 years ago

You are right, ListQuery::default() works, for some reason I didn't think of it. I think I tried ListQuery{ ..Default::default() } which understandably didn't work because the fields are private.

anowell commented 6 years ago

Cool. I'm gonna close this for now, but if you have any compelling thoughts on the ergonomics of common usage patterns, feel free to open an issue to discuss. Cheers!