-
Notifications
You must be signed in to change notification settings - Fork 13
Automatically approves change requests decreasing quotas for Openshift #207
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
Open
QuanMPhm
wants to merge
3
commits into
nerc-project:main
Choose a base branch
from
QuanMPhm:194/auto_approve_change_request
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,15 @@ | |
| from coldfront_plugin_cloud.tasks import (activate_allocation, | ||
| add_user_to_allocation, | ||
| disable_allocation, | ||
| remove_user_from_allocation) | ||
| remove_user_from_allocation, | ||
| get_allocation_usage, | ||
| approve_change_request) | ||
| from coldfront_plugin_cloud import utils | ||
| from coldfront.core.allocation.signals import (allocation_activate, | ||
| allocation_activate_user, | ||
| allocation_disable, | ||
| allocation_remove_user, | ||
| allocation_change_created, | ||
| allocation_change_approved) | ||
|
|
||
|
|
||
|
|
@@ -52,3 +56,20 @@ def activate_allocation_user_receiver(sender, **kwargs): | |
| def allocation_remove_user_receiver(sender, **kwargs): | ||
| allocation_user_pk = kwargs.get('allocation_user_pk') | ||
| remove_user_from_allocation(allocation_user_pk) | ||
|
|
||
| # TODO (Quan): How to/should we do the functional test for this? | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a functional test case for this feature? If so, how should I go about manipulating openshift resource usage for the test? |
||
| @receiver(allocation_change_created) | ||
| def allocation_change_created_receiver(sender, **kwargs): | ||
| allocation_pk = kwargs.get('allocation_pk') | ||
| allocation_change_pk = kwargs.get('allocation_change_pk') | ||
|
|
||
| if not utils.check_cr_only_decreases(allocation_change_pk): | ||
| return | ||
|
|
||
| if utils.check_cr_set_to_zero(allocation_change_pk): | ||
| return | ||
|
|
||
| allocation_quota_usage = get_allocation_usage(allocation_pk) | ||
| if allocation_quota_usage and utils.check_usage_is_lower(allocation_change_pk, allocation_quota_usage): | ||
| approve_change_request(allocation_change_pk) # Updates attributes on Coldfront side | ||
| allocation_change_approved.send(None, allocation_pk=allocation_pk, allocation_change_pk=allocation_change_pk) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should the code account for cases where a user's project has more than one ResourceQuota?
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 just checked and it's possible to create multiple resourcequotas for a namespace but in practice that should be avoided. I'd say if there's more than 1 resourcequota you should just raise an error.
Just posting this for completeness sake. When you have multiple resourcequotas your pods need to meet the limits specified by all
rq-1 allows 1 CPU and 8 Gi of memory and rq-2 allows 2 CPU and 4 Gi memory, in effect this meant I was restricted to 1 CPU and 4 Gi of memory.