-
Notifications
You must be signed in to change notification settings - Fork 275
Description
Command line arguments are processed differently for HostProcess containers and Windows Server containers.
This makes it difficult to develop / test /deploy workingloads in HostProcess containers on Windows.
I wrote a small program that dumps the command line arguments pass to the program
package main
import (
"fmt"
"os"
)
func main() {
fmt.Printf("Raw command line: %v", os.Args)
fmt.Println()
}When I deployed the follow pod to a Kubernetes cluster
apiVersion: v1
kind: Pod
metadata:
name: print-cmd-args
spec:
containers:
- name: container
image: mrosse3/print-cmd-args
imagePullPolicy: Always
command:
- "print-cmd-args.exe"
- "arg"
- "arg with spaces"
- 'arg with single quotes'
- --cobra-style-command=foobar
- --another-cobra-command="foobar"
- --cobra-with-space="hello world"
restartPolicy: Never
nodeSelector:
"kubernetes.io/os": windowsI see the following output
kubectl logs print-cmd-args
Raw command line: [print-cmd-args.exe arg arg with spaces
arg with single quotes --cobra-style-command=foobar
--another-cobra-command="foobar" --cobra-with-space="hello world"]I then tried to deploy the same container as a HostProcess container
apiVersion: v1
kind: Pod
metadata:
name: print-cmd-args-host-process
spec:
securityContext:
windowsOptions:
hostProcess: true
runAsUserName: "NT AUTHORITY\\SYSTEM"
hostNetwork: true
containers:
- name: container
image: mrosse3/print-cmd-args
imagePullPolicy: Always
command:
- "print-cmd-args.exe"
- "arg"
- "arg with spaces"
- 'arg with single quotes'
- \"espaced quotes\"
- --cobra-style-command=foobar
- --another-cobra-command="foobar"
- --cobra-with-space="hello world"
restartPolicy: Never
nodeSelector:
"kubernetes.io/os": windowsand see this different output
kubectl logs print-cmd-args-host-process
Raw command line: [print-cmd-args.exe arg "arg with spaces"
"arg with single quotes" --cobra-style-command=foobar
--another-cobra-command=\ "foobar\" "--cobra-with-space=\" hello world\ ""]Additionally - many workloads in the Kubernetes/CNCF ecosystem use https://github.com/spf13/cobra to parse command lines.
Adding quotes around the string (like how --cobra-with-space="hello world" goes to "--cobra-with-space=\" hello world\ "" for HostProcess containers breaks the processing logic for these workloads.