How to write command for Kubernetes pod with flag and parameter on same line?

Hi :wave:

I have this configuration working for a Kubernetes/OpenShift cronjob/pod:

spec:
  containers:
  - name: activate-trigger
    image: curlimages/curl
    command:
      - curl
      - --header
      - "content-Type: application/json"
      - --data
      - '{"name": "Pipeline triggered from curl"}'
      - http://api.endpoint

I would like to combine the flag and it’s associated value on to the same line with something along the lines of:

spec:
  containers:
  - name: activate-trigger
    image: curlimages/curl
    command:
      - curl
      - --header "content-Type: application/json"
      - --data '{"name": "Pipeline triggered from curl"}'
      - http://api.endpoint

But I could not find the right combination of quotes and double quotes to get it working. Is this possible to do in YAML and Kubernetes?

Thank you for your time :pray:

Two things:

  1. Each distinct argument to the command MUST be a distinct entry in the list. Unlike a shell, we do not try to tokenize the argument strings. The quoting rules become far too complicated. So there is no “right combination of quotes and double quotes” to do this.

  2. Many tools allow an = in flags, so you might be able to say:

spec:
  containers:
  - name: activate-trigger
    image: curlimages/curl
    command:
      - curl
      - --header=content-Type: application/json
      - --data={"name": "Pipeline triggered from curl"}
      - http://api.endpoint

Note that the embedded quotes will be preserved. There’s an implied quoting (as long as it tastes like a string, caution), so - --foo="bar" is really - "--foo=\"bar\"". You may want to be explicit and put those outer quotes yourself.

spec:
  containers:
  - name: activate-trigger
    image: curlimages/curl
    command:
      - "curl"
      - "--header=content-Type: application/json"
      - "--data={\"name\": \"Pipeline triggered from curl\"}"
      - "http://api.endpoint"

Thank you for the tips! I’ll give that a try. Thank you also for explaining why the things I’ve tried has been failing. It makes much more sense now. I never knew that that’s what the shell is doing underneath the hood. Thanks again :pray:

Thank you again for the suggestion. Unfortunately, curl does not accept the = in the flag so I guess I’ll try this out another time. Thanks again for your time and help :pray: