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.38k stars 361 forks source link

Variables in variables are not resolved correctly #2219

Closed dhruvbaldawa closed 2 years ago

dhruvbaldawa commented 2 years ago

What happened?

In Devspace v6, variables within variables are not resolved correctly.

What did you expect to happen instead?

I expect the variables to be resolved correctly and get their proper value. Equivalent devspace.yaml file in v5 worked perfectly fine

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

export ENV_VAR=foo

My devspace.yaml:

version: v2beta1
name: ssh
deployments:
  ssh:
    helm:
      chart:
        name: component-chart
        repo: https://charts.devspace.sh
      values:
        containers:
          - image: ubuntu
            command:
              - /usr/bin/sleep
            args:
              - infinity
       labels:
         mylabel: "${MY_VAR}" 
dev:
  ssh:
    imageSelector: ubuntu
    ssh: {}
vars:
    MY_VAR: "${ENV_VAR}/bar"

in v5, this renders as

mylabel: foo/bar

in v6, this renders as

mylabel: ${ENV_VAR}/bar

Local Environment:

Anything else we need to know?

/kind bug

FabianKramm commented 2 years ago

@dhruvbaldawa thanks for creating this issue! This is actually behaving as intended as you either need to use an inline bash variable here or define the ENV_VAR in the devspace.yaml:

vars:
  ENV_VAR:
    source: env
  MY_VAR: "${ENV_VAR}/bar"

Or:

vars:
  MY_VAR: "$( echo $ENV_VAR/bar )"
dhruvbaldawa commented 2 years ago

@FabianKramm Yes, I am using the bash commands right now.

I am trying to understand how to deal with this kind of scenario best.

PROJECT_DIR: "${HOME}/projects"
APP_DIR: "${PROJECT_DIR}/app"
APP_CONF_DIR: "${APP_DIR}/conf"

What approach would you recommend? Should I just have them all as environment variables?

FabianKramm commented 2 years ago

@dhruvbaldawa I see, yes I would use this:

HOME:
  source: env
PROJECT_DIR: "${HOME}/projects"
APP_DIR: "${PROJECT_DIR}/app"
APP_CONF_DIR: "${APP_DIR}/conf"