-
Notifications
You must be signed in to change notification settings - Fork 56
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 support for containerContributions #844
Conversation
To add, this PR enables more easily switching editors in the Che case, as only the plugin needs to be swapped out (and potentially the annotation saying which vsix plugins need to be installed). With the existing approach in Che, the changes to the devfile have to be undone before another editor can be applied |
@amisevsk thanks I will test that later. To help me understanding the approach can you please confirm that it requires that:
Or are the attributes inferred automatically (for instance if the component is a plugin then, when flattened, it will have |
At the moment, attributes are explicit and have to be defined in the DevWorkspace/plugins. I took this approach to avoid breaking devfiles, as e.g. the che-docs devfile does not use an UDI image and injecting the editor stuff there might break things. The Part of my hope with how this works is that plugins with container contributions can use a fallback image in case injecting is not possible. For example, che-code could specify an image that will mostly work to host the editor in the case that a container that can run it is not found -- I believe this is the case with the current plugin definition. |
I've tested the container contribution functionality with the existing Che dashboard:
However, in the vscode case, it appears that the dashboard drops the A note on testing: to test this flow, it's not possible to use standalone devfiles due to eclipse-che/che#21433. The correct flow appears to be
|
Hello, is that because I don't expect to have users having to change their devfile. For |
Currently it's not optional, and merging does not happen if it is not present. The reason for this is that it could be a breaking change -- for example, I don't know if the che-docs repository would work if the injection happened automatically, since it does not use the common UDI image. If automatically merging contributions breaks your devfile, then you'd have to change your devfile to make it work again, as opposed to changing it to make it work in a different way. The upshot is that it should be possible to write the editor plugins so that the workspace starts and shows an editor even if merging does not happen, as the contribution component could bring its own default image. If we want the merge-contribution feature to be inferred, this could also be done in the Che Dashboard, where we currently manually do the injection. For example, in the case of che-code, instead of taking the fields from the |
b133925
to
79bd392
Compare
@amisevsk I've followed the testing steps for the two test DevWorkspaces (Che-Code + Golang, Che-Theia + Golang) and the flattened devfile has the container contributions merged as expected 👍 . I wasn't able to open the Che-Code + Golang editor via the devworkspace's |
@dkwon17 you may have to add |
@dkwon17 Shouldn't be happening 🤔. Florent is right (in case your DevWorkspace doesn't have the CODE_HOST override, though that is in the sample devfile so if you used that it might be something else. Without the CODE_HOST override, I believe the DevWorkspace won't reach a running state since it tries to check the mainUrl. |
I see, I'm still not able to open the editor even though I'm using the sample devfile that @amisevsk provided. Here is the flattened devfile I retrieved by running I also confirmed that the
Also, the devworkspace seems to enter the running state without any issues: Here is the yaml for the |
hit the same problem as David during the vs code verification. |
After discussion yesterday with @amisevsk +1 to require the explicit attributes: adding the On the other hand, to keep the The theia-golang example above would change like this: kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
name: test-contrib-theia
spec:
started: true
+ contributions:
+ - name: che-theia-ide
+ uri: https://gist.githubusercontent.com/amisevsk/b342b9ae064b5a79e08945d04d02c208/raw/84cd2df9266b4a608fbc0fd0cc18816bca03e344/theia-contrib.devfile.yaml:
template:
attributes:
controller.devfile.io/storage-type: ephemeral
components:
(...)
- - name: che-theia-ide
- plugin:
- uri: https://gist.githubusercontent.com/amisevsk/b342b9ae064b5a79e08945d04d02c208/raw/84cd2df9266b4a608fbc0fd0cc18816bca03e344/theia-contrib.devfile.yaml |
I was able to test out both the che-theia and che-code gists provided with this PR. I am also +1 for making the |
@amisevsk a small remark: looking at the Che-Theia + Golang DevWorkspace, it's better to rename the editor component, because che-code is confusing a bit |
PR devfile/api#879 would add the proposed containerContributions field if merged. However, in the interest of sequencing PRs/issues, I'm marking this PR as ready to review -- if there's no issues with this approach this PR can be merged and the functionality can be extended/applied to the |
@svor good catch -- updated. |
/retest |
To test these changes via OLM, I've build an index image |
I don't recall why we need to add the suffix |
@l0rd @amisevsk |
Thanks @azatsarynnyy for the clarification. I think that then we should replace that path with |
@l0rd please see my comment on eclipse-che/che#21400 (comment) upd: I mean not losing that functionality completely, but it will require the user to do some manual steps for opening a multi-root VS Code workspace. The mentioned VS Code extension does that automatically. We just need to reworking that in a more efficient way, w/o reloading the page. |
In that case, it appears that this issue isn't a real problem for merging the current PR -- we can figure out the parameters later and it works as intended in the Che dashboard in my testing. I'm still interested in why providing the |
/retest |
pkg/library/flatten/merge.go
Outdated
newComponents = append(newComponents, component) | ||
continue | ||
} | ||
if component.Attributes.GetBoolean(constants.ContainerContributionAttribute, nil) == true { |
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.
Though this line (and other similar ones) could be just if component.Attributes.GetBoolean(constants.ContainerContributionAttribute, nil) {...
I think it's okay to be explicit here about wanting the value of the ContainerContributionAttribute
to be true.
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.
No, this is just me being a dummy :D
I'll remove it.
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 now, thanks :)
pkg/library/flatten/merge.go
Outdated
// Ignore attribute on non-container components as it's not clear what this would mean | ||
continue | ||
} | ||
if component.Attributes.GetBoolean(constants.ContainerContributionAttribute, nil) == true { |
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 is nitpicking, but maybe an error holder should be added here and at line 134. It'll make the code that calls this function in merge.go
a bit uglier though.
Future calls of component.Attributes.GetBoolean(constants.ContainerContributionAttribute, nil)
in mergeContainerContributions
wouldn't need this error holder since needsContainerContributionMerge
is called first.
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 is a good point -- previously I was just interpreting wrong values as false but it makes sense to highlight the case where the attribute is present but cannot be read correctly, e.g. if the value is ture
or something.
I'll update the PR with that change.
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.
Left some minor comments that aren't really necessary for this to be merged.
Code looks good to me, as do the automated test cases.
Tested (again) the provided samples on Minikube, and they work as expected. Awesome work @amisevsk 😁
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.
@amisevsk I have tested the PR updating the devworkspace-demo and it worked perfectly. I have also tried to reproduce the scenario of this downstream issue and the CPU limits are summed up correctly. Just one note: I have also tired to use the spec.contributions
in the devworkspace-demo but it's not working yet: I think that's supposed to be implemented in a separate PR.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: amisevsk, AObuchow, ibuziuk, l0rd 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 |
This is correct. This PR does not update the devfile/api dependency to include containerContributions in the DevWorkspace CR. The dependency bump is part of #868, which is currently on hold to ensure we don't cause issues applying the CRDs in other tools. Once that PR is merged, I'll open another PR to also process containerContributions. |
Add support for attributes controller.devfile.io/container-contribution: true controller.devfile.io/merge-contribution: true When a container-contribution component can be matched with a merge-contribution component, the two are merged: * resource requirements (memory, cpu) are added together * the image from the contribution is ignored * remaining fields are merged using a strategic merge patch This can be used to e.g. update an existing devworkspace component to inject configuration or an editor into that container without having to update the DevWorkspace Signed-off-by: Angel Misevski <amisevsk@redhat.com>
Add attribute controller.devfile.io/merged-contributions that is applied to the component after merging contributions into it. This attribute stores a comma-separated list of the contributions' IDs. We also remove the source-attribute and other containercontributions attributes as they do not make sense in the merged context. Signed-off-by: Angel Misevski <amisevsk@redhat.com>
Signed-off-by: Angel Misevski <amisevsk@redhat.com>
60f9095
to
8e265eb
Compare
New changes are detected. LGTM label has been removed. |
When the 'controller.devfile.io/container-contribution' or 'controller.devfile.io/merge-contribution' attribute is present on a component in a DevWorkspace, check whether its value can be parse as a boolean. If the value cannot be read as a boolean (e.g. a typo), then fail workspace start with a message pointing at the issue. Signed-off-by: Angel Misevski <amisevsk@redhat.com>
This PR is an early draft. Before merging:
What does this PR do?
Adds support for container contributions as described in #656 without needing to add new component types.
This PR adds two new attributes to the operator:
controller.devfile.io/container-contribution: true
defines a container component as a "container contribution"controller.devfile.io/merge-contribution: true
defines a container as a target for merging a "container contribution"If a flattened DevWorkspace has a container component with the
merge-contribution
attribute, then any container contributions are merged into that container component according toThis approach has the additional benefit of failing safely if it's not obvious how to merge containers, defaulting to using the unmerged image to host the container components that cannot be merged.
If multiple components have the
merge-contribution
attribute, contributions are merged into the first one encountered.Background
Eclipse Che uses DWO to create workspaces from a basic devfile, injecting an editor into the Devfile before converting it to a DevWorkspace. However, since Che intends to run editors inside a devfile container component and not as sidecars, it's necessary to modify existing container components to add endpoints, environment variables, and override the args. For example, to update a container component to run Eclipse Theia plugins, Che has to update the component to add the following fields:
The added fields are defined by the plugin (
theia-ide-golang-example
in this case), so it would be useful if plugins had a mechanism for automatically defining these additions. This would also mean that devfiles could be converted into DevWorkspaces by only adding plugin components, leaving original devfile components untouched (as the merging happens within the flatten process, leaving the DevWorkspace as-is).What issues does this PR fix or reference?
Closes #656
Is it tested? How?
There are two DevWorkspaces for testing this feature:
Che-Theia + Golang [link]
Creates a DevWorkspace that references plugin devfile theia-next.yaml. The contributions in this plugin add fields as described above to allow Theia plugins to run inside the
tools
container component without having to update thetools
component in the DevWorkspace itself (duplicating the process that Che does when creating a workspace from a devfile). The diff between the referenced plugin and the default plugin at https://che-plugin-registry-main.surge.sh/v3/plugins/eclipse/che-theia/next/devfile.yaml isChe-Code + Golang [link]
Creates a DevWorkspace that references the plugin devfile che-code.yaml. This plugin is a modified version of the current plugin hosted here, which converts the
che-code-runtime-description
into a container contribution. This workspace results in a deployment with two init containers (che-code-injector
andproject-clone
) and only one running container (tools
). The changes to the plugin used here compared to the one in the registry are:(I updated the image to match the one from the devfile to avoid having to pull two separate UDI images)
PR Checklist
/test v8-devworkspace-operator-e2e, v8-che-happy-path
to trigger)v8-devworkspace-operator-e2e
: DevWorkspace e2e testv8-che-happy-path
: Happy path for verification integration with Che