skip to Main Content

I found that creating a yaml object description using --dry-run=client and providing --command only works when the provided arguments are in a very specific order.

This works:

k run nginx --image=nginx --restart=Never --dry-run=client -o yaml --command -- env > nginx.yaml

This does NOT:

k run nginx --image=nginx --restart=Never --command -- env --dry-run=client -o yaml > nginx.yaml

I feel a bit confused because the version that does not work looks a lot more intuitive to me then the one that does work. Ideally both should work in my opinion. Is this intended behavior? I can’t find any documentation about it.

2

Answers


  1. Everything after -- is a positional argument (until the > which is a shell metachar), not an option.

    Login or Signup to reply.
  2. Ideally both should work in my opinion.

    Unfortunately, the commands you presented are not the same. They will never work the same either. This is correct behaviour. Double dash (--) is of special importance here:

    a double dash (--) is used in most Bash built-in commands and many other commands to signify the end of command options, after which only positional arguments are accepted.

    So you can’t freely swap "parameters" places. Only these options can be freely set

    --image=nginx --restart=Never --dry-run=client -o yaml --command
    

    Then you have -- env (double dash, space, and another command). After -- (double dash and space) only positional arguments are accepted.

    Additionally, > is shell meta-character to set redirection.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search