Skip to content

Extend the DevWorkspaceTemplate spec with containers contributions #656

Closed
@sleshchenko

Description

@sleshchenko

Che Editors (VS Code, Theia, JetBrain IDEs) are defined as DevWorkspaceTemplate. But the DevWorkspaceTemplate syntax currently lacks a way to express the changes required to the containers that will host the editor. In fact Che Editors are injected in user's containers (which one is covered here) and require changes to the original user's container to work properly: add env variables, volumes, mem and cpu requisites, postStart and postStart events etc...

This feature is critical to allow using the same Devfile or DevWorkspace with different editors. But also to unblock some other features as "universal" idling.

This is a subtask of eclipse-che/che#21340

Here is an example of a DevWorkspaceTemplate that defines VS Code with a containerContribution component:

VS Code editor definition:

apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
  name: che-code-editor
spec:
  components:
    - name: che-code-volume
      volume: {}
    - name: che-code-injector
      container:
        image: quay.io/che-incubator/che-code:insiders
        command:
          - /entrypoint-init-container.sh
        volumeMounts:
          - name: che-code-volume
            path: /checode
        memoryLimit: 128Mi
        memoryRequest: 32Mi
        cpuLimit: 500m
        cpuRequest: 30m
    - name: che-code-host
      containerContribution:
          endpoints:
            - name: che-code
              attributes:
                type: main
                cookiesAuthEnabled: true
                discoverable: false
                urlRewriteSupported: true
                contributed-by: che-code.eclipse.org
              targetPort: 3100
              exposure: public
              path: '?tkn=eclipse-che'
              secure: false
              protocol: https
            - name: code-redirect-1
              attributes:
                discoverable: false
                urlRewriteSupported: true
                contributed-by: che-code.eclipse.org
              targetPort: 13131
              exposure: public
              protocol: http
            - name: code-redirect-2
              attributes:
                discoverable: false
                urlRewriteSupported: true
                contributed-by: che-code.eclipse.org
              targetPort: 13132
              exposure: public
              protocol: http
            - name: code-redirect-3
              attributes:
                discoverable: false
                urlRewriteSupported: true
                contributed-by: che-code.eclipse.org
              targetPort: 13133
              exposure: public
              protocol: http
          volumeMounts:
            - name: che-code-volume
              path: /checode
          memoryLimit: 1Gi
          memoryRequest: 128Mi
          cpuLimit: 200m
          cpuRequest: 10m
  commands:
    - id: che-code-init-container-command
      apply:
        component: che-code-injector
    - id: che-code-post-start-command
      exec:
        component: che-code-host
        command: /checode/entrypoint-volume.sh
  events:
    preStart:
      - che-code-init-container-command
    postStart:
      - che-code-post-start-command

And here is a DevWorkspace that references the previous DWT:

apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
  name: nodejs-web-app
spec:
  started: true
  template:
    components:
      - name: tools
        container:
          image: quay.io/devfile/universal-developer-image:ubi8-0e189d9
          endpoints:
            - exposure: public
              name: nodejs
              protocol: http
              targetPort: 3000
          memoryLimit: 1Gi
          mountSources: true
      - name: che-code-volume
        volume: {}
      - name: che-code-injector
        container:
          image: quay.io/che-incubator/che-code:insiders
          command:
            - /entrypoint-init-container.sh
          volumeMounts:
            - name: che-code-volume
              path: /checode
          memoryLimit: 128Mi
          memoryRequest: 32Mi
          cpuLimit: 500m
          cpuRequest: 30m
    commands:
      - id: install-dependencies
        exec:
          label: "Install dependencies"
          component: tools
          workingDir: ${PROJECT_SOURCE}/app
          commandLine: "npm install"
          group:
            kind: build
            isDefault: true
    
      - id: run-application
        exec:
          label: "Run web application"
          component: tools
          workingDir: ${PROJECT_SOURCE}/app
          commandLine: "nodemon app.js"
          group:
            kind: run
    
      - id: debug
        exec:
          label: "Run web application (debugging enabled)"
          component: tools
          workingDir: ${PROJECT_SOURCE}/app
          commandLine: "nodemon --inspect app.js"
          group:
            kind: debug
            isDefault: true
    
      - id: stop-application
        exec:
          label: "Stop web application"
          component: tools
          commandLine: >-
              node_server_pids=$(pgrep -fx '.*nodemon (--inspect )?app.js' | tr "\\n" " ") &&
              echo "Stopping node server with PIDs: ${node_server_pids}" && 
              kill -15 ${node_server_pids} &>/dev/null && echo 'Done.'
          group:
            kind: run

This should be the resulting flattened DevWorkspace:

apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
  name: nodejs-web-app
spec:
  started: true
  template:
    components:
        - name: tools
          container:
            image: quay.io/devfile/universal-developer-image:ubi8-0e189d9
            endpoints:
              - exposure: public
                name: nodejs
                protocol: http
                targetPort: 3000
              ### APPENDED ENDPOINTS ###
              - name: che-code
                attributes:
                  type: main
                  cookiesAuthEnabled: true
                  discoverable: false
                  urlRewriteSupported: true
                  contributed-by: che-code.eclipse.org
                targetPort: 3100
                exposure: public
                path: '?tkn=eclipse-che'
                secure: false
                protocol: https
              - name: code-redirect-1
                attributes:
                  discoverable: false
                  urlRewriteSupported: true
                  contributed-by: che-code.eclipse.org
                targetPort: 13131
                exposure: public
                protocol: http
              - name: code-redirect-2
                attributes:
                  discoverable: false
                  urlRewriteSupported: true
                  contributed-by: che-code.eclipse.org
                targetPort: 13132
                exposure: public
                protocol: http
              - name: code-redirect-3
                attributes:
                  discoverable: false
                  urlRewriteSupported: true
                  contributed-by: che-code.eclipse.org
                targetPort: 13133
                exposure: public
                protocol: http
            ### NEW VOLUMEMOUNTS ### 
            volumeMounts:
              - name: che-code-volume
                path: /checode
            ### SUMMED memorlyLimit ###
            memoryLimit: 2Gi

            ### APPENDED other resources req/limits ###
            memoryRequest: 128Mi
            cpuLimit: 200m
            cpuRequest: 10m	   

            mountSources: true
        - name: che-code-volume
          volume: {}
        - name: che-code-injector
          container:
            image: quay.io/che-incubator/che-code:insiders
            command:
              - /entrypoint-init-container.sh
            volumeMounts:
              - name: che-code-volume
                path: /checode
            memoryLimit: 128Mi
            memoryRequest: 32Mi
            cpuLimit: 500m
            cpuRequest: 30m
    commands:
      - id: install-dependencies
        exec:
          label: "Install dependencies"
          component: tools
          workingDir: ${PROJECT_SOURCE}/app
          commandLine: "npm install"
          group:
            kind: build
            isDefault: true
    
      - id: run-application
        exec:
          label: "Run web application"
          component: tools
          workingDir: ${PROJECT_SOURCE}/app
          commandLine: "nodemon app.js"
          group:
            kind: run
    
      - id: debug
        exec:
          label: "Run web application (debugging enabled)"
          component: tools
          workingDir: ${PROJECT_SOURCE}/app
          commandLine: "nodemon --inspect app.js"
          group:
            kind: debug
            isDefault: true
    
      - id: stop-application
        exec:
          label: "Stop web application"
          component: tools
          commandLine: >-
              node_server_pids=$(pgrep -fx '.*nodemon (--inspect )?app.js' | tr "\\n" " ") &&
              echo "Stopping node server with PIDs: ${node_server_pids}" && 
              kill -15 ${node_server_pids} &>/dev/null && echo 'Done.'
          group:
            kind: run

      - id: che-code-init-container-command
        apply:
          component: che-code-injector
      - id: che-code-post-start-command
        exec:
          component: che-code-host
          command: /checode/entrypoint-volume.sh
  events:
    preStart:
      - che-code-init-container-command
    postStart:
      - che-code-post-start-command
  • containerContribution env, endpoints and volumeMounts are appended to user DevWorkspace
  • containerContribution resources limits and request are summed up
  • containerContribution commands should not be allowed

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions