garden-io / garden

Automation for Kubernetes development and testing. Spin up production-like environments for development, testing, and CI on demand. Use the same configuration and workflows at every step of the process. Speed up your builds and test runs via shared result caching
https://garden.io
Mozilla Public License 2.0
3.39k stars 274 forks source link

garden exec splits quoted arguments #2957

Closed mattwarenski closed 11 months ago

mattwarenski commented 2 years ago

Bug

Current Behavior

Running garden exec api '/usr/bin/env -v echo "hello world"' gives this output:

executing: echo
   arg[0]= 'echo'
   arg[1]= '"hello'
   arg[2]= 'world"'
"hello world"

In the above example "hello" and "world" are being passed as two separate arguments even though they are quoted.

Expected behavior

Running garden exec api '/usr/bin/env -v echo "hello world"' should match the output of kubectl exec pod -- /usr/bin/env -v echo "hello world"

executing: echo
   arg[0]= 'echo'
   arg[1]= '"hello world"'
"hello world"

In this example "hello world" is passed as a single argument.

Your environment

The examples were generated running on mac os with garden 0.12.40

stefreak commented 1 year ago

I believe we should not split at all, but allow using -- to provide multiple parameters, similar to how kubectl works:

% kubectl exec -it x -- "ls -lah"
OCI runtime exec failed: exec failed: unable to start container process: exec: "ls -lah": executable file not found in $PATH: unknown
command terminated with exit code 126
% kubectl exec -it x -- ls -lah
total 8K
drwxr-xr-x    1 root     root          86 Oct 16 18:17 .
drwxr-xr-x    1 root     root          86 Oct 16 18:17 ..
shumailxyz commented 1 year ago

In Bonsai, this doesn't work with the command arguments at all. So running this will fail altogether:

garden exec <pod-name> ls -la 
garden exec <pod-name> "/bin/sh -c ls"