Multi container devfile bug fix
What does this MR do and why?
Issue: Gitlab Workspaces - API backend locks up with s... (#437887 - closed)
Problem
If a devfile had multiple container components, the volume wasn't getting mounted to each of these containers. This causes problems while generating the Kubernetes resources.
Solution
Refactor the code to ensure the volume(containing the source code) is mounted to each container components.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Create a project with the following devfile
schemaVersion: 2.2.0
variables:
registry-root: registry.gitlab.com
components:
- name: tooling-container
attributes:
gl/inject-editor: true
container:
image: patnaikshekhar/go-ssh:1
env:
- name: KEY
value: VALUE
endpoints:
- name: http-3000
targetPort: 3000
- name: database
attributes:
gl/inject-editor: false
container:
image: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "my-secret-pw"
endpoints:
- name: mysql
targetPort: 3306
exposure: none
protocol: tcp
- Create a workspace from the said project.
- Ensure the volume that gets mounted(containing the project's code) is accessible in all container and any file written from one container can be seen by the other.
# change kubernetes namespace to the one just created for the workspace
POD_NAME=$(kubectl get po --no-headers -o custom-columns=":metadata.name")
kubectl exec -it $POD_NAME -c tooling-container -- sh
$ ls -lart /projects
total 16
drwxr-xr-x 3 gitlab-workspaces root 4096 Jan 30 04:43 testing-remote-development
drwxrwxrwx 4 root root 4096 Jan 30 04:43 .
drwxr-xr-x 3 gitlab-workspaces root 4096 Jan 30 04:43 .gl-tools
drwxr-xr-x 1 root root 4096 Jan 30 04:44 ..
$ touch /projects/TEST.md
kubectl exec -it $POD_NAME -c database -- sh
sh-4.4$ ls -lart /projects
total 16
drwxr-xr-x 3 5001 root 4096 Jan 30 04:43 testing-remote-development
drwxr-xr-x 3 5001 root 4096 Jan 30 04:43 .gl-tools
drwxr-xr-x 1 root root 4096 Jan 30 04:44 ..
-rw-r--r-- 1 5001 5001 0 Jan 30 04:51 TEST.md
drwxrwxrwx 4 root root 4096 Jan 30 04:51 .
As you can see, we wrote a file TEST.md
from the tooling-container
and we can see that file in the database
container.
Edited by Vishal Tak