Skip to content

Refactor to allow resource-agnostic validation#248

Open
QuanMPhm wants to merge 1 commit intonerc-project:mainfrom
QuanMPhm:239/agnostic_validate
Open

Refactor to allow resource-agnostic validation#248
QuanMPhm wants to merge 1 commit intonerc-project:mainfrom
QuanMPhm:239/agnostic_validate

Conversation

@QuanMPhm
Copy link
Copy Markdown
Contributor

@QuanMPhm QuanMPhm commented Sep 15, 2025

Closes #239. This PR consists of the last commit. Built on top of #245. More details in the commit message.

@knikolla @jtriley I have a small bug in how error handling is done when the object storage quota is missing. Just want to confirm that my change is desirable.

@QuanMPhm QuanMPhm changed the title 239/agnostic validate Refactor to allow resource-agnostic validation Sep 15, 2025
Copy link
Copy Markdown
Collaborator

@knikolla knikolla left a 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 start, but not going as far as I would like in terms of making it "resource-agnostic", as you still have a lot of if resource_name in OPENSHIFT|OPENSTACK.

Try thinking about a way to push those resource-specific functions inside the respective allocators and creating a new function in the base Allocator that serves as the abstraction.

See my comment about validate project exist.

@QuanMPhm
Copy link
Copy Markdown
Contributor Author

Note-to-self: The branch name for the original solution (before time of this comment) is 239/agnostic_validate_first

@QuanMPhm QuanMPhm force-pushed the 239/agnostic_validate branch from 9153d7b to a86da68 Compare November 11, 2025 19:33
@QuanMPhm QuanMPhm requested a review from knikolla November 11, 2025 19:33
@QuanMPhm QuanMPhm force-pushed the 239/agnostic_validate branch 2 times, most recently from 40883e2 to 129234b Compare November 11, 2025 20:08
@QuanMPhm
Copy link
Copy Markdown
Contributor Author

QuanMPhm commented Nov 11, 2025

@knikolla I've cleaned house on validate_allocations.py. Hopefully this is closer to your vision. I haven't included tests for idempotency yet. For the sake of not making this PR too complicated, I believe that should be done in a subsequent PR?

@knikolla
Copy link
Copy Markdown
Collaborator

@QuanMPhm can you resolve conflicts (and update to new quota system if necessary). I would like to have this be part of next month's update.

@QuanMPhm QuanMPhm force-pushed the 239/agnostic_validate branch from 129234b to a0ba80d Compare March 20, 2026 13:57
@QuanMPhm
Copy link
Copy Markdown
Contributor Author

@knikolla I have resolved all conflicts. This is ready to review

current_value = quota.get(quota_key, None)
current_value = parse_quota_value(current_value, attr)

self.check_and_apply_quota_attr(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this going to trigger a delete and set quota for each quota attribute that is out of date?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. The check_and_apply_quota_attr() (defined in base.py) will have the same quota validation logic as the current validate_allocation command. Out-of-date quotas will trigger a call to set_quota, which deletes and sets the quotas

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, but in this implementation the call to set quota is made for each allocation attribute, rather than setting a flag for failed_validation which calls set_quota once at the end and setting all the quotas and avoiding unnecessary deletions and recreations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yes. I noticed that inefficiency too with the validation code. I'll refactor that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@knikolla the quota validation function has been refactored

@knikolla
Copy link
Copy Markdown
Collaborator

I did a quick first pass, I like this approach much more. Will do a second pass early tomorrow morning.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors validate_allocations to be more resource-agnostic by delegating validation/sync behavior to each resource allocator (OpenStack/OpenShift/ESI), aligning behavior across resource types as requested in #239 (built on #245).

Changes:

  • Move common validation/sync logic into ResourceAllocator (user sync + quota comparison/apply helper) and implement per-resource set_project_configuration() flows.
  • Update OpenStack/OpenShift allocators to own quota validation/application (and OpenShift labels/limitrange validation).
  • Update functional/unit tests to use the new public get_project() API and to cover “new quota attribute added after allocations exist”.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/coldfront_plugin_cloud/tests/unit/openshift/test_project.py Switch to get_project() public API.
src/coldfront_plugin_cloud/tests/functional/openstack/test_allocation.py Update logging assertion target; add functional test for new quota attribute behavior.
src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py Switch to get_project() public API in functional checks.
src/coldfront_plugin_cloud/openstack.py Implement set_project_configuration() + quota validation/apply; adjust Swift quota handling.
src/coldfront_plugin_cloud/openshift.py Implement set_project_configuration() + limitrange/label/quota validation/apply; expose get_project().
src/coldfront_plugin_cloud/management/commands/validate_allocations.py Simplify command to iterate resource types and call allocator-provided configuration sync.
src/coldfront_plugin_cloud/base.py Add shared user sync + quota comparison/apply helpers and allocation_str.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@QuanMPhm QuanMPhm force-pushed the 239/agnostic_validate branch from a22bf80 to 6ebd705 Compare April 6, 2026 16:04
@QuanMPhm QuanMPhm requested a review from knikolla April 6, 2026 17:48
@knikolla knikolla requested a review from Copilot April 8, 2026 14:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

utils.set_attribute_on_allocation(self.allocation, attr, current_quota)
expected_quota = (
current_quota # To pass `current_quota != expected_quota` check
)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

In check_and_apply_quota_attr, the branch where expected_quota is None but current_quota is present sets the allocation attribute (good) but still returns failed_validation=True. That forces set_quota_config() to call set_quota() even though the cluster is already the source of truth in this case, which can cause unnecessary (and potentially disruptive) quota reapplication—especially for OpenShift where set_quota() deletes and recreates ResourceQuotas. Consider distinguishing “allocation state fixed” from “cluster state needs updating” (e.g., return False after successfully setting the allocation attribute when no cluster change is needed, or return a structured result with separate flags).

Suggested change
)
)
failed_validation = False

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree, let's treat failed_validation as a flag for when we need to perform changes to the cluster. In this case we only need to set the allocation attribute, so we can leave failed_validation as False.

Copy link
Copy Markdown
Collaborator

@knikolla knikolla left a comment

Choose a reason for hiding this comment

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

This looks good to me, the only outstanding things is the failed_validation comment by Copilot.

With regards to the Swift comments, if you want to do a bit more investigating and see if they are important to fix.

@knikolla
Copy link
Copy Markdown
Collaborator

knikolla commented Apr 8, 2026

@naved001 would appreciate a pass from you.

Quota validation will now behave the same for both resource types.
OpenStack's particular use of default quotas is reflected in a new
test in `openstack/test_allocation.py`

OpenStack integration code is slightly changed to
better handle missing object storage quotas

Much of the validation logic has been pushed into
`base.py`, `openshift.py`, and `openstack.py`
@QuanMPhm QuanMPhm force-pushed the 239/agnostic_validate branch from 6ebd705 to 30236f0 Compare April 8, 2026 18:24
@QuanMPhm QuanMPhm requested a review from knikolla April 8, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor validate_allocations to be resource-agnostic

3 participants