Skip to content
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

Merging the account manager into the plugin #134

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

QuanMPhm
Copy link
Contributor

@QuanMPhm QuanMPhm commented Jan 17, 2024

Closes #137, I am merging the account manager into the plugin. Most changes are in openshift.py

src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/acct_mgt/defaults.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/acct_mgt/moc_openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
Copy link
Contributor

@larsks larsks left a comment

Choose a reason for hiding this comment

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

I would like to see this series of commits cleaned up:

  • Each commit should have a clear purpose and should be clearly described. There should be a short descriptive subject followed by information about why the changes are necessary.
  • There should not be multiple commits with the same subject.
  • Please check messages for spelling and grammar.
  • Typo fixes and other cleanups should be folded into other commits.

@QuanMPhm
Copy link
Contributor Author

I will likely need to close this PR and open a new one, hopefully with a lot more cleanup and up to standard

@larsks
Copy link
Contributor

larsks commented Jan 24, 2024

I will likely need to close this PR and open a new one

Please don't do that. Just update this PR. If you need help with that, let me know.

@QuanMPhm QuanMPhm marked this pull request as ready for review January 30, 2024 17:39
@knikolla
Copy link
Collaborator

Great work on cleaning up the commits. One final advice. You can see that when you merged the main branch back into this working branch, it introduced a series of extraneous commits into your history. It's generally better to rebase your working branch into the main branch. Please look into and remove the merge commits from your history. I suggest you backup your work too, just in case something goes wrong modifying the history.

See this Stackoverflow answer quickly describing the differences between the two workflows https://stackoverflow.com/questions/804115/when-do-you-use-git-rebase-instead-of-git-merge

@QuanMPhm QuanMPhm force-pushed the iss_114 branch 3 times, most recently from 69b3b6a to e06e459 Compare January 31, 2024 17:58
@QuanMPhm
Copy link
Contributor Author

@knikolla I've resolved all comments so far. The things I see that are left to do is to rename the OS_AUTH_URL attribute, and update the test files as you see fit. I will wait for further instructions.

src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
raise NotFound(f"{response.status_code}: {response.text}")
elif 'already exists' in response.text:
raise Conflict(f"{response.status_code}: {response.text}")
openshift_token = os.getenv(f"OPENSHIFT_{var_name}_TOKEN")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing in a token, can we just read the configuration from a kubeconfig file? Using config.load_kubeconfig() will work with both the in-cluster configuration for a serviceaccount and with a local kubeconfig file (and respects the KUBECONFIG environment variable).

If you don't want to change this now, it may be worth turning into an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@knikolla What is your opinion on this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For now we can keep passing the token as an environment variable, as that preserves the original behavior. We can work out a better way in the future.

Copy link

@joachimweyl joachimweyl Jul 26, 2024

Choose a reason for hiding this comment

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

@QuanMPhm please create an issue to resolve this later, link it here and then resolve this conversation.

src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
self.logger.info(f"msg: user created ({unique_id})")
return

raise Conflict("400: " + f"user already exists ({unique_id})")
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid including http response codes in our text messages. We're already providing the response code to the client as part of the HTTP response. Also, we should be returning a 409 status code on conflicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@larsks @knikolla Currently I am handling the exceptions the same way that the current code is handling it, by passing the response and the message. Should I still remove all error codes?

As for whether the Conflict exception returns the appropriate code, that doesn't seem to be implemented yet. Conflict is simply subclassed from the built-in Exception class. Let me know if I should implement it.

Copy link
Contributor Author

@QuanMPhm QuanMPhm Mar 5, 2024

Choose a reason for hiding this comment

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

From what I've read about Django exception handling, there is no way to raise custom exceptions in Django which returns custom status codes in the http response, especially not in a signal handler, as is the case with openshift.py.
When an error is raised (as in the example you highlighted), Django by default returns 500 as the status code.

The only way I can see to return appropriate errors is by including it in the error message. Please tell me if I missed something and if there is a clean way of returning custom errors. Otherwise, I've edited the error messages to contain the appropriate status code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to return custom error codes in Django. These exceptions are purely for the code itself to handle, not any external user.

Choose a reason for hiding this comment

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

@QuanMPhm if you have made this change please resolve this conversation or ask one of those in the conversation to resolve it if you are not sure.

Copy link
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.

I'll do another pass later today as I ran out of time now.

src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
self.logger.info(f"msg: user created ({unique_id})")
return

raise Conflict("409: " + f"user already exists ({unique_id})")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this line as it will always be called regardless. We don't need to raise an exception here in case of conflict.

The purpose of the exception block below is to make sure that all Conflict exceptions thrown by the Kubernetes client are caught so that execution of the code can continue.

Please add some functional tests to see what happens in cases of attempting to create an already existing user and make sure the code continues to work.

Choose a reason for hiding this comment

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

@QuanMPhm if you removed the line please resolve this conversation.

test-requirements.txt Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
src/coldfront_plugin_cloud/openshift.py Outdated Show resolved Hide resolved
return self.check_response(r)
if self.client.project_exists(project_id):
self.logger.info(f"msg: project exists ({project_id})")
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're not returning anything here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems the purpose of _get_role and _get_project is purely to check if the role or project has been created on the Openshift cluster. I've actually broke the test cases here by converting the exception raise to a log message.

Choose a reason for hiding this comment

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

@knikolla what are your thoughts on this approach?

@QuanMPhm QuanMPhm force-pushed the iss_114 branch 3 times, most recently from c446f15 to e76b430 Compare March 12, 2024 18:22
@joachimweyl
Copy link

Blocked on Functional test.

@QuanMPhm
Copy link
Contributor Author

@knikolla I have brought over the unit tests from the account manager and hopefully resolved all problems with the functional tests

@joachimweyl
Copy link

@QuanMPhm what are the next steps?

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.

Copy over the code from openshift-acct-mgt with minimum changes
4 participants