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

add projectsrc to env #220

Merged
merged 5 commits into from
Aug 21, 2024
Merged

Conversation

Horiodino
Copy link
Contributor

@Horiodino Horiodino commented Aug 3, 2024

What does this PR do?:

Updating ENV list for all special/reserved ENVs

Which issue(s) this PR fixes:

fixes: devfile/api#1601

PR acceptance criteria:

Testing and documentation do not need to be complete in order for this PR to be approved. We just need to ensure tracking issues are opened and linked to this PR, if they are not in the PR scope due to various constraints.

  • Unit/Functional tests

  • QE Integration test

  • Documentation (READMEs, Product Docs, Blogs, Education Modules, etc.)

  • Client Impact

  • Gosec scans

How to test changes / Special notes to the reviewer:

Signed-off-by: Horiodino <holiodin@gmail.com>
@openshift-ci openshift-ci bot requested review from elsony and Jdubrick August 3, 2024 16:04
@Horiodino
Copy link
Contributor Author

Horiodino commented Aug 3, 2024

should i remove addSyncFolder module ? as the EnvProjectsSrc repeated two times
@Jdubrick

@Horiodino
Copy link
Contributor Author

i was thinking maybe rather than using addSyncFolder why wont just merge that module with addSyncRootFolder ?
does the same work ?

Copy link
Contributor

@thepetk thepetk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I just realized the review I left on Wednesday left on "pending" state.

pkg/devfile/generator/utils.go Outdated Show resolved Hide resolved
pkg/devfile/generator/generators_test.go Outdated Show resolved Hide resolved
Signed-off-by: Horiodino <holiodin@gmail.com>
Copy link
Contributor

@Jdubrick Jdubrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After taking a look into this and testing it myself the following changes should be made in addition to my review comments:

In addSyncFolder we should turn this:

container.Env = append(container.Env,
		corev1.EnvVar{
			Name:  EnvProjectsSrc,
			Value: syncFolder,
		})

Into this:

container.Env = append([]corev1.EnvVar{
		{
			Name:  EnvProjectsSrc,
			Value: syncFolder,
		},
	}, container.Env...)

We can also update TestGetContainers test cases to the following to observe the ordering:

{
			name: "Container with default project root",
			containerComponents: []v1.Component{
				{
					Name: containerNames[0],
					ComponentUnion: v1.ComponentUnion{
						Container: &v1.ContainerComponent{
							Container: v1.Container{
								Image:        containerImages[0],
								MountSources: &trueMountSources,
								Env: []v1.EnvVar{
									{
										Name:  "testVar1",
										Value: "testVal1",
									},
									{
										Name:  "testVar2",
										Value: "testVal2",
									},
								},
							},
						},
					},
				},
			},
			wantContainerName:  containerNames[0],
			wantContainerImage: containerImages[0],
			wantContainerEnv: []corev1.EnvVar{
				{
					Name:  "PROJECT_SOURCE",
					Value: "/projects/test-project",
				},
				{
					Name:  "PROJECTS_ROOT",
					Value: "/projects",
				},
				{
					Name:  "testVar1",
					Value: "testVal1",
				},
				{
					Name:  "testVar2",
					Value: "testVal2",
				},
			},
			wantContainerVolMount: []corev1.VolumeMount{
				{
					Name:      "devfile-projects",
					MountPath: "/projects",
				},
			},
		},
		{
			name: "Container with source mapping",
			containerComponents: []v1.Component{
				{
					Name: containerNames[0],
					ComponentUnion: v1.ComponentUnion{
						Container: &v1.ContainerComponent{
							Container: v1.Container{
								Image:         containerImages[0],
								MountSources:  &trueMountSources,
								SourceMapping: "/myroot",
								Env: []v1.EnvVar{
									{
										Name:  "testVar1",
										Value: "testVal1",
									},
									{
										Name:  "testVar2",
										Value: "testVal2",
									},
								},
							},
						},
					},
				},
			},
			wantContainerName:  containerNames[0],
			wantContainerImage: containerImages[0],
			wantContainerEnv: []corev1.EnvVar{
				{
					Name:  "PROJECT_SOURCE",
					Value: "/myroot/test-project",
				},
				{
					Name:  "PROJECTS_ROOT",
					Value: "/myroot",
				},
				{
					Name:  "testVar1",
					Value: "testVal1",
				},
				{
					Name:  "testVar2",
					Value: "testVal2",
				},
			},
			wantContainerVolMount: []corev1.VolumeMount{
				{
					Name:      "devfile-projects",
					MountPath: "/myroot",
				},
			},
		},

pkg/devfile/generator/generators_test.go Outdated Show resolved Hide resolved
pkg/devfile/generator/utils.go Outdated Show resolved Hide resolved
@Jdubrick
Copy link
Contributor

fyi @thepetk if you see my review and want to try the changes yourself

@thepetk
Copy link
Contributor

thepetk commented Aug 15, 2024

fyi @thepetk if you see my review and want to try the changes yourself

@Jdubrick yes +1 is aligned with my comment here

Signed-off-by: Horiodino <holiodin@gmail.com>
pkg/devfile/generator/utils.go Outdated Show resolved Hide resolved
Signed-off-by: Horiodino <holiodin@gmail.com>
@Jdubrick
Copy link
Contributor

/ok-to-test

@Jdubrick
Copy link
Contributor

@Horiodino I believe the tests Go tests are failing because the order of the env vars in the tests is 1: PROJECT_ROOT and 2: PROJECT_SOURCE but since we are prepending and PROJECT_SOURCE is added last it is now coming first. We will need to adjust these tests. You should be able to reference the failing tests here

Signed-off-by: Horiodino <holiodin@gmail.com>
@Horiodino
Copy link
Contributor Author

=== RUN   Test_VolumeComponentEdit
--- PASS: Test_VolumeComponentEdit (3.03s)
=== RUN   Test_MultiComponent
--- PASS: Test_MultiComponent (3.09s)
=== RUN   Test_Projects
--- PASS: Test_Projects (3.06s)
=== RUN   Test_StarterProjects
--- PASS: Test_StarterProjects (3.10s)
=== RUN   Test_Events
--- PASS: Test_Events (3.05s)
=== RUN   Test_EventsEdit
--- PASS: Test_EventsEdit (3.22s)
=== RUN   Test_Metadata
--- PASS: Test_Metadata (3.02s)
=== RUN   Test_MetadataEdit
--- PASS: Test_MetadataEdit (3.07s)
=== RUN   Test_Parent_Local_URI
--- PASS: Test_Parent_Local_URI (3.02s)
=== RUN   Test_v200_Devfile
--- PASS: Test_v200_Devfile (3.05s)
=== RUN   Test_v210_Devfile
--- PASS: Test_v210_Devfile (3.01s)
=== RUN   Test_v220_Devfile
--- PASS: Test_v220_Devfile (0.01s)
=== RUN   Test_Parent_KubeCRD
--- PASS: Test_Parent_KubeCRD (3.01s)
=== RUN   Test_Parent_RegistryURL
--- PASS: Test_Parent_RegistryURL (6.85s)
=== RUN   Test_Everything
--- PASS: Test_Everything (3.06s)
=== RUN   Test_EverythingEdit
--- PASS: Test_EverythingEdit (3.11s)
PASS
coverage: [no statements]
ok  	github.com/devfile/library/v2/tests/v2/libraryTest	92.911s	coverage: [no statements]

@Jdubrick
Copy link
Contributor

/retest

Copy link
Contributor

@Jdubrick Jdubrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@thepetk I know you reviewed alongside me if you want to also give a final review :)

Copy link
Contributor

@thepetk thepetk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Copy link

openshift-ci bot commented Aug 21, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Horiodino, Jdubrick, thepetk

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Jdubrick Jdubrick merged commit c06005c into devfile:main Aug 21, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

devfile special envs cannot be defined last in the env list
3 participants