-
-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement accessing Kubernetes API via proxy #246
Conversation
This commit adds method `Config::proxy` that allows setting proxy to use when talking to Kubernetes API. Fixes #245
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you! One small casing issue in the example that i'll probably tweak once it's in.
std::env::set_var("RUST_LOG", "info,kube=debug"); | ||
env_logger::init(); | ||
|
||
let proxy_url = std::env::var("http_proxy").ok(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would stick to upper case for an evar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking was that http_proxy
is a defacto standard inspired by curl. kubectl
too respects this env var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh really? sorry, i was not aware of that. i'll change it back then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean to push for my option.
The example you made is more focused on the important part. Also reqwest lets setting socks5 proxy too with that code, so PROXY_URL
is strictly speaking a more meaningful name.
I wrote my comment to just explain why lowercase, and it was before I saw your example.
Apologies for the caused confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yes, that is true as well - even though the example does not support multiplexing to other reqwest::proxy constructors.
it's nice to be able to match conventions where they exist - so appreciate the reasoning there - but perhaps it's actually better to have the more generic name in this case.
no worries! i'll just leave it as is now then :-)
let mut config = Config::from_kubeconfig(&KubeConfigOptions::default()).await?; | ||
let proxy = proxy_url.map(|url| reqwest::Proxy::https(&url)).map_or(Ok(None), |p| p.map(Some))?; | ||
let config = proxy.map(|p| config.proxy(p)).unwrap_or(config); | ||
let client = Client::new(config); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice example!
/// ``` | ||
pub fn proxy(&mut self, proxy: reqwest::Proxy) -> Self { | ||
Config { proxy: Some(proxy), ..(self.clone()) } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, actually... this is pointlessly cloning self. probably will change this to modify (it already takes a mut self)
This commit adds method
Config::proxy
that allows setting proxy to usewhen talking to Kubernetes API.
Fixes #245