Skip to content

Commit

Permalink
simplify proxy example a bit - for kube-rs#246
Browse files Browse the repository at this point in the history
  • Loading branch information
clux authored and ctron committed Jun 18, 2020
1 parent 06ee61a commit 5defe83
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions kube/examples/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ async fn main() -> anyhow::Result<()> {
std::env::set_var("RUST_LOG", "info,kube=debug");
env_logger::init();

let proxy_url = std::env::var("HTTP_PROXY").ok();
if let Some(p) = &proxy_url {
info!("HTTP_PROXY is {}", p);
let mut config = Config::from_kubeconfig(&KubeConfigOptions::default()).await?;

if let Ok(proxy_url) = &std::env::var("PROXY_URL") {
info!("PROXY_URL is {}", proxy_url);
config = config.proxy(reqwest::Proxy::https(proxy_url)?);
} else {
warn!("Running without HTTP_PROXY environment variable set");
warn!("Running without PROXY_URL environment variable set");
}

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))?;
if let Some(p) = proxy {
config = config.proxy(p);
}
let client = Client::new(config);

// Verify we can access kubernetes through proxy
Expand Down

0 comments on commit 5defe83

Please sign in to comment.