Skip to content

Allow direct communication to Openshift Quota API #205

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

Merged
merged 2 commits into from
May 6, 2025

Conversation

QuanMPhm
Copy link
Contributor

@QuanMPhm QuanMPhm commented Apr 5, 2025

Closes #187, this PR consists of two commits. The first one fixes an integration bug and will now require Openshift resources to specify two URLs, one to the account manager, and one to the Openshift API. The second implements the integration to the Openshift API.

More details in the commit messages.

Copy link
Contributor

@naved001 naved001 left a comment

Choose a reason for hiding this comment

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

mostly looks good, but just some comments/questions

It was discovered that Openshift integration did not
function because the Openshift allocation would use
the same url to make calls to both the account
manager and the Openshift API. This resulted in the
Openshift API never actually being called. Due to
poor error handling by the integration code (more details below),
this bug went undetected by the functional tests.
Appropriate fixes have been added to tests, and the
Openshift resource type now requires two URLs, one
for the account manager, and one for the Openshift API.

Regarding the poor error handling, none of the functional
Openshift test cases actually checked if the call to
`get_federated_user()` returned the expected output.
The `get_federated_user()` function itself only emits a
log message if the user is not found. This meant that
even though `get_federated_user()` never called the
Openshift API and would therefore never find the user, the test cases still passed.

Additionally, while `_openshift_user_exists()`, the function
which was supposed to call the Openshift API, does
catch the `kexc.NotFoundError`, this error is not specific
enough, as it could be caused by a 404 response made
by ANY server (in the case of our tests, the account manager).

It was also found that the `RESOURCE_IDENTITY_NAME`
attribute, which identifies the idp, was referenced in
integration code but never defined, leading to
`_openshift_identity_exists` always failing, since
`self.id_provider` would always be `None`
@QuanMPhm
Copy link
Contributor Author

_openshift_user_exists() has been edited to be a bit more robust. Some minor changes to docstrings. Changed the test_get_federated_user_not_exist test case to check for expected behavior when a kexc.NotFoundError error is actually thrown.

@QuanMPhm
Copy link
Contributor Author

The way the Openshift quota is fetched has been simplified. _get_moc_quota_from_resourcequotas() has been removed, and the weird quota object has been removed. Getting the Openshift quota now just returns a dict with quota attributes and values

@hpdempsey
Copy link

What are the circumstances under which this direct communication is needed? The description is insufficient.

@QuanMPhm
Copy link
Contributor Author

@hpdempsey Currently, this Coldfront plugin interacts with the Openshift API through a piece of middleware, openshift-acct-mgt. The motivation for this middleware, and why we're now planning to bypass it, is detailed in @knikolla's comment here. I would have explained it myself but I'm worried of wording it incorrectly. :P

@knikolla @naved001 I'll defer to you guys for more clarification

Copy link
Contributor

@naved001 naved001 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 fine to me. I know you have added some unit tests, but do you think the existing functional tests sufficiently test the resourcequota apis?

@QuanMPhm
Copy link
Contributor Author

This looks fine to me. I know you have added some unit tests, but do you think the existing functional tests sufficiently test the resourcequota apis?

@naved001 The unit test test_quota.py was added to make sure the allocator's functions returned the expected output. You're right in pointing out that the functional tests would cover the quota API, but I thought it would also be prudent to add unit tests as well.

@QuanMPhm
Copy link
Contributor Author

@naved001 @knikolla This is blocking #211, so feel free to resolve your comments and merge this whenever you can before the May maintenance.

The Openshift allocator will now only make the minimal
`resourcequota` object for each namespace, with no
support for scopes.

Most of the integration code and test cases have been
adapted from `openshift-acct-mgt`. Notable exclusions
were any code related to the `quota.json`[1],
`limits.json`[2], and quota scopes[3].

[1] https://github.com/CCI-MOC/openshift-acct-mgt/blob/master/k8s/base/quotas.json
[2] https://github.com/CCI-MOC/openshift-acct-mgt/blob/master/k8s/base/limits.json
[3] https://github.com/CCI-MOC/openshift-acct-mgt/blob/42db8f80962fd355eac1bc80a1894dc6bb824f12/acct_mgt/moc_openshift.py#L418-L431
@knikolla knikolla merged commit 5d0d1e9 into nerc-project:main May 6, 2025
6 checks passed
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.

Allow direct communication to Openshift through all quota-related endpoints
4 participants