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

fix: Ensure $PROJECT_SOURCE and $PROJECT_ROOT are first environment variables in workspace containers #1282

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions pkg/library/container/mountSources.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ func handleMountSources(k8sContainer *corev1.Container, devfileContainer *dw.Con
return err
}

k8sContainer.Env = append(k8sContainer.Env, corev1.EnvVar{
Name: devfileConstants.ProjectsRootEnvVar,
Value: sourceMapping,
}, corev1.EnvVar{
Name: devfileConstants.ProjectsSourceEnvVar,
Value: path.Join(sourceMapping, projectsSourcePath),
})
// The $PROJECT_ROOT and $PROJECT_SOURCE environment variables must be the first
// environment variables defined in the container so that other environment variables can reference them.
k8sContainer.Env = append([]corev1.EnvVar{
{
Name: devfileConstants.ProjectsRootEnvVar,
Value: sourceMapping,
},
{
Name: devfileConstants.ProjectsSourceEnvVar,
Value: path.Join(sourceMapping, projectsSourcePath),
}}, k8sContainer.Env...)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ output:
memory: "-1"
cpu: "-1"
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: "TEST_ENVVAR"
value: "TEST_VALUE"
- name: "PROJECTS_ROOT"
value: "/source-mapping"
- name: "PROJECT_SOURCE"
value: "/source-mapping"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: "TEST_ENVVAR"
value: "TEST_VALUE"
command:
- "test"
- "command"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: "Ensures PROJECT_ROOT and PROJECT_SOURCE env vars are first in list of env vars"

input:
projects:
- name: test_project
clonePath: clone-path
components:
- name: testing-container-1
container:
image: testing-image-1
memoryRequest: "-1" # isolate test to not include this field
memoryLimit: "-1" # isolate test to not include this field
cpuRequest: "-1" # isolate test to not include this field
cpuLimit: "-1" # isolate test to not include this field
# no mountSources defined -> should mount sources
env:
- name: user-env-var-1
value: value1
- name: user-env-var-1
value: value1
- name: testing-container-2
container:
image: testing-image-2
memoryRequest: "-1" # isolate test to not include this field
memoryLimit: "-1" # isolate test to not include this field
cpuRequest: "-1" # isolate test to not include this field
cpuLimit: "-1" # isolate test to not include this field
# No sourceMapping -> defaults to "/projects"
mountSources: true # mountSources: true -> should mount sources
env:
- name: user-env-var-2
value: value1
- name: user-env-var-3
value: value1
- name: testing-container-3
container:
image: testing-image-3
memoryRequest: "-1" # isolate test to not include this field
memoryLimit: "-1" # isolate test to not include this field
cpuRequest: "-1" # isolate test to not include this field
cpuLimit: "-1" # isolate test to not include this field
sourceMapping: "/projects"
mountSources: false # mountSources: false -> should not mount sources
env:
- name: user-env-var-4
value: value1
- name: user-env-var-5
value: value1
output:
podAdditions:
containers:
- name: testing-container-1
image: testing-image-1
imagePullPolicy: Always
resources:
requests:
memory: "-1"
cpu: "-1"
limits:
memory: "-1"
cpu: "-1"
volumeMounts:
- name: "projects"
mountPath: "/projects"
env:
- name: "PROJECTS_ROOT"
value: "/projects"
- name: "PROJECT_SOURCE"
value: "/projects/clone-path"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: user-env-var-1
value: value1
- name: user-env-var-1
value: value1
- name: testing-container-2
image: testing-image-2
imagePullPolicy: Always
resources:
requests:
memory: "-1"
cpu: "-1"
limits:
memory: "-1"
cpu: "-1"
volumeMounts:
- name: "projects"
mountPath: "/projects"
env:
- name: "PROJECTS_ROOT"
value: "/projects"
- name: "PROJECT_SOURCE"
value: "/projects/clone-path"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-2"
- name: user-env-var-2
value: value1
- name: user-env-var-3
value: value1
- name: testing-container-3
image: testing-image-3
imagePullPolicy: Always
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-3"
- name: user-env-var-4
value: value1
- name: user-env-var-5
value: value1
resources:
requests:
memory: "-1"
cpu: "-1"
limits:
memory: "-1"
cpu: "-1"
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ output:
- name: "projects"
mountPath: "/testdir1"
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: "PROJECTS_ROOT"
value: "/testdir1"
- name: "PROJECT_SOURCE"
value: "/testdir1/clone-path"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: testing-container-2
image: testing-image-2
imagePullPolicy: Always
Expand All @@ -71,12 +71,12 @@ output:
- name: "projects"
mountPath: "/projects"
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-2"
- name: "PROJECTS_ROOT"
value: "/projects"
- name: "PROJECT_SOURCE"
value: "/projects/clone-path"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-2"
- name: testing-container-3
image: testing-image-3
imagePullPolicy: Always
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ output:
- name: "projects"
mountPath: "/testdir1"
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: "PROJECTS_ROOT"
value: "/testdir1"
- name: "PROJECT_SOURCE"
value: "/testdir1/test_project"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: testing-container-2
image: testing-image-2
imagePullPolicy: Always
Expand All @@ -70,12 +70,12 @@ output:
- name: "projects"
mountPath: "/projects"
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-2"
- name: "PROJECTS_ROOT"
value: "/projects"
- name: "PROJECT_SOURCE"
value: "/projects/test_project"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-2"
- name: testing-container-3
image: testing-image-3
imagePullPolicy: Always
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ output:
- name: "projects"
mountPath: "/not-source-mapping"
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: "PROJECTS_ROOT"
value: "/not-source-mapping"
- name: "PROJECT_SOURCE"
value: "/not-source-mapping"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
8 changes: 4 additions & 4 deletions pkg/library/container/testdata/volume/mountSources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ output:
- name: "projects"
mountPath: "/testdir1"
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: "PROJECTS_ROOT"
value: "/testdir1"
- name: "PROJECT_SOURCE"
value: "/testdir1"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-1"
- name: testing-container-2
image: testing-image-2
imagePullPolicy: Always
Expand All @@ -66,12 +66,12 @@ output:
- name: "projects"
mountPath: "/projects"
env:
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-2"
- name: "PROJECTS_ROOT"
value: "/projects"
- name: "PROJECT_SOURCE"
value: "/projects"
- name: "DEVWORKSPACE_COMPONENT_NAME"
value: "testing-container-2"
- name: testing-container-3
image: testing-image-3
imagePullPolicy: Always
Expand Down
Loading