Skip to content

Commit

Permalink
add projectsrc to env
Browse files Browse the repository at this point in the history
Signed-off-by: Horiodino <[email protected]>
  • Loading branch information
Horiodino committed Aug 3, 2024
1 parent 69a656f commit 87c44d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
23 changes: 18 additions & 5 deletions pkg/devfile/generator/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func init() {
}

func TestGetContainers(t *testing.T) {

containerNames := []string{"testcontainer1", "testcontainer2", "testcontainer3"}
containerImages := []string{"image1", "image2", "image3"}

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -372,7 +376,6 @@ func TestGetContainers(t *testing.T) {
}
})
}

}

func TestGetVolumesAndVolumeMounts(t *testing.T) {
Expand Down Expand Up @@ -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{
Expand All @@ -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{},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down
12 changes: 8 additions & 4 deletions pkg/devfile/generator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 87c44d7

Please sign in to comment.