devfile / devworkspace-operator

Apache License 2.0
61 stars 55 forks source link

$PROJECT_SOURCE incorrectly set if starterProjects are used #1189

Closed AObuchow closed 11 months ago

AObuchow commented 11 months ago

Description

If a devworkspace has a selected starter project, but no regular projects, the $PROJECT_SOURCE environment variable will be set to /projects, instead of /projects/<selected-starterProject-name>.

Currently, the list of projects that we search when determining what $PROJECT_SOURCE should be set to only contains regular projects, and not starterProjects.

How To Reproduce

Steps to reproduce the behavior:

  1. Apply the following devworkspace:
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
  name: plain-starter-projects
spec:
  started: true
  routingClass: 'basic'
  template:
    attributes:
      controller.devfile.io/use-starter-project: community
    starterProjects:
    - name: community
      zip:
        location: https://code.quarkus.io/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-micrometer&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift&cn=devfile
    - name: redhat-product
      zip:
        location: https://code.quarkus.redhat.com/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift
    components:
      - name: web-terminal
        container:
          image: quay.io/wto/web-terminal-tooling:next
          memoryRequest: 256Mi
          memoryLimit: 512Mi
          mountSources: true
          command:
           - "tail"
           - "-f"
           - "/dev/null"
  1. Check the workspace pod's spec for the $PROJECT_SOURCE environment variable in the web-terminal container.
spec:
(...)
  containers:
    - name: web-terminal
      env:
        - name: PROJECTS_ROOT
          value: /projects
        - name: PROJECT_SOURCE
          value: /projects
(...)

Expected behavior

$PROJECT_SOURCE should be set to the selected starterProject (in this case, community). In this case, $PROJECT_SOURCE should be /projects/community.

If our devworkspace had a regular project, I would expect it to take precedence over any starterProjects as well. E.g. the following devworkspace would have $PROJECT_SOURCE set to /projects/web-nodejs-sample:

kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
  name: plain-starter-projects
spec:
  started: true
  routingClass: 'basic'
  template:
    attributes:
      controller.devfile.io/use-starter-project: community
    starterProjects:
    - name: community
      zip:
        location: https://code.quarkus.io/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-micrometer&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift&cn=devfile
    - name: redhat-product
      zip:
        location: https://code.quarkus.redhat.com/d?e=io.quarkus%3Aquarkus-resteasy&e=io.quarkus%3Aquarkus-smallrye-health&e=io.quarkus%3Aquarkus-openshift
    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"

Additional context

Related Che issue