Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the DevWorkspaceTemplate spec with containers contributions #656

Closed
sleshchenko opened this issue Oct 21, 2021 · 1 comment · Fixed by #844
Closed

Extend the DevWorkspaceTemplate spec with containers contributions #656

sleshchenko opened this issue Oct 21, 2021 · 1 comment · Fixed by #844
Assignees
Milestone

Comments

@sleshchenko
Copy link
Member

sleshchenko commented Oct 21, 2021

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
@sleshchenko sleshchenko added sprint/current Is assigned to issues which are planned to work on in the current team sprint and removed sprint/next labels Oct 28, 2021
@amisevsk amisevsk added sprint/next and removed sprint/current Is assigned to issues which are planned to work on in the current team sprint labels Nov 5, 2021
@ibuziuk ibuziuk added sprint/current Is assigned to issues which are planned to work on in the current team sprint and removed sprint/next labels Nov 10, 2021
@ibuziuk ibuziuk changed the title Investigate an ability to inject stuff(volume, env var, postStart command) into user's container [SPIKE] Investigate an ability to inject stuff(volume, env var, postStart command) into user's container Nov 10, 2021
@max-cx
Copy link

max-cx commented Nov 15, 2021

Hi, a question to the assignee of this issue:

Will the outcome require any changes to the relevant content of the Installation Guide or Administration Guide or End-user Guide?

Yes/No?

@amisevsk amisevsk self-assigned this Nov 22, 2021
@amisevsk amisevsk removed their assignment Feb 1, 2022
@ibuziuk ibuziuk added sprint/next and removed sprint/current Is assigned to issues which are planned to work on in the current team sprint labels Feb 8, 2022
@l0rd l0rd changed the title [SPIKE] Investigate an ability to inject stuff(volume, env var, postStart command) into user's container Support containerContribution component type to inject stuff(volume, env var, postStart command) into user's container Feb 20, 2022
@l0rd l0rd changed the title Support containerContribution component type to inject stuff(volume, env var, postStart command) into user's container Extend the DevWorkspace spec with containers contributions Apr 27, 2022
@l0rd l0rd changed the title Extend the DevWorkspace spec with containers contributions Extend the DevWorkspaceTemplate spec with containers contributions Apr 27, 2022
@ibuziuk ibuziuk mentioned this issue May 18, 2022
49 tasks
@amisevsk amisevsk self-assigned this May 30, 2022
@ibuziuk ibuziuk mentioned this issue Jun 2, 2022
64 tasks
@ibuziuk ibuziuk mentioned this issue Jun 27, 2022
68 tasks
@ibuziuk ibuziuk mentioned this issue Jul 19, 2022
51 tasks
@ibuziuk ibuziuk mentioned this issue Aug 9, 2022
67 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants