From 87c44d7c0b8562b17c21428bbb209cb68ebd2a8a Mon Sep 17 00:00:00 2001 From: Horiodino Date: Sat, 3 Aug 2024 13:10:13 +0530 Subject: [PATCH] add projectsrc to env Signed-off-by: Horiodino --- pkg/devfile/generator/generators_test.go | 23 ++++++++++++++++++----- pkg/devfile/generator/utils.go | 12 ++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pkg/devfile/generator/generators_test.go b/pkg/devfile/generator/generators_test.go index e5c13868..9f65ccbd 100644 --- a/pkg/devfile/generator/generators_test.go +++ b/pkg/devfile/generator/generators_test.go @@ -52,7 +52,6 @@ func init() { } func TestGetContainers(t *testing.T) { - containerNames := []string{"testcontainer1", "testcontainer2", "testcontainer3"} containerImages := []string{"image1", "image2", "image3"} @@ -132,11 +131,14 @@ func TestGetContainers(t *testing.T) { wantContainerName: containerNames[0], wantContainerImage: containerImages[0], wantContainerEnv: []corev1.EnvVar{ - { Name: "PROJECTS_ROOT", Value: "/projects", }, + { + Name: "PROJECT_SOURCE", + Value: "/projects", + }, { Name: "PROJECT_SOURCE", Value: "/projects/test-project", @@ -168,11 +170,14 @@ func TestGetContainers(t *testing.T) { wantContainerName: containerNames[0], wantContainerImage: containerImages[0], wantContainerEnv: []corev1.EnvVar{ - { Name: "PROJECTS_ROOT", Value: "/myroot", }, + { + Name: "PROJECT_SOURCE", + Value: "/myroot", + }, { Name: "PROJECT_SOURCE", Value: "/myroot/test-project", @@ -309,7 +314,6 @@ func TestGetContainers(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ctrl := gomock.NewController(t) defer ctrl.Finish() mockDevfileData := data.NewMockDevfileData(ctrl) @@ -372,7 +376,6 @@ func TestGetContainers(t *testing.T) { } }) } - } func TestGetVolumesAndVolumeMounts(t *testing.T) { @@ -1449,6 +1452,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, SecurityContext: &corev1.SecurityContext{ @@ -1461,6 +1465,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{}, @@ -1513,6 +1518,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, SecurityContext: &corev1.SecurityContext{ @@ -1567,6 +1573,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, SecurityContext: &corev1.SecurityContext{ @@ -1623,6 +1630,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{}, @@ -1677,6 +1685,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, SecurityContext: &corev1.SecurityContext{ @@ -1743,6 +1752,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{}, @@ -1812,6 +1822,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{}, @@ -1875,6 +1886,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{}, @@ -1937,6 +1949,7 @@ func TestGetPodTemplateSpec(t *testing.T) { Env: []corev1.EnvVar{ {Name: "PROJECTS_ROOT", Value: "/projects"}, {Name: "PROJECT_SOURCE", Value: "/projects"}, + {Name: "PROJECT_SOURCE", Value: "/projects"}, }, ImagePullPolicy: corev1.PullAlways, Ports: []corev1.ContainerPort{}, diff --git a/pkg/devfile/generator/utils.go b/pkg/devfile/generator/utils.go index edfc4c66..19d44c19 100644 --- a/pkg/devfile/generator/utils.go +++ b/pkg/devfile/generator/utils.go @@ -24,10 +24,10 @@ import ( v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" "github.com/devfile/api/v2/pkg/attributes" + "github.com/hashicorp/go-multierror" "github.com/devfile/library/v2/pkg/devfile/parser" "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common" - "github.com/hashicorp/go-multierror" buildv1 "github.com/openshift/api/build/v1" routev1 "github.com/openshift/api/route/v1" appsv1 "k8s.io/api/apps/v1" @@ -153,11 +153,15 @@ func addSyncRootFolder(container *corev1.Container, sourceMapping string) string // Note: PROJECTS_ROOT & PROJECT_SOURCE are validated at the devfile parser level // Add PROJECTS_ROOT to the container - container.Env = append(container.Env, - corev1.EnvVar{ + container.Env = append([]corev1.EnvVar{ + { Name: EnvProjectsRoot, Value: syncRootFolder, - }) + }, { + Name: EnvProjectsSrc, + Value: syncRootFolder, + }, + }, container.Env...) return syncRootFolder }