Skip to content

Adding support of the ephemeral workspaces (using emptyDir volume instead of PVC) via 'persistVolumes' attribute#11343

Merged
ibuziuk merged 6 commits intoeclipse-che:masterfrom
ibuziuk:ephemeral
Sep 27, 2018
Merged

Adding support of the ephemeral workspaces (using emptyDir volume instead of PVC) via 'persistVolumes' attribute#11343
ibuziuk merged 6 commits intoeclipse-che:masterfrom
ibuziuk:ephemeral

Conversation

@ibuziuk
Copy link
Copy Markdown
Member

@ibuziuk ibuziuk commented Sep 25, 2018

What does this PR do?

Adding support of the ephemeral workspaces (using emptyDir volume instead of PVC) via mountSources attribute. Once persistVolumes attribute is set to false all workspace volumes would be created not according to the defined as emptyDirs :

    Mounts:
      /another/volume from ephemeral-z8cst7yy (rw)
      /projects from ephemeral-3euiezrk (rw)
      /test/my/volume from ephemeral-gqhpebls (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-jhsmm (ro)
      /workspace_logs from ephemeral-wjc5yu37 (rw)
Conditions:
  Type           Status
  Initialized    True 
  Ready          True 
  PodScheduled   True 
Volumes:
  ephemeral-gqhpebls:
    Type:    EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:  
  ephemeral-3euiezrk:
    Type:    EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:  
  ephemeral-z8cst7yy:
    Type:    EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:  
  ephemeral-wjc5yu37:
    Type:    EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium: 

What issues does this PR fix or reference?

#11350
redhat-developer/rh-che#860

WIP

Release Notes

WIP

Docs PR

WIP

…tead of PVC) via 'mountSources' attribute

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
@ibuziuk ibuziuk added the status/in-progress This issue has been taken by an engineer and is under active development. label Sep 25, 2018
@ibuziuk
Copy link
Copy Markdown
Member Author

ibuziuk commented Sep 25, 2018

@garagatyi @sleshchenko PR is still WIP and missing tests / docs, but I just want to make sure that you are ok with the overall approach.

…PVCCleaner

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
Copy link
Copy Markdown

@garagatyi garagatyi left a comment

Choose a reason for hiding this comment

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

@ibuziuk Overall looks good. Would be nice to clean it a bit to simplify PR review and code support.

String machineName = Names.machineName(pod, container);
InternalMachineConfig machineConfig = k8sEnv.getMachines().get(machineName);
addMachineVolumes(workspaceId, subPaths, pod, container, machineConfig.getVolumes());
if (ephemeralWorkspaceAdapter.isEphemeral(workspaceId)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Changing code like that shows a big diff I would say. Can you just:

if (ephemeralWorkspaceAdapter.isEphemeral(workspaceId)) {
    ephemeralWorkspaceAdapter.provision(k8sEnv, identity);
    return;
}

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah, sure

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

}
if (preCreateDirs && subpaths != null) {
pvcSubPathHelper.createDirs(workspaceId, subpaths);
if (!ephemeralWorkspaceAdapter.isEphemeral(workspaceId)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

See comment above

final String workspaceId = event.getWorkspace().getId();
try {
strategy.cleanup(workspaceId);
if (!isEphemeral(event.getWorkspace())) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would be better to move this logic to the strategy to avoid splitting it between components.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah, good point

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@garagatyi do you think it would be acceptable to change strategy interface e.g. void cleanup(Workspace workspace) throws InfrastructureException; in order to get the whole workspace config directly in strategies ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, I do. @sleshchenko WDYT?

}

private String getSubPath(String workspaceId, String volumeName, String machineName) {
// logs must be located inside the folder related to the machine because few machines can
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems that a lot of code is inspired by strategies code. Would be nice to reuse the code if possible.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

you are right, but reusing strategies code might be not really straight-forward

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Then let's go with a simpler approach. Time will show whether we would need to refactor that later

…ntSources' attribute

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
@ibuziuk ibuziuk changed the title [WIP] Adding support of the ephemeral workspaces (using emptyDir volume instead of PVC) via 'mountSources' attribute Adding support of the ephemeral workspaces (using emptyDir volume instead of PVC) via 'mountSources' attribute Sep 26, 2018
@benoitf benoitf added the kind/enhancement A feature request - must adhere to the feature request template. label Sep 26, 2018
@ibuziuk
Copy link
Copy Markdown
Member Author

ibuziuk commented Sep 26, 2018

ci-test

@riuvshin
Copy link
Copy Markdown
Contributor

Results of automated E2E tests of Eclipse Che Multiuser on OCP:
Build details
Test report
docker image: eclipseche/che-server:11343
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
@ibuziuk
Copy link
Copy Markdown
Member Author

ibuziuk commented Sep 26, 2018

ci-test

@riuvshin
Copy link
Copy Markdown
Contributor

Results of automated E2E tests of Eclipse Che Multiuser on OCP:
Build details
Test report
docker image: eclipseche/che-server:11343
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

*/
public boolean isEphemeral(String workspaceId) throws InternalInfrastructureException {
try {
WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We can actually avoid using WorkspaceMnaager here since we can pass WorkspaceConfig attributes here. And we can get them from Workspace object or K8s environment object. I'm not sure we really need that but would want to hear about that from @sleshchenko @ibuziuk . This doesn't block the PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

when I tested PR on minishift for some reason K8s environment does not seem to contain WorkspaceConfig attributes, so I had to use WorkspaceManager instead

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ibuziuk I think it should be considered it as a bug because it must be there https://github.com/eclipse/che/blob/27bed82d5c57dc0c95093a1cea6043cfa47877f1/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java#L740
Otherwise, WorkspaceNext won't be working on Kubernetes infra. And three weeks ago I tested it and it worked.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@sleshchenko I will re-test and provide a comment about it. AFAIK k8sEnv.getAttributes() always returned emptyMap for me
`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok, seems I was wrong and all the config attributes are actually located in k8sEnv.getAttributes()
I will remove the usage of WorkspaceMnaager. Thanks for noticing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done, WorkspaceMnaager usage has been removed from PR

Copy link
Copy Markdown
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

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

In general LGTM
Please take a look my inlined comments

*/
@Singleton
public class EphemeralWorkspaceAdapter {
private final String EPHEMERAL_VOLUME_NAME_PREFIX = "ephemeral-che-workspace-";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

static modifier is missing

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

* PVC strategies</a>
* @see <a href="https://kubernetes.io/docs/concepts/storage/volumes/#emptydir">emptyDir</a>
*/
public static final String MOUNT_SOURCES_ATTRIBUTE = "mountSources";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Just interesting to know, is there similar functionality for Docker infrastructure?

  2. Does sources mean source code here? If yes, then actually it is related not to sources only but to all workspaces volumes, like maven repository may be declared by a user. Maybe it makes sense to choose another name for this attribute that won't be source related by that will indicate non-persistent volumes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  1. I was not able to find anything similar for docker infra. VolumesConverter just grabs all the volumes from workspace config and adds them to container config.

  2. yeah, this is a good point. Maybe persistVolumes would be a better option ? @l0rd @garagatyi wdyt ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  1. I think we don't have to support this in Docker infra. It can be implemented later in case it would be needed.
  2. persistVolumes looks good to me

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@sleshchenko attribute has been renamed to persistVolumes

return isEphemeral(workspace);
} catch (NotFoundException | ServerException e) {
throw new InternalInfrastructureException(
"Failed to load workspace info" + e.getMessage(), e);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Your message and message from exception will be merged. Consider adding space or another separator.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

* this case regardless of the PVC strategy, workspace volumes would be created as `emptyDir`.
* When a workspace Pod is removed for any reason, the data in the `emptyDir` volume is
* deleted forever
* @throws InternalInfrastructureException
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually this exception can not be thrown here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed

…ests

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
…aceManager. Renaming atribute to 'persistVolumes'

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
@ibuziuk ibuziuk changed the title Adding support of the ephemeral workspaces (using emptyDir volume instead of PVC) via 'mountSources' attribute Adding support of the ephemeral workspaces (using emptyDir volume instead of PVC) via 'persistVolumes' attribute Sep 27, 2018
@ibuziuk
Copy link
Copy Markdown
Member Author

ibuziuk commented Sep 27, 2018

ci-test

Copy link
Copy Markdown
Contributor

@amisevsk amisevsk left a comment

Choose a reason for hiding this comment

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

Great work! Looks good to me, but I have one question:

Since the persistVolumes attribute is mutable (i.e. I can start a workspace with bound volume and then later modify the config), how does this interact with workspace deletion? What's the UX if e.g. we create a workspace with persistVolumes true, do some work, set it to false, restart the workspace?

What will happen if I delete a workspace that is ephemeral? We currently don't do anything if the clean up job fails but ideally in the future we would work to ensure the PVC is cleaned up. I suppose this is more an issue with cleanup though.

@ibuziuk
Copy link
Copy Markdown
Member Author

ibuziuk commented Sep 27, 2018

@amisevsk yeah, good point. Currently there are no checks for such scenarios during cleanup. Basically, if workspace is ephmeral no pvc cleanup is performed, even if it was originally non-ephemeral. However, I believe the main usage of the ephemeral workspaces would be when the persistVolumes property is set as a config value from the very beginning, so we could probably treat the fact that pvc is not cleaned when the property is changed as an edge case for now.

Copy link
Copy Markdown
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

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

LGTM

@sleshchenko
Copy link
Copy Markdown
Member

@amisevsk Really good point 👍
@ibuziuk

we could probably treat the fact that pvc is not cleaned when the property is changed as an edge case for now.

it's OK for me to leave it as it is for now. But:
Does it lead to performance issues if we would try to clean up volumes (in both strategies, common and unique) without check if workspace is configured as ephemeral? I suppose there will be some issue with common strategy but not with unique
Should not we create an issue that such a situation is possible?

@riuvshin
Copy link
Copy Markdown
Contributor

Results of automated E2E tests of Eclipse Che Multiuser on OCP:
Build details
Test report
docker image: eclipseche/che-server:11343
https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

@ibuziuk
Copy link
Copy Markdown
Member Author

ibuziuk commented Sep 27, 2018

@sleshchenko I'm mostly worried about the common strategy since rm pod which mounts PVC would be still created and since the main goal of the ephemeral workspaces is to avoid volume mount problems always cleaning PVC would potentially bring more problems than benefits. But let me create a separate issue for the PVC cleanup situation.

@ibuziuk ibuziuk merged commit 174e1ae into eclipse-che:master Sep 27, 2018
@benoitf benoitf added this to the 6.12.0 milestone Sep 27, 2018
@l0rd
Copy link
Copy Markdown
Contributor

l0rd commented Sep 27, 2018

We should document how to configure an ephemeral workspaces in https://www.eclipse.org/che/docs/

@ibuziuk
Copy link
Copy Markdown
Member Author

ibuziuk commented Sep 27, 2018

@sleshchenko @amisevsk I have created a separate issue to start the cleanup discussion - #11391
@l0rd sure, will provide a doc PR in in the short term

nickboldt pushed a commit to nickboldt/che that referenced this pull request Oct 3, 2018
…nstead of PVC) via 'persistVolumes' attribute (eclipse-che#11343)

che eclipse-che#11350 Adding support of the ephemeral workspaces (using emptyDir volume instead of PVC) via 'persistVolumes' attribute

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement A feature request - must adhere to the feature request template. status/in-progress This issue has been taken by an engineer and is under active development.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants