devfile / devworkspace-operator

Apache License 2.0
67 stars 55 forks source link

fix: Ensure $PROJECT_SOURCE and $PROJECT_ROOT are first environment variables in workspace containers #1282

Closed AObuchow closed 4 months ago

AObuchow commented 4 months ago

What does this PR do?

Environment variables defined in a Kubernetes container can only reference other variables declared earlier in the list of container environment variables. See the second note from the Kubernetes docs on environment variables.

This change ensures that the $PROJECT_SOURCE and $PROJECT_ROOT devfile environment variables are the first environment variables defined in all workspace pod containers so that devfile environment variables can reference $PROJECT_SOURCE and $PROJECT_ROOT.

Instead of appending $PROJECT_SOURCE and $PROJECT_ROOT to all workspace containers, we are now prepending them.

Additionally, existing tests were modified to accommodate this change in the list of container environment variables ordering, and a new test was added for this change.

What issues does this PR fix or reference?

https://github.com/devfile/devworkspace-operator/issues/1274

Is it tested? How?

  1. Install DWO with the changes made from this PR. I've pushed to quay.io/aobuchow/devworkspace-controller:project-source-first for ease of testing.
  2. Apply the following devworkspace:
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
  name: plain-devworkspace-env-test
spec:
  started: true
  routingClass: 'basic'
  template:
    projects:
      - name: web-nodejs-sample
        git:
          remotes:
            origin: "https://github.com/che-samples/web-nodejs-sample.git"
    components:
      - name: web-terminal
        container:
          image: quay.io/wto/web-terminal-tooling:next
          memoryRequest: 256Mi
          memoryLimit: 512Mi
          mountSources: true
          command:
           - "tail"
           - "-f"
           - "/dev/null"
          env:
           - name: ENV_TEST
             value: $(PROJECT_SOURCE)/hey-there
  1. Once the workspace starts up, exec into the workspace pod and run echo $ENV_TEST. The output should be /projects/web-nodejs-sample/hey-there -- in other words, $(PROJECT_SOURCE) will get evaluated to /projects/web-nodejs-sample/.

PR Checklist

openshift-ci[bot] commented 4 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AObuchow, dkwon17

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/devfile/devworkspace-operator/blob/main/OWNERS)~~ [AObuchow,dkwon17] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
AObuchow commented 4 months ago

For some reason, the GH Actions aren't running. Will try and do a no-op commit to get it to run, then remove the no-op commit.

openshift-ci[bot] commented 4 months ago

New changes are detected. LGTM label has been removed.

AObuchow commented 4 months ago

/retest

AObuchow commented 4 months ago

/retest

AObuchow commented 4 months ago

/retest

AObuchow commented 4 months ago

/retest