Skip to content

Command line arguments are process differently for HostProcess containers and Windows Server containers #1199

@marosset

Description

@marosset

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": windows

I 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": windows

and 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions