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.19k stars 351 forks source link

Component chart values are not evaluated as expressions #1829

Closed dhruvbaldawa closed 2 years ago

dhruvbaldawa commented 2 years ago

Thanks for the fast turnaround time on #1816. This issue is an extension of the same issue

What happened?

deployment:
  - name: api
    helm:
      componentChart: true
      values:
        containers:
          - image: legacy-api
            env: $(populate-env ${API_DIR}/local.env)
        service:
          ports:
            - port: 9000

If I do devspace print, this is the output that I receive

deployment:
  - name: api
    helm:
      componentChart: true
      values:
        containers:
          - image: legacy-api
            env: $(populate-env ${API_DIR}/local.env)
        service:
          ports:
            - port: 9000

I tried devspace deploy but it threw another error

[fatal]  error deploying: error deploying api: Unable to deploy helm chart: error during 'helm upgrade ....': Error: UPGRADE FAILED: cannot patch "api" with kind Deployment: The order in patch list:
[map[name:FOO value:bar] map[name:ENV value:value]]
 doesn't match $setElementOrder list:
[map[name:FOO] map[name:ENV]]

What did you expect to happen instead?
The output I expect is:

deployment:
  - name: api
    helm:
      componentChart: true
      values:
        containers:
          - image: legacy-api
            env:
             - name: FOO
               value: bar
            - name: ENV
              value: value
        service:
          ports:
            - port: 9000

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

Add an expression on the env for component chart on devspace 5.18.0, and run devspace print

env: '$(echo [{"name": "ENV", "value": "foo"}, "name": "NAMESPACE", "value": "${DEVSPACE_NAMESPACE}"}])'

The output for devspace print should look like

env:
    - name: ENV
      value: foo
    - name: NAMESPACE
      value: mynamespace

Local Environment:

/kind bug

FabianKramm commented 2 years ago

@dhruvbaldawa thanks for the issue! This is expected behaviour now as DevSpace will resolve certain config paths later on during actual deployment to be able to resolve runtime variables. We could think about making an exception for devspace print. In your case the problem seems to be that you are returning a map from the config expression, but an array is expected.

dhruvbaldawa commented 2 years ago

@FabianKramm I am returning an array from the config expression, the same .env file with v5.17.0 is rendering as expected and also deploying correctly. I have checked the command's output independently to also validate that. I purged the deployment and tried again and it is deploying correctly now.

However, my file is structured in this way

- name: API_SERVICE_URL
  value: http://api.${DEV_NAMESPACE}.svc.cluster.local

and this would render as expected previously where value would render like http://api.mynamespace.svc.cluster.local but it does not happen anymore. I have changed the variable to {devspace.namespace} but it is still not working. Can you please help fix this too?

FabianKramm commented 2 years ago

@dhruvbaldawa yes you are right, that is not working correctly, we'll fix that for the next release

sandrotaje commented 2 years ago

@dhruvbaldawa thanks for the issue! This is expected behaviour now as DevSpace will resolve certain config paths later on during actual deployment to be able to resolve runtime variables. We could think about making an exception for devspace print. In your case the problem seems to be that you are returning a map from the config expression, but an array is expected.

@FabianKramm It seems it still doesn't work on devspace print command. Every variable inside the helm values is not substituted. Is this an expected behavior?