From 72c6a9cab23150a31b49fe7ed2208ed3623c61e2 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 7 Mar 2018 11:12:05 -1000 Subject: [PATCH] Proxy: Make CONDUIT_PROXY_POD_NAMESPACE a required parameter. (#527) Wwe will be able to simplify service discovery in the near future if we can rely on the namespace being available. Signed-off-by: Brian Smith --- proxy/src/config.rs | 12 +++++++++--- proxy/src/ctx/mod.rs | 4 +--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/proxy/src/config.rs b/proxy/src/config.rs index 2457cb6c2..578a5afcf 100644 --- a/proxy/src/config.rs +++ b/proxy/src/config.rs @@ -54,7 +54,7 @@ pub struct Config { pub bind_timeout: Duration, pub pod_name: Option, - pub pod_namespace: Option, + pub pod_namespace: String, pub pod_zone: Option, pub node_name: Option, @@ -185,7 +185,13 @@ impl<'a> TryFrom<&'a Strings> for Config { parse(strings, ENV_METRICS_FLUSH_INTERVAL_SECS, parse_number); let report_timeout = parse(strings, ENV_REPORT_TIMEOUT_SECS, parse_number); let pod_name = strings.get(ENV_POD_NAME); - let pod_namespace = strings.get(ENV_POD_NAMESPACE); + let pod_namespace = strings.get(ENV_POD_NAMESPACE).and_then(|maybe_value| { + // There cannot be a default pod namespace, and the pod namespace is required. + maybe_value.ok_or_else(|| { + error!("{} is not set", ENV_POD_NAMESPACE); + Error::InvalidEnvVar + }) + }); let pod_zone = strings.get(ENV_POD_ZONE); let node_name = strings.get(ENV_NODE_NAME); let destinations_autocomplete_fqdn = @@ -248,7 +254,7 @@ impl<'a> TryFrom<&'a Strings> for Config { impl Config { pub fn default_destination_namespace(&self) -> Option<&String> { match self.destinations_autocomplete_fqdn { - Some(Environment::Kubernetes) => self.pod_namespace.as_ref(), + Some(Environment::Kubernetes) => Some(&self.pod_namespace), None => None, } } diff --git a/proxy/src/ctx/mod.rs b/proxy/src/ctx/mod.rs index 7f1b8e3f4..fd4e02ff9 100644 --- a/proxy/src/ctx/mod.rs +++ b/proxy/src/ctx/mod.rs @@ -28,8 +28,6 @@ pub struct Process { pub scheduled_instance: String, /// Identifies the namespace for the `scheduled_instance`. - /// - /// Empty if unknown. pub scheduled_namespace: String, } @@ -68,7 +66,7 @@ impl Process { Arc::new(Self { node: empty_if_missing(&config.node_name), scheduled_instance: empty_if_missing(&config.pod_name), - scheduled_namespace: empty_if_missing(&config.pod_namespace), + scheduled_namespace: config.pod_namespace.clone(), }) } }