Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow agent port to be configurable #3053

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading