Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

chore:add default dev container component #736

Merged
merged 1 commit into from
Apr 20, 2023
Merged

chore:add default dev container component #736

merged 1 commit into from
Apr 20, 2023

Conversation

svor
Copy link
Contributor

@svor svor commented Apr 17, 2023

What does this PR do?

This PR provides an ability to inject a default dev container component into the DevWorkspace. For this, two additional parameters were added:

--injectDefaultComponent: inject a default dev container component if no component is defined in the devfile and it doesn't provide a parent, the value can be true or false, default is false

--defaultComponentImage: image to use for the dev container component that will be injected if injectDefaultComponent is true, default is quay.io/devfile/universal-developer-image:ubi8-latest

The resulted DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
  name: che-code-empty
spec:
  commands:
    - id: init-container-command
      apply:
        component: che-code-injector
    - id: init-che-code-command
      exec:
        component: che-code-runtime-description
        commandLine: >-
          nohup /checode/entrypoint-volume.sh > /checode/entrypoint-logs.txt
          2>&1 &
  events:
    preStart:
      - init-container-command
    postStart:
      - init-che-code-command
  components:
    - name: che-code-runtime-description
      container:
        image: >-
          quay.io/devfile/universal-developer-image@sha256:73d38afb1c7ce012d4c5f3b0c25894d2e70ae876effee6382e869d40d6ed468e
        volumeMounts:
          - name: checode
            path: /checode
        memoryLimit: 1024Mi
        memoryRequest: 256Mi
        cpuLimit: 500m
        cpuRequest: 30m
        endpoints:
          - name: che-code
            attributes:
              type: main
              cookiesAuthEnabled: true
              discoverable: false
              urlRewriteSupported: true
            targetPort: 3100
            exposure: public
            secure: false
            protocol: https
          - name: code-redirect-1
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13131
            exposure: public
            protocol: http
          - name: code-redirect-2
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13132
            exposure: public
            protocol: http
          - name: code-redirect-3
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13133
            exposure: public
            protocol: http
      attributes:
        app.kubernetes.io/component: che-code-runtime
        app.kubernetes.io/part-of: che-code.eclipse.org
        controller.devfile.io/container-contribution: true
    - name: checode
      volume: {}
    - name: che-code-injector
      container:
        image: >-
          quay.io/che-incubator/che-code@sha256:8fd9eca7c28c59ce93c0b24c7ff0f38080e9a2ac66668274aeabc6b8f3144012
        command:
          - /entrypoint-init-container.sh
        volumeMounts:
          - name: checode
            path: /checode
        memoryLimit: 256Mi
        memoryRequest: 32Mi
        cpuLimit: 500m
        cpuRequest: 30m
---
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
  name: empty
spec:
  started: true
  routingClass: che
  template:
    components:
      - name: dev
        container:
          image: quay.io/devfile/universal-developer-image:ubi8-latest
        attributes:
          controller.devfile.io/merge-contribution: true
  contributions:
    - name: editor
      kubernetes:
        name: che-code-empty

Screenshot/screencast of this PR

frame_safari_light

What issues does this PR fix or reference?

eclipse-che/che#22082

How to test this PR?

Try to generate a DevWorkspace using this devfile.yaml:

schemaVersion: 2.1.0
metadata:
  name: empty

For this:

  • build che-devfile-registry/tools/devworkspace-generator by eecuting yarn
  • create devfile folder in che-devfile-registry/tools/devworkspace-generator
  • put devfile.yaml into che-devfile-registry/tools/devworkspace-generator folder
  • execute a command that will generate a DevWorkspace:
node lib/entrypoint.js \
        --devfile-path:./devfile/devfile.yaml \
        --plugin-registry-url:https://che-plugin-registry-main.surge.sh/v3/ \
        --editor-entry:che-incubator/che-code/latest \
        --output-file:/tmp/all-in-one.yaml \
        --injectDefaultComponent:true \
        --defaultComponentImage:quay.io/devfile/universal-developer-image:latest
The resulted file is
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspaceTemplate
metadata:
  name: che-code-empty
spec:
  commands:
    - id: init-container-command
      apply:
        component: che-code-injector
    - id: init-che-code-command
      exec:
        component: che-code-runtime-description
        commandLine: >-
          nohup /checode/entrypoint-volume.sh > /checode/entrypoint-logs.txt
          2>&1 &
  events:
    preStart:
      - init-container-command
    postStart:
      - init-che-code-command
  components:
    - name: che-code-runtime-description
      container:
        image: >-
          quay.io/devfile/universal-developer-image@sha256:73d38afb1c7ce012d4c5f3b0c25894d2e70ae876effee6382e869d40d6ed468e
        volumeMounts:
          - name: checode
            path: /checode
        memoryLimit: 1024Mi
        memoryRequest: 256Mi
        cpuLimit: 500m
        cpuRequest: 30m
        endpoints:
          - name: che-code
            attributes:
              type: main
              cookiesAuthEnabled: true
              discoverable: false
              urlRewriteSupported: true
            targetPort: 3100
            exposure: public
            secure: false
            protocol: https
          - name: code-redirect-1
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13131
            exposure: public
            protocol: http
          - name: code-redirect-2
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13132
            exposure: public
            protocol: http
          - name: code-redirect-3
            attributes:
              discoverable: false
              urlRewriteSupported: false
            targetPort: 13133
            exposure: public
            protocol: http
      attributes:
        app.kubernetes.io/component: che-code-runtime
        app.kubernetes.io/part-of: che-code.eclipse.org
        controller.devfile.io/container-contribution: true
    - name: checode
      volume: {}
    - name: che-code-injector
      container:
        image: >-
          quay.io/che-incubator/che-code@sha256:8fd9eca7c28c59ce93c0b24c7ff0f38080e9a2ac66668274aeabc6b8f3144012
        command:
          - /entrypoint-init-container.sh
        volumeMounts:
          - name: checode
            path: /checode
        memoryLimit: 256Mi
        memoryRequest: 32Mi
        cpuLimit: 500m
        cpuRequest: 30m
---
apiVersion: workspace.devfile.io/v1alpha2
kind: DevWorkspace
metadata:
  name: empty
spec:
  started: true
  routingClass: che
  template:
    components:
      - name: dev
        container:
          image: quay.io/devfile/universal-developer-image:latest
        attributes:
          controller.devfile.io/merge-contribution: true
  contributions:
    - name: editor
      kubernetes:
        name: che-code-empty

Now you can create a workspace via
oc apply -f /tmp/all-in-one.yaml

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

@svor svor self-assigned this Apr 17, 2023
@github-actions
Copy link

Click here to review and test in web IDE: Contribute

Copy link
Member

@ibuziuk ibuziuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few importnant things to consider:

  • if the devfile has the parent reference no default compoment should be injected, similar issue has been addressed on the user dashboard end - When a devfile references a parent we should not add the default component che#22103
  • my understanding is that on the lib end we are going to hardcode quay.io/devfile/universal-developer-image:latest, however on CR level it is possible to define the default component which would be applied by the dashboard e.g.
    devEnvironments:
      defaultComponents:
        - container:
            image: 'quay.io/devfile/universal-developer-image:ubi8-38da5c2'
            sourceMapping: /projects
          name: universal-developer-image

I'm afraid that if we merge this PR, this functionality will be broken, the library will always inject the hardcoded default component

@ibuziuk
Copy link
Member

ibuziuk commented Apr 18, 2023

My understanding is that the feature with default component injection is going to be introduced for API tests usage. I would propose adding some flag on the lib end that would allow to opt-in for the default component injection that would emulate the UD behavior that will be used by API tests. On the UD end we will be using the lib without the flag and inject default component based on the CR property. @l0rd wdyt?

@ibuziuk ibuziuk requested a review from l0rd April 18, 2023 09:37
@l0rd
Copy link
Contributor

l0rd commented Apr 18, 2023

I agree. It's important to allow specifying the default component image name.

@svor
Copy link
Contributor Author

svor commented Apr 18, 2023

We can add --injectDefaultComponent: [true/false] as an optional parameter to the generator tool.

The command to generate a DW will be like:

node lib/entrypoint.js \
        --injectDefaultComponent:true \
        --devfile-url:https://github.com/che-samples/java-spring-petclinic/tree/main \
        --plugin-registry-url:https://che-plugin-registry-main.surge.sh/v3/ \
        --editor-entry:che-incubator/che-code/latest \
        --output-file:/tmp/devworkspace-che-code-latest.yaml`

The default value will be false, in this case the generator tool won't add a container component with UDI.

@ibuziuk @l0rd WDYT?

@ibuziuk
Copy link
Member

ibuziuk commented Apr 18, 2023

The default value will be false, in this case the generator tool won't add a container component with UDI.

@svor sounds good 👍

@l0rd
Copy link
Contributor

l0rd commented Apr 18, 2023

Yes and also adding a new flag --defaultComponentImage: <image-name>. If not specified the default value is quay.io/devfile/universal-developer-image:latest.

@svor svor marked this pull request as draft April 18, 2023 13:53
If devfile doesn't provide any component and doesn't have parent, the generator can inject a default one with name 'dev' and image that could be defined

Signed-off-by: Valerii Svydenko <vsvydenk@redhat.com>
@svor svor force-pushed the sv-add-devComponent branch from a48ad9f to 0f72cca Compare April 19, 2023 09:48
@svor svor marked this pull request as ready for review April 19, 2023 09:48
@svor
Copy link
Contributor Author

svor commented Apr 19, 2023

The codebase and the description were updated, it's ready for review
cc @ibuziuk @l0rd @olexii4 @musienko-maxim

@svor svor merged commit 58f79fb into main Apr 20, 2023
@svor svor deleted the sv-add-devComponent branch April 20, 2023 11:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants