From f7e2bd76c4a06d1e31001ba7d465e4897737b83a Mon Sep 17 00:00:00 2001 From: Dmitry Dodzin Date: Sun, 22 Sep 2024 11:17:53 +0300 Subject: [PATCH] Add support for container cli_extra_args (#2757) * Add support for cli_extra_args * Ops --- changelog.d/2756.added.md | 10 ++++++++++ mirrord-schema.json | 11 +++++++++++ mirrord/cli/src/container.rs | 21 ++++++++++++++------- mirrord/config/configuration.md | 14 ++++++++++++++ mirrord/config/src/container.rs | 16 ++++++++++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 changelog.d/2756.added.md diff --git a/changelog.d/2756.added.md b/changelog.d/2756.added.md new file mode 100644 index 00000000000..b06a66ebc48 --- /dev/null +++ b/changelog.d/2756.added.md @@ -0,0 +1,10 @@ +Add `cli_extra_args` field to `container` config to allow specifing custom arguments for `mirrord container` sidecar container. + +```json +{ + "container": { + "cli_extra_args": ["--network", "host"] + } +} +``` +this config will spawn mirrord cli container with ` run --network host --rm -d ...`. diff --git a/mirrord-schema.json b/mirrord-schema.json index 253dffa4571..8213a619267 100644 --- a/mirrord-schema.json +++ b/mirrord-schema.json @@ -530,6 +530,17 @@ "description": "Unstable: `mirrord container` command specific config.", "type": "object", "properties": { + "cli_extra_args": { + "title": "container.cli_extra_args {#container-cli_extra_args}", + "description": "Any extra args to use when creating the sidecar mirrord-cli container.\n\nThis is useful when you want to use portforwarding, passing `-p local:container` won't work for main command but adding them here will work ```json { \"container\": { \"cli_extra_args\": [\"-p\", \"local:container\"] } } ```", + "type": [ + "array", + "null" + ], + "items": { + "type": "string" + } + }, "cli_image": { "title": "container.cli_image {#container-cli_image}", "description": "Tag of the `mirrord-cli` image you want to use.\n\nDefaults to `\"ghcr.io/metalbear-co/mirrord-cli:\"`.", diff --git a/mirrord/cli/src/container.rs b/mirrord/cli/src/container.rs index 73b01b0bc10..8101da29580 100644 --- a/mirrord/cli/src/container.rs +++ b/mirrord/cli/src/container.rs @@ -134,13 +134,20 @@ async fn create_sidecar_intproxy( sidecar_command.add_env(MIRRORD_INTPROXY_CONTAINER_MODE_ENV, "true"); sidecar_command.add_envs(connection_info); - let sidecar_container_command = ContainerCommand::run([ - "--rm", - "-d", - &config.container.cli_image, - "mirrord", - "intproxy", - ]); + let sidecar_container_command = ContainerCommand::run( + config + .container + .cli_extra_args + .iter() + .map(String::as_str) + .chain([ + "--rm", + "-d", + &config.container.cli_image, + "mirrord", + "intproxy", + ]), + ); let (runtime_binary, sidecar_args) = sidecar_command .with_command(sidecar_container_command) diff --git a/mirrord/config/configuration.md b/mirrord/config/configuration.md index 54e87be53de..5464d945d1a 100644 --- a/mirrord/config/configuration.md +++ b/mirrord/config/configuration.md @@ -386,6 +386,20 @@ IP:PORT to connect to instead of using k8s api, for testing purposes. Unstable: `mirrord container` command specific config. +### container.cli_extra_args {#container-cli_extra_args} + +Any extra args to use when creating the sidecar mirrord-cli container. + +This is useful when you want to use portforwarding, passing `-p local:container` won't work +for main command but adding them here will work +```json +{ + "container": { + "cli_extra_args": ["-p", "local:container"] + } +} +``` + ### container.cli_image {#container-cli_image} Tag of the `mirrord-cli` image you want to use. diff --git a/mirrord/config/src/container.rs b/mirrord/config/src/container.rs index 36ef97bdf4a..f118350c4a6 100644 --- a/mirrord/config/src/container.rs +++ b/mirrord/config/src/container.rs @@ -24,6 +24,22 @@ pub struct ContainerConfig { #[config(default = DEFAULT_CLI_IMAGE)] pub cli_image: String, + /// ### container.cli_extra_args {#container-cli_extra_args} + /// + /// Any extra args to use when creating the sidecar mirrord-cli container. + /// + /// This is useful when you want to use portforwarding, passing `-p local:container` won't work + /// for main command but adding them here will work + /// ```json + /// { + /// "container": { + /// "cli_extra_args": ["-p", "local:container"] + /// } + /// } + /// ``` + #[config(default)] + pub cli_extra_args: Vec, + /// ### container.cli_image_lib_path {#container-cli_image} /// /// Path of the mirrord-layer lib inside the specified mirrord-cli image.