Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional command line flags #13991

Open
pvanderlinden opened this issue Dec 12, 2024 · 4 comments
Open

Optional command line flags #13991

pvanderlinden opened this issue Dec 12, 2024 · 4 comments
Labels
type/feature Feature request

Comments

@pvanderlinden
Copy link

Summary

When passing arguments to the image commands, it's currently not possible to pass optional flags, depending on parameters.

Use Cases

A lot of command line tools use these flags. The simplest example is ls, if you want certain flags (like -l or -a) to only be used when a certain template parameter is set, this is currently not possible besides using the complicated feature podSpecPatch.

Example which doesn't work, as it will pass two empty arguments to the ls command:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: example-
spec:
  arguments:
    parameters:
      - name: long
        value: false
      - name: all
        value: false

  entrypoint: do-work

  templates:
    - name: do-work
      container:
        image: alpine:3.7
        command: [ls]
        args:
          - "{{workflow.parameters.long == 'true' ? '-l' : '' }}"
          - "{{workflow.parameters.all == 'true' ? '-a' : '' }}"
          - /etc

Message from the maintainers:

Love this feature request? Give it a 👍. We prioritise the proposals with the most 👍.

@pvanderlinden pvanderlinden added the type/feature Feature request label Dec 12, 2024
@pvanderlinden pvanderlinden changed the title Command line flags Optional command line flags Dec 12, 2024
@shuangkun
Copy link
Member

Could this method meet your needs?

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: example-
spec:
  arguments:
    parameters:
      - name: long
        value: false
      - name: all
        value: false

  entrypoint: do-work

  templates:
    - name: do-work
      container:
        image: alpine:3.7
        command: [sh, -c]
        args: ["ls {{=workflow.parameters.long == 'true' ? '-l' : '' }} {{=workflow.parameters.all == 'true' ? '-a' : '' }} /etc"]

@shuangkun
Copy link
Member

All combinations work fine.

13991 % argo submit wf.yaml -p long=false -p all=false
Name:                example-m6c6l
Namespace:           argo
ServiceAccount:      unset (will run with the default ServiceAccount)
Status:              Pending
Created:             Sun Dec 15 15:32:49 +0800 (now)
Progress:
Parameters:
  long:              false
  all:               false
13991 % argo submit wf.yaml -p long=false -p all=true
Name:                example-ttnpr
Namespace:           argo
ServiceAccount:      unset (will run with the default ServiceAccount)
Status:              Pending
Created:             Sun Dec 15 15:33:04 +0800 (now)
Progress:
Parameters:
  long:              false
  all:               true
13991 % argo submit wf.yaml -p long=true -p all=false
Name:                example-h56n4
Namespace:           argo
ServiceAccount:      unset (will run with the default ServiceAccount)
Status:              Pending
Created:             Sun Dec 15 15:33:28 +0800 (now)
Progress:
Parameters:
  long:              true
  all:               false
13991 % argo list
NAME                                                          STATUS      AGE   DURATION   PRIORITY   MESSAGE
example-h56n4                                                 Succeeded   7s    7s         0
example-ttnpr                                                 Succeeded   31s   7s         0
example-m6c6l                                                 Succeeded   46s   7s         0

@pvanderlinden
Copy link
Author

Could this method meet your needs?

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: example-
spec:
  arguments:
    parameters:
      - name: long
        value: false
      - name: all
        value: false

  entrypoint: do-work

  templates:
    - name: do-work
      container:
        image: alpine:3.7
        command: [sh, -c]
        args: ["ls {{=workflow.parameters.long == 'true' ? '-l' : '' }} {{=workflow.parameters.all == 'true' ? '-a' : '' }} /etc"]

This works, but one thing which might not work is shutting down the pod gracefully if kubernetes requests it.

@pvanderlinden
Copy link
Author

As I suspected, this is not working if you need to be able to gracefully shutdown a command. (For whatever reason kubernetes decides to terminate your pod: e.g. memory, etc). Simplified example:

test.py

import signal
import sys
import time

kill_now = False


def exit_gracefully(signum, frame):
    global kill_now
    print("received signal!", file=sys.stderr)
    kill_now = True


signal.signal(signal.SIGINT, exit_gracefully)
signal.signal(signal.SIGTERM, exit_gracefully)


while not kill_now:
    time.sleep(1)
    print("working", file=sys.stderr)

print("bye", file=sys.stderr)
time.sleep(1)

Dockerfile

FROM python
COPY test.py /

worfklow:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: test
spec:
  entrypoint: print-message
  templates:
    - name: print-message
      container:
        image: localhost:5000/testit:latest
        command: [python]
        args: ["test.py"]

If I run the above, then run kubectl delete on the pod, to simulate a forced shutdown. The log looks like the following:

working
working
working
received signal!
working
bye
time="2024-12-16T15:54:00.004Z" level=info msg="sub-process exited" argo=true error="<nil>"

If I change the spec, to use sh -c to run the above. The same results in:

working
working
working
received signal!
time="2024-12-16T15:53:00.520Z" level=info msg="sub-process exited" argo=true error="<nil>"
Error: exit status 143

Which indicate it doesn't allow the command to gracefully shutdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature Feature request
Projects
None yet
Development

No branches or pull requests

2 participants