diff --git a/mirrord/cli/src/execution.rs b/mirrord/cli/src/execution.rs index 5d3e9657e88..611c45172ce 100644 --- a/mirrord/cli/src/execution.rs +++ b/mirrord/cli/src/execution.rs @@ -7,7 +7,7 @@ use std::{ use mirrord_analytics::{AnalyticsError, AnalyticsReporter, Reporter}; use mirrord_config::{ config::ConfigError, feature::env::mapper::EnvVarsRemapper, - internal_proxy::MIRRORD_INTPROXY_CONNECT_TCP_ENV, LayerConfig, + internal_proxy::MIRRORD_INTPROXY_CONNECT_TCP_ENV, LayerConfig, MIRRORD_RESOLVED_CONFIG_ENV, }; use mirrord_intproxy::agent_conn::AgentConnectInfo; use mirrord_operator::client::OperatorSession; @@ -269,7 +269,7 @@ impl MirrordExecution { let stdout = proxy_process.stdout.take().expect("stdout was piped"); - let address: SocketAddr = BufReader::new(stdout) + let intproxy_address: SocketAddr = BufReader::new(stdout) .lines() .next_line() .await @@ -288,9 +288,10 @@ impl MirrordExecution { )) })?; - // Provide details for layer to connect to agent via internal proxy - config.connect_tcp = Some(format!("127.0.0.1:{}", address.port())); + config.connect_tcp.replace(intproxy_address.to_string()); config.update_env_var()?; + let config_as_env = config.to_env_var()?; + env_vars.insert(MIRRORD_RESOLVED_CONFIG_ENV.to_string(), config_as_env); // Fixes // by disabling the fork safety check in the Objective-C runtime. diff --git a/mirrord/cli/src/extension.rs b/mirrord/cli/src/extension.rs index 005491a9aed..0c3f2c9c73c 100644 --- a/mirrord/cli/src/extension.rs +++ b/mirrord/cli/src/extension.rs @@ -4,7 +4,7 @@ use mirrord_analytics::{AnalyticsError, AnalyticsReporter, Reporter}; use mirrord_config::{LayerConfig, MIRRORD_CONFIG_FILE_ENV}; use mirrord_progress::{JsonProgress, Progress, ProgressTracker}; -use crate::{config::ExtensionExecArgs, error::CliError, execution::MirrordExecution, CliResult}; +use crate::{config::ExtensionExecArgs, execution::MirrordExecution, CliResult}; /// Actually facilitate execution after all preparations were complete async fn mirrord_exec

( @@ -40,23 +40,15 @@ where pub(crate) async fn extension_exec(args: ExtensionExecArgs, watch: drain::Watch) -> CliResult<()> { let progress = ProgressTracker::try_from_env("mirrord preparing to launch") .unwrap_or_else(|| JsonProgress::new("mirrord preparing to launch").into()); - let mut env: HashMap = HashMap::new(); + // Set environment required for `LayerConfig::from_env_with_warnings`. if let Some(config_file) = args.config_file.as_ref() { - // Set canoncialized path to config file, in case forks/children are in different - // working directories. - let full_path = std::fs::canonicalize(config_file) - .map_err(|e| CliError::CanonicalizeConfigPathFailed(config_file.into(), e))?; - std::env::set_var(MIRRORD_CONFIG_FILE_ENV, full_path.clone()); - env.insert( - MIRRORD_CONFIG_FILE_ENV.into(), - full_path.to_string_lossy().into(), - ); + std::env::set_var(MIRRORD_CONFIG_FILE_ENV, config_file); } if let Some(target) = args.target.as_ref() { std::env::set_var("MIRRORD_IMPERSONATED_TARGET", target.clone()); - env.insert("MIRRORD_IMPERSONATED_TARGET".into(), target.to_string()); } + let (config, mut context) = LayerConfig::from_env_with_warnings()?; let mut analytics = AnalyticsReporter::only_error(config.telemetry, Default::default(), watch); @@ -76,7 +68,7 @@ pub(crate) async fn extension_exec(args: ExtensionExecArgs, watch: drain::Watch) ) .await; #[cfg(not(target_os = "macos"))] - let execution_result = mirrord_exec(env, config, progress, &mut analytics).await; + let execution_result = mirrord_exec(Default::default(), config, progress, &mut analytics).await; if execution_result.is_err() && !analytics.has_error() { analytics.set_error(AnalyticsError::Unknown); diff --git a/mirrord/config/src/lib.rs b/mirrord/config/src/lib.rs index 8414bd742df..d3f8fae7bc6 100644 --- a/mirrord/config/src/lib.rs +++ b/mirrord/config/src/lib.rs @@ -345,15 +345,15 @@ impl LayerConfig { /// Given a [`LayerConfig`], serialise it and convert to base 64 so it can be /// set into [`MIRRORD_RESOLVED_CONFIG_ENV`]. - fn to_env_var(&self) -> Result { + pub fn to_env_var(&self) -> Result { let serialized = serde_json::to_string(self) .map_err(|error| ConfigError::EnvVarEncodeError(error.to_string()))?; Ok(BASE64_STANDARD.encode(serialized)) } - /// Given the encoded config as a string, set it into [`MIRRORD_RESOLVED_CONFIG_ENV`]. - /// Must be used when updating [`LayerConfig`] after creation in order for the config - /// in env to reflect the change. + /// Encode this config with [`Self::to_env_var`] and set it into + /// [`MIRRORD_RESOLVED_CONFIG_ENV`]. Must be used when updating [`LayerConfig`] after + /// creation in order for the config in env to reflect the change. pub fn update_env_var(&self) -> Result<(), ConfigError> { std::env::set_var(MIRRORD_RESOLVED_CONFIG_ENV, self.to_env_var()?); Ok(())