Simplify passing of arguments through wwctl container exec

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2024-11-01 19:55:54 -06:00
parent f4308ca02d
commit a0c58e4183
3 changed files with 7 additions and 5 deletions

View File

@@ -83,6 +83,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix issue that NetworkManager marks managed interfaces "unmanaged" if they do
not have a device specified. #1154
- Return non-zero exit code on overlay sub-commands #1423
- Simplify passing of arguments to commands through `wwctl container exec`. #253
## v4.5.8, 2024-10-01

View File

@@ -61,6 +61,7 @@ func runContainedCmd(cmd *cobra.Command, containerName string, args []string) (e
if nodeName != "" {
childArgs = append(childArgs, "--node", nodeName)
}
childArgs = append(childArgs, "--")
childArgs = append(childArgs, args...)
// copy the files into the container at this stage, es in __child the
// command syscall.Exec which replaces the __child process with the

View File

@@ -40,27 +40,27 @@ func Test_Exec(t *testing.T) {
{
name: "plain test",
args: []string{"test", "/bin/true"},
stdout: `--loglevel 20 container exec __child test /bin/true`,
stdout: `--loglevel 20 container exec __child test -- /bin/true`,
},
{
name: "test with --bind",
args: []string{"test", "--bind", "/tmp", "/bin/true"},
stdout: `--loglevel 20 container exec __child test --bind /tmp /bin/true`,
stdout: `--loglevel 20 container exec __child test --bind /tmp -- /bin/true`,
},
{
name: "test with --node",
args: []string{"test", "--node", "node1", "/bin/true"},
stdout: `--loglevel 20 container exec __child test --node node1 /bin/true`,
stdout: `--loglevel 20 container exec __child test --node node1 -- /bin/true`,
},
{
name: "test with --node and --bind",
args: []string{"test", "--bind", "/tmp", "--node", "node1", "/bin/true"},
stdout: `--loglevel 20 container exec __child test --bind /tmp --node node1 /bin/true`,
stdout: `--loglevel 20 container exec __child test --bind /tmp --node node1 -- /bin/true`,
},
{
name: "test with complex command",
args: []string{"test", "/bin/bash", "echo 'hello'"},
stdout: `--loglevel 20 container exec __child test /bin/bash echo 'hello'`,
stdout: `--loglevel 20 container exec __child test -- /bin/bash echo 'hello'`,
},
}