Skip to content

Commit 87c44d7

Browse files
committed
add projectsrc to env
Signed-off-by: Horiodino <[email protected]>
1 parent 69a656f commit 87c44d7

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

pkg/devfile/generator/generators_test.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func init() {
5252
}
5353

5454
func TestGetContainers(t *testing.T) {
55-
5655
containerNames := []string{"testcontainer1", "testcontainer2", "testcontainer3"}
5756
containerImages := []string{"image1", "image2", "image3"}
5857

@@ -132,11 +131,14 @@ func TestGetContainers(t *testing.T) {
132131
wantContainerName: containerNames[0],
133132
wantContainerImage: containerImages[0],
134133
wantContainerEnv: []corev1.EnvVar{
135-
136134
{
137135
Name: "PROJECTS_ROOT",
138136
Value: "/projects",
139137
},
138+
{
139+
Name: "PROJECT_SOURCE",
140+
Value: "/projects",
141+
},
140142
{
141143
Name: "PROJECT_SOURCE",
142144
Value: "/projects/test-project",
@@ -168,11 +170,14 @@ func TestGetContainers(t *testing.T) {
168170
wantContainerName: containerNames[0],
169171
wantContainerImage: containerImages[0],
170172
wantContainerEnv: []corev1.EnvVar{
171-
172173
{
173174
Name: "PROJECTS_ROOT",
174175
Value: "/myroot",
175176
},
177+
{
178+
Name: "PROJECT_SOURCE",
179+
Value: "/myroot",
180+
},
176181
{
177182
Name: "PROJECT_SOURCE",
178183
Value: "/myroot/test-project",
@@ -309,7 +314,6 @@ func TestGetContainers(t *testing.T) {
309314
}
310315
for _, tt := range tests {
311316
t.Run(tt.name, func(t *testing.T) {
312-
313317
ctrl := gomock.NewController(t)
314318
defer ctrl.Finish()
315319
mockDevfileData := data.NewMockDevfileData(ctrl)
@@ -372,7 +376,6 @@ func TestGetContainers(t *testing.T) {
372376
}
373377
})
374378
}
375-
376379
}
377380

378381
func TestGetVolumesAndVolumeMounts(t *testing.T) {
@@ -1449,6 +1452,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
14491452
Env: []corev1.EnvVar{
14501453
{Name: "PROJECTS_ROOT", Value: "/projects"},
14511454
{Name: "PROJECT_SOURCE", Value: "/projects"},
1455+
{Name: "PROJECT_SOURCE", Value: "/projects"},
14521456
},
14531457
ImagePullPolicy: corev1.PullAlways,
14541458
SecurityContext: &corev1.SecurityContext{
@@ -1461,6 +1465,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
14611465
Env: []corev1.EnvVar{
14621466
{Name: "PROJECTS_ROOT", Value: "/projects"},
14631467
{Name: "PROJECT_SOURCE", Value: "/projects"},
1468+
{Name: "PROJECT_SOURCE", Value: "/projects"},
14641469
},
14651470
ImagePullPolicy: corev1.PullAlways,
14661471
Ports: []corev1.ContainerPort{},
@@ -1513,6 +1518,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
15131518
Env: []corev1.EnvVar{
15141519
{Name: "PROJECTS_ROOT", Value: "/projects"},
15151520
{Name: "PROJECT_SOURCE", Value: "/projects"},
1521+
{Name: "PROJECT_SOURCE", Value: "/projects"},
15161522
},
15171523
ImagePullPolicy: corev1.PullAlways,
15181524
SecurityContext: &corev1.SecurityContext{
@@ -1567,6 +1573,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
15671573
Env: []corev1.EnvVar{
15681574
{Name: "PROJECTS_ROOT", Value: "/projects"},
15691575
{Name: "PROJECT_SOURCE", Value: "/projects"},
1576+
{Name: "PROJECT_SOURCE", Value: "/projects"},
15701577
},
15711578
ImagePullPolicy: corev1.PullAlways,
15721579
SecurityContext: &corev1.SecurityContext{
@@ -1623,6 +1630,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
16231630
Env: []corev1.EnvVar{
16241631
{Name: "PROJECTS_ROOT", Value: "/projects"},
16251632
{Name: "PROJECT_SOURCE", Value: "/projects"},
1633+
{Name: "PROJECT_SOURCE", Value: "/projects"},
16261634
},
16271635
ImagePullPolicy: corev1.PullAlways,
16281636
Ports: []corev1.ContainerPort{},
@@ -1677,6 +1685,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
16771685
Env: []corev1.EnvVar{
16781686
{Name: "PROJECTS_ROOT", Value: "/projects"},
16791687
{Name: "PROJECT_SOURCE", Value: "/projects"},
1688+
{Name: "PROJECT_SOURCE", Value: "/projects"},
16801689
},
16811690
ImagePullPolicy: corev1.PullAlways,
16821691
SecurityContext: &corev1.SecurityContext{
@@ -1743,6 +1752,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
17431752
Env: []corev1.EnvVar{
17441753
{Name: "PROJECTS_ROOT", Value: "/projects"},
17451754
{Name: "PROJECT_SOURCE", Value: "/projects"},
1755+
{Name: "PROJECT_SOURCE", Value: "/projects"},
17461756
},
17471757
ImagePullPolicy: corev1.PullAlways,
17481758
Ports: []corev1.ContainerPort{},
@@ -1812,6 +1822,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
18121822
Env: []corev1.EnvVar{
18131823
{Name: "PROJECTS_ROOT", Value: "/projects"},
18141824
{Name: "PROJECT_SOURCE", Value: "/projects"},
1825+
{Name: "PROJECT_SOURCE", Value: "/projects"},
18151826
},
18161827
ImagePullPolicy: corev1.PullAlways,
18171828
Ports: []corev1.ContainerPort{},
@@ -1875,6 +1886,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
18751886
Env: []corev1.EnvVar{
18761887
{Name: "PROJECTS_ROOT", Value: "/projects"},
18771888
{Name: "PROJECT_SOURCE", Value: "/projects"},
1889+
{Name: "PROJECT_SOURCE", Value: "/projects"},
18781890
},
18791891
ImagePullPolicy: corev1.PullAlways,
18801892
Ports: []corev1.ContainerPort{},
@@ -1937,6 +1949,7 @@ func TestGetPodTemplateSpec(t *testing.T) {
19371949
Env: []corev1.EnvVar{
19381950
{Name: "PROJECTS_ROOT", Value: "/projects"},
19391951
{Name: "PROJECT_SOURCE", Value: "/projects"},
1952+
{Name: "PROJECT_SOURCE", Value: "/projects"},
19401953
},
19411954
ImagePullPolicy: corev1.PullAlways,
19421955
Ports: []corev1.ContainerPort{},

pkg/devfile/generator/utils.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424

2525
v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
2626
"github.com/devfile/api/v2/pkg/attributes"
27+
"github.com/hashicorp/go-multierror"
2728

2829
"github.com/devfile/library/v2/pkg/devfile/parser"
2930
"github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
30-
"github.com/hashicorp/go-multierror"
3131
buildv1 "github.com/openshift/api/build/v1"
3232
routev1 "github.com/openshift/api/route/v1"
3333
appsv1 "k8s.io/api/apps/v1"
@@ -153,11 +153,15 @@ func addSyncRootFolder(container *corev1.Container, sourceMapping string) string
153153

154154
// Note: PROJECTS_ROOT & PROJECT_SOURCE are validated at the devfile parser level
155155
// Add PROJECTS_ROOT to the container
156-
container.Env = append(container.Env,
157-
corev1.EnvVar{
156+
container.Env = append([]corev1.EnvVar{
157+
{
158158
Name: EnvProjectsRoot,
159159
Value: syncRootFolder,
160-
})
160+
}, {
161+
Name: EnvProjectsSrc,
162+
Value: syncRootFolder,
163+
},
164+
}, container.Env...)
161165

162166
return syncRootFolder
163167
}

0 commit comments

Comments
 (0)