Skip to content

Commit

Permalink
Merge branch 'main' into dimad/mbe-510-proxy-randomly-closes-during-c…
Browse files Browse the repository at this point in the history
…onnection
  • Loading branch information
DmitryDodzin authored Feb 3, 2025
2 parents 32998d3 + fe3bcc9 commit ea3f493
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/+set-agent-port.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`mirrord-kube` now allows for setting agent listen port.
2 changes: 1 addition & 1 deletion mirrord/cli/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ where

let agent_connect_info = tokio::time::timeout(
Duration::from_secs(config.agent.startup_timeout),
k8s_api.create_agent(progress, &config.target, Some(config), Default::default()),
k8s_api.create_agent(progress, &config.target, Some(config), None, None),
)
.await
.unwrap_or(Err(KubeApiError::AgentReadyTimeout))
Expand Down
3 changes: 2 additions & 1 deletion mirrord/kube/src/api/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ impl ContainerParams {
tls_cert: Option<String>,
pod_ips: Option<String>,
support_ipv6: bool,
port: Option<u16>,
) -> ContainerParams {
let port: u16 = rand::thread_rng().gen_range(30000..=65535);
let port = port.unwrap_or_else(|| rand::thread_rng().gen_range(30000..=65535));
let gid: u16 = rand::thread_rng().gen_range(3000..u16::MAX);

let name = format!(
Expand Down
10 changes: 8 additions & 2 deletions mirrord/kube/src/api/kubernetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,15 @@ impl KubernetesAPI {
/// * `tls_cert` - value for
/// [`AGENT_OPERATOR_CERT_ENV`](mirrord_protocol::AGENT_OPERATOR_CERT_ENV), for creating an
/// agent from the operator. In usage from this repo this is always `None`.
/// * `agent_port` - port number on which the agent will listen for client connections. If
/// [`None`] is given, a random high port will be user.
#[tracing::instrument(level = "trace", skip(self), ret, err)]
pub async fn create_agent_params(
&self,
target: &TargetConfig,
tls_cert: Option<String>,
support_ipv6: bool,
agent_port: Option<u16>,
) -> Result<(ContainerParams, Option<RuntimeData>), KubeApiError> {
let runtime_data = match target.path.as_ref().unwrap_or(&Target::Targetless) {
Target::Targetless => None,
Expand All @@ -188,7 +191,7 @@ impl KubernetesAPI {
.join(",")
});

let params = ContainerParams::new(tls_cert, pod_ips, support_ipv6);
let params = ContainerParams::new(tls_cert, pod_ips, support_ipv6, agent_port);

Ok((params, runtime_data))
}
Expand All @@ -199,13 +202,16 @@ impl KubernetesAPI {
/// * `tls_cert` - value for
/// [`AGENT_OPERATOR_CERT_ENV`](mirrord_protocol::AGENT_OPERATOR_CERT_ENV), for creating an
/// agent from the operator. In usage from this repo this is always `None`.
/// * `agent_port` - port number on which the agent will listen for client connections. If
/// [`None`] is given, a random high port will be used.
#[tracing::instrument(level = "trace", skip(self, progress))]
pub async fn create_agent<P>(
&self,
progress: &mut P,
target: &TargetConfig,
config: Option<&LayerConfig>,
tls_cert: Option<String>,
agent_port: Option<u16>,
) -> Result<AgentKubernetesConnectInfo, KubeApiError>
where
P: Progress + Send + Sync,
Expand All @@ -214,7 +220,7 @@ impl KubernetesAPI {
.map(|layer_conf| layer_conf.feature.network.ipv6)
.unwrap_or_default();
let (params, runtime_data) = self
.create_agent_params(target, tls_cert, support_ipv6)
.create_agent_params(target, tls_cert, support_ipv6, agent_port)
.await?;
if let Some(RuntimeData {
guessed_container: true,
Expand Down

0 comments on commit ea3f493

Please sign in to comment.