Skip to content
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

Merged
merged 1 commit into from
Jun 3, 2020
Merged

Implement accessing Kubernetes API via proxy #246

merged 1 commit into from
Jun 3, 2020

Conversation

koiuo
Copy link
Contributor

@koiuo koiuo commented Jun 2, 2020

This commit adds method Config::proxy that allows setting proxy to use
when talking to Kubernetes API.

Fixes #245

This commit adds method `Config::proxy` that allows setting proxy to use
when talking to Kubernetes API.

Fixes #245
Copy link
Member

@clux clux left a 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();
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

@koiuo koiuo Jun 3, 2020

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

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice example!

@clux clux merged commit cf4773e into kube-rs:master Jun 3, 2020
/// ```
pub fn proxy(&mut self, proxy: reqwest::Proxy) -> Self {
Config { proxy: Some(proxy), ..(self.clone()) }
}
Copy link
Member

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)

clux added a commit that referenced this pull request Jun 3, 2020
clux added a commit that referenced this pull request Jun 3, 2020
ctron pushed a commit to ctron/kube-rs that referenced this pull request Jun 18, 2020
ctron pushed a commit to ctron/kube-rs that referenced this pull request Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Talk to k8s API via http(s) proxy
2 participants