-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
che #18369 Deleting the common PVC if there are no workspaces left for a given user #18713
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.
In general looks good but there are corner cases:
- We have different namespace strategy, one of them is common predefined, like
che
, then multiple users use the same PVC. - Do we have a guarantee that the same PVC was not used for another purpose apart from Che?
The safe solution I see here: PVC-clean-up job apart from removing the files is able to remove PVC if there are no files left.
* Removes PVC by name. | ||
* | ||
* @param name the name of the PVC | ||
* @throws InfrastructureException |
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 add a few words
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.
there are a few words already ;-)
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.
oh, you probably mean smth. like when any error occurs while removing
for exeption
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
Page<WorkspaceImpl> workspaces = workspaceManager.getWorkspaces(userId, false, 30, 0); | ||
if (workspaces.isEmpty()) { | ||
log.debug("User '{}' has no more workspaces left", userId); | ||
userHasNoWorkspaces = 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.
Personally I prefer early return
private boolean userHasNoWorkspaces() {
String userId = getSessionUserIdOrUndefined();
if (!"undefined".equals(userId)) {
try {
Page<WorkspaceImpl> workspaces = workspaceManager.getWorkspaces(userId, false, 1, 0);
if (workspaces.isEmpty()) {
log.debug("User '{}' has no more workspaces left", userId);
return true;
}
} catch (ServerException e) {
log.error(
"Unable to get the number of workspaces for user '{}'. Cause: {}",
userId,
e.getMessage(),
e);
}
}
return false;
}
Also, I don't think you need to fetch 30 workspaces, even one should be enough.
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.
good point regarding 30, but I preferred to use the default configuration.
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
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.
good point regarding 30, but I preferred to use the default configuration.
Since it's not a constant but just a hard-coded value, there is no guarantee that it will continue to be a default.
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.
right, but currently it is default on the service level, anyway changed to 1
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.
I think that is unnecessary logic. userid can be che
in single-user mode or real in multi-user mode. It can't be "undefined"
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.
I suppose it may work in the wrong way when admin removes user and their workspaces.
@sleshchenko @sparkoo @metlos wdyt. Maybe we should iterate over all workspace and check if that is the last workspace in the concrete k8s namespace. Of cause, if there are no workspaces at all it's safe to delete pvc.
it should fix the issue above
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.
Anonymus user will be "undefined" based on implementation.
Handling the case when the common PVC is used across multiple users ('workspaceNamespaceDefault' without placeholders is defined) - 8e02f78
I'm not aware of this strategy, could you clarify how is it possible to configure a common PVC for multiple users?
Well, I would expect that |
Just deploy Che with Che Operator where spec:
server:
workspaceNamespaceDefault: che |
@sleshchenko @sparkoo @metlos wdyt. Maybe we should iterate over all workspace and check if that is the last workspace in the concrete k8s namespace. Of cause, if there are no workspaces at all - it's safe to delete pvc. |
@sleshchenko could you clarify what is the expected flow when the property is enabled. Tested with latest Che against OCP 4.6 and this setup fails with permissions issue:
Is it expected that cluster-admin grants manually the required permissions for che SA for a namespace specified in |
It's not expected and it used to work. @tolusha Do you remember the changes in that area? BTW It works fine on minikube |
Handling the case when the common PVC is used across multiple users ('workspaceNamespaceDefault' without placeholders is defined) - 8e02f78 |
Sonar check is failing:
any ideas on how the permissions are expected to be granted? |
That is ok for the fork. |
@ibuziuk @sleshchenko |
} | ||
|
||
private String getSessionUserIdOrUndefined() { | ||
final Subject subject = EnvironmentContext.getCurrent().getSubject(); |
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 code is not needed. You always should have a valid subject.
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.
not following, why there is an isAnonymous()
method in this case?
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.
removed this method and improved the case when the subject is anonymous
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.
I haven't had a chance to test, but I did have a question: are there any issues around timing when removing the common PVC? i.e. if I delete my last workspace and then immediately try to create a new one, will a terminating claim-che-workspace
PVC block workspace creation for some length of time?
I seem to recall running into issues waiting for garbage collection on PVCs in e.g. minikube, but don't know the details further than that.
So this is considered to be an expected setup and all the PRs would be marked as red? |
Red, but it's not mandatory. |
pretty ugly IMO ;-) Wondering how the plugin can be configured to be green for PRs (currently it is false positive) |
@amisevsk yeah, this looks like a very good corner case to handle |
…ces left for a given user Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
…oss multiple users ('workspaceNamespaceDefault' without placeholders is defined) Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
❌ E2E Happy path tests failed ❗ See Details
Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1)
|
code moved to https://github.com/eclipse-che/che-server/ |
❌ E2E Happy path tests failed ❗ See Details
Tested with Eclipse Che on K8S (minikube v1.1.1)
Eclipse Che QE channel: https://mattermost.eclipse.org/eclipse/channels/eclipse-che-qe |
Closing in favour of eclipse-che/che-server#16 |
What does this PR do?
Deleting the common PVC if there are no workspaces left for a given user
What issues does this PR fix or reference?
#18369
How to test this PR?
image -
quay.io/ibuziuk/che-server:che-18369
PR Checklist
As the author of this Pull Request I made sure that:
What issues does this PR fix or reference
andHow to test this PR
completedReviewers
Reviewers, please comment how you tested the PR when approving it.