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 <brian@briansmith.org>
This commit is contained in:
Brian Smith 2018-03-07 11:12:05 -10:00 committed by GitHub
parent 0d4ab39ce7
commit 72c6a9cab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -54,7 +54,7 @@ pub struct Config {
pub bind_timeout: Duration, pub bind_timeout: Duration,
pub pod_name: Option<String>, pub pod_name: Option<String>,
pub pod_namespace: Option<String>, pub pod_namespace: String,
pub pod_zone: Option<String>, pub pod_zone: Option<String>,
pub node_name: Option<String>, pub node_name: Option<String>,
@ -185,7 +185,13 @@ impl<'a> TryFrom<&'a Strings> for Config {
parse(strings, ENV_METRICS_FLUSH_INTERVAL_SECS, parse_number); parse(strings, ENV_METRICS_FLUSH_INTERVAL_SECS, parse_number);
let report_timeout = parse(strings, ENV_REPORT_TIMEOUT_SECS, parse_number); let report_timeout = parse(strings, ENV_REPORT_TIMEOUT_SECS, parse_number);
let pod_name = strings.get(ENV_POD_NAME); 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 pod_zone = strings.get(ENV_POD_ZONE);
let node_name = strings.get(ENV_NODE_NAME); let node_name = strings.get(ENV_NODE_NAME);
let destinations_autocomplete_fqdn = let destinations_autocomplete_fqdn =
@ -248,7 +254,7 @@ impl<'a> TryFrom<&'a Strings> for Config {
impl Config { impl Config {
pub fn default_destination_namespace(&self) -> Option<&String> { pub fn default_destination_namespace(&self) -> Option<&String> {
match self.destinations_autocomplete_fqdn { match self.destinations_autocomplete_fqdn {
Some(Environment::Kubernetes) => self.pod_namespace.as_ref(), Some(Environment::Kubernetes) => Some(&self.pod_namespace),
None => None, None => None,
} }
} }

View File

@ -28,8 +28,6 @@ pub struct Process {
pub scheduled_instance: String, pub scheduled_instance: String,
/// Identifies the namespace for the `scheduled_instance`. /// Identifies the namespace for the `scheduled_instance`.
///
/// Empty if unknown.
pub scheduled_namespace: String, pub scheduled_namespace: String,
} }
@ -68,7 +66,7 @@ impl Process {
Arc::new(Self { Arc::new(Self {
node: empty_if_missing(&config.node_name), node: empty_if_missing(&config.node_name),
scheduled_instance: empty_if_missing(&config.pod_name), scheduled_instance: empty_if_missing(&config.pod_name),
scheduled_namespace: empty_if_missing(&config.pod_namespace), scheduled_namespace: config.pod_namespace.clone(),
}) })
} }
} }