eclipse-che / che

Kubernetes based Cloud Development Environments for Enterprise Teams
http://eclipse.org/che
Eclipse Public License 2.0
6.99k stars 1.19k forks source link

Add an ability to expose K8s/OS tool container port in Workspace Runtime #12808

Closed vitaliy-guliy closed 5 years ago

vitaliy-guliy commented 5 years ago

Show motivation description

With Workspace Config, there is an ability to define that Container exposed some port (with server config entry in machine configuration) and then it is possible to get publicly available URL (powered by Ingress/Route) via Che Server API (it's Workspace#Runtime#Machines[n]#Servers). And there are two main reasons why users may want to expose their containers ports with Che Server API:

  1. Theia provides UI to get these servers URLs for a user for further using, like their server testing.
  2. Theia itself may need to pick up such exposed port. See Detailed use-case description.

Detailed Theia Dev Use case description

In my use case I need a workspace with Theia editor and two custom containers which I use to launch another instance of Theia and remote plugin. This two containers must have exposed ports. One is for Theia http server, another one is for remote plugin which opens a websocket server. Theia has to know URI to the plugin server which is taken from workspace runtime.

In the Dockerfile I use kubernetes tool to describe custom containers. For those containers I need to describe exposes ports 3030 and 10000. Here are my files from which I create my workspace.

.devfile

specVersion: 0.0.1
name: develop-remote-plugins
projects:
  - name: theia
    source:
      type: git
      location: 'https://github.com/theia-ide/theia.git'
  - name: sample-remote-plugin
    source:
      type: git
      location: 'https://github.com/vitaliy-guliy/sample-remote-plugin.git'
tools:
  - name: theia-editor
    type: cheEditor
    id: org.eclipse.che.editor.theia:1.0.0
  - name: exec-plugin
    type: chePlugin
    id: che-machine-exec-plugin:0.0.1
  - name: dev
    type: kubernetes
    local: dev.yaml
commands:
  - name: build-plugin
    actions:
      - type: exec
        tool: dev-plugin
        command: cd /projects/sample-remote-plugin && yarn
        workdir: /projects/sample-remote-plugin
  - name: build-theia
    actions:
      - type: exec
        tool: dev
        command: cd /projects/theia && yarn
        workdir: /projects/theia

dev.yaml

---
apiVersion: v1
kind: List
items:
- apiVersion: v1
  kind: Pod
  metadata:
    name: ws
  spec:
    containers:
    - name: dev
      image: eclipse/che-theia-dev:nightly
      resources:
        limits:
          memory: 2048Mi
      volumeMounts:
      - mountPath: /projects
        name: projects
    - name: dev-plugin
      image: eclipse/che-theia-dev:nightly
      resources:
        limits:
          memory: 2048Mi
      volumeMounts:
      - mountPath: /projects
        name: projects
    volumes:
    - name: projects
      persistentVolumeClaim:
        claimName: projects
- apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: projects
  spec:
    accessModes:
     - ReadWriteOnce
    resources:
      requests:
        storage: 2Gi
sleshchenko commented 5 years ago

@vitaliy-guliy Actually, you already are able to expose containers ports with dockerimage tool type. See https://redhat-developer.github.io/devfile/#tools endpoint field. And then Workspace API will have information about exposed endpoint as a server of the machine in runtime.

But if you need multiple containers, then (for time being) you have to use kubernetes/openshift tool where it is possible. And in this case, you are able to define Kubernetes Services/Ingresses, OpenShift Routes for exposing your containers ports BUT Workspace API server won't expose URLs for such objects. Here is an issue for exposing URLs of such objects https://github.com/eclipse/che/issues/12268.

Anyway, it would be useful to see an example of your use case in the issue description.

vitaliy-guliy commented 5 years ago

Also I include a JSON template to create a Factory which covers my case

{
  "v": "4.0",
  "name": "remote_plugin_developer",
  "workspace": {
    "defaultEnv": "default",
    "environments": {
      "default": {
        "machines": {
          "ws/dev-plugin": {
            "attributes": {
              "memoryLimitBytes": "2684354560"
            },
            "servers": {
              "PluginDev": {
                "attributes": {},
                "port": "10000",
                "protocol": "ws"
              }
            },
            "volumes": {
              "projects": {
                "path": "/projects"
              }
            },
            "installers": [],
            "env": {}
          },
          "ws/dev": {
            "attributes": {
              "memoryLimitBytes": "2684354560"
            },
            "servers": {
              "TheiaDev": {
                "attributes": {},
                "port": "3030",
                "protocol": "http"
              }
            },
            "volumes": {
              "projects": {
                "path": "/projects"
              }
            },
            "installers": [],
            "env": {}
          }
        },
        "recipe": {
          "type": "kubernetes",
          "content": "kind: List\nitems:\n - \n  apiVersion: v1\n  kind: Pod\n  metadata:\n   name: ws\n  spec:\n   containers:\n    - \n     image: 'eclipse/che-theia-dev:nightly'\n     name: dev\n     resources:\n      limits:\n       memory: 3072Mi\n    - \n     image: 'eclipse/che-theia-dev:nightly'\n     name: dev-plugin\n     resources:\n      limits:\n       memory: 2560Mi\n",
          "contentType": "application/x-yaml"
        }
      }
    },
    "projects": [
      {
        "links": [],
        "name": "theia",
        "attributes": {},
        "type": "blank",
        "source": {
          "location": "https://github.com/theia-ide/theia.git",
          "type": "git",
          "parameters": {}
        },
        "path": "/theia",
        "description": "",
        "mixins": [],
        "problems": []
      }
    ],
    "name": "remote_plugin_developer",
    "attributes": {
      "editor": "org.eclipse.che.editor.theia:1.0.0",
      "plugins": "che-machine-exec-plugin:0.0.1"
    },
    "commands": [],
    "links": []
  }
}
sunix commented 5 years ago

@vitaliy-guliy could we close it ? as we managed to do it with https://github.com/sunix/devfiles/blob/e4dc471ed71b2f488a98b304ff49117e4304c2ac/che-in-che/che-theia-remote.devfile.yaml ?

sleshchenko commented 5 years ago

@sunix Thanks for sharing a way how you solved this issue with dockerimage tool. I think it makes sense to keep this issue opened since there is no way to make Che Server expose k8s/os tool's container port. I do not know how critical it is, but still, such an issue exists.

sunix commented 5 years ago

OK so maybe rename this issue to be more precise of what is not working :) or create a new issue ? WDYT ?

sleshchenko commented 5 years ago

@sunix I'll modify the current issue.

sleshchenko commented 5 years ago

Issue description is updated. Hope everything is clear enough. Everybody - feel free to modify issue description or ask me missing details.

sunix commented 5 years ago

Thanks @sleshchenko i am not sure to understand the via Che API.

sleshchenko commented 5 years ago

@sunix Here I mean propagating server URL via Workspace API, like we do with Theia (or any other servers) URL Screenshot_20190319_133725

sunix commented 5 years ago

@sleshchenko via Che API -> in Che workspace config or just remove via Che API WDYT ?

che-bot commented 5 years ago

Issues go stale after 180 days of inactivity. lifecycle/stale issues rot after an additional 7 days of inactivity and eventually close.

Mark the issue as fresh with /remove-lifecycle stale in a new comment.

If this issue is safe to close now please do so.

Moderators: Add lifecycle/frozen label to avoid stale mode.

vitaliy-guliy commented 5 years ago

Outdated