-
Notifications
You must be signed in to change notification settings - Fork 61
Support global environment variables defined by a component-level attribute #538
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Just a few minor comments. Good job!
pkg/library/flatten/helper.go
Outdated
@@ -64,3 +65,14 @@ func formatImportCycle(end *resolutionContextTree) string { | |||
} | |||
return cycle | |||
} | |||
|
|||
func getOriginalNameForComponent(component dw.Component) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we don't modify components names, it returns exactly what is written in body: SourceComponent. Maybe then rename it to getSourceForComponent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't modify component names per se, but we delete plugin components and add e.g. container components:
components:
- name: my-plugin
plugin: [...]
becomes
components:
- name: plugin-container
container: [...]
But I see your point -- I'll update.
pkg/library/flatten/workspaceEnv.go
Outdated
var componentEnv []dw.EnvVar | ||
err := component.Attributes.GetInto(WorkspaceEnvAttribute, &componentEnv) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read attribute %s on component %s: %w", WorkspaceEnvAttribute, getOriginalNameForComponent(component), err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate the format of attributes can be +1 things we can validate with validate webhooks.
@@ -0,0 +1,75 @@ | |||
name: "Adds workspace environment variables from plugin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please allign test files names, now some are with _, some only -, some with CamelCase for workspaceEnv, some has workspace-env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed for consistency -- note the format I've used thus far for _
vs -
is that dashes replace spaces in the sentence describing the test, and error_
is the prefix that specifies that a test case is expected to return an error (it's mostly so that an alphabetical sort puts all error testcases together). If I've missed a place in that framework, I'll fix it.
@@ -0,0 +1,84 @@ | |||
name: "Adds JSON workspace environment variables from plugin " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File name and case name does not seem to be really the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy-paste error :)
@@ -0,0 +1,84 @@ | |||
name: "Adds workspace environment variables from plugin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suite case appear the second time
pkg/library/flatten/testdata/workspace-env/error_workspaceEnv-formatted-wrong.yaml
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other then Serhii's comments it looks good to me
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: amisevsk, JPinkney, sleshchenko 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 |
/test v7-devworkspaces-operator-e2e, v7-devworkspace-happy-path |
@amisevsk feel free to merge with squash or rebase to get rid of fixups and rerun tests. |
Add support for workspaceEnv (i.e. environment variables provided by a component that get added to all other components) though setting an attribute 'workspaceEnv' in a component. If that component is added to the workspace (either directly or through a plugin) the environment variables defined within are added to all containers and init containers in the workspace. Example: a component components: - name: my-component attributes: workspaceEnv: - name: MY_ENV value: my-value - name: MY_ENV_2 value: my-value-2 will add the MY_ENV and MY_ENV_2 environment variables to all containers in the DevWorkspace. Note we use component attributes rather than top-level attributes for workspaceEnv, since top-level attributes pose some problems for flattening: - If the base DevWorkspace defines workspaceEnv in top-level attributes and a plugin does the same, flattening fails - If two plugins define top-level workspaceEnv attributes, the workspaceEnv of the first if overwritten by the second Signed-off-by: Angel Misevski <[email protected]>
Extract common setup for tests to a separate function Signed-off-by: Angel Misevski <[email protected]>
Signed-off-by: Angel Misevski <[email protected]>
6a5d12f
to
a3b6122
Compare
New changes are detected. LGTM label has been removed. |
/test v7-devworkspaces-operator-e2e, v7-devworkspace-happy-path |
This PR is a slightly cleaned up iteration of #529
What does this PR do?
Add support for the devfile 1.0 feature
workspaceEnv
(env vars supplied by a component that get added to all containers in the workspace). This is defined using an attribute on components namedworkspaceEnv
formatted as[]EnvVar
, i.e.:Note: it's necessary to define the attribute on components for now, because merging plugin components with top-level attributes is unsuitable to some use cases:
An alternative approach that would allow using top-level attributes would be some sort of namespacing mechanism, e.g. using
workspace-env/my-component
as the attribute, but this would be harder to process and write.What issues does this PR fix or reference?
Closes #530
Is it tested? How?
Test cases are included; can be tested directly using the DevWorkspace
and checking that all containers in the resulting pod have the environment variables listed.
PR Checklist
/test v7-devworkspaces-operator-e2e, v7-devworkspace-happy-path
to trigger)v7-devworkspaces-operator-e2e
: DevWorkspace e2e testv7-devworkspace-happy-path
: DevWorkspace e2e test