devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.22k stars 353 forks source link

Running commands fails if question variable is set and used #2266

Closed MathiasVandePol closed 1 year ago

MathiasVandePol commented 1 year ago

image

I have a var set

  ANIMAL:
    question: Which type of animal are you
    options:
      - "cat"
      - "dog"

and a profile (this is optional, also fails without)

profiles:

  - name: no-humans
    activation:
      - vars:
          ANIMAL:"cat"

When running a command ex: devspace run 'somecommand' it will try to use the question variable which fails as commands are not being run in a terminal

What happened?

Commands stop execution with Cannot ask question

What did you expect to happen instead?

Ideally, there should be an option to ignore variables when a command is executed. For example. I use commands to seed some data in the database for which only db connection string vars are required. The rest I should not need.

How can we reproduce the bug? (as minimally and precisely as possible)

My devspace.yaml:

version: v2beta1

vars:
  ANIMAL:
    question: Which type of animal are you
    options:
      - "cat"
      - "dog"

commands:
  "test-command":
      command: "echo 'hi'"

profiles:
  - name: no-humans
    activation:
      - vars:
          ANIMAL:"cat"

Local Environment:

Anything else we need to know?

/kind bug

FabianKramm commented 1 year ago

@MathiasVandePol thanks for creating this issue! We'll take a look and fix the issue!

pratikjagrut commented 1 year ago

Hi @MathiasVandePol You can use the following option to skip the question:

vars:
  ANIMAL:
    alwaysResolve: false
    question: Which type of animal are you
    options:
      - "cat"
      - "dog"

But as long as you use this variable in activation the question will be asked.

You could also use the default option to skip questions:

version: v2beta1
name: test

vars:
  ANIMAL:
    question: Which type of animal are you
    default: cat
    options:
      - "cat"
      - "dog"

commands:
  test-command:
    command: "echo 'hi'"

Note: If you use DevSpace, not in a Terminal e.g. echo 123 | devspace run test-command, the default value should be used, if no default is defined then it should print an error. But currently, this scenario is not working. We're working on a fix.