-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Create utility function for getting Kubernetes client #2845
Conversation
The `get_kubernetes_client` function takes two parameters and returns the initialized and authorized object with appropriate kubernetes client. It can be used across entire application.
After extracting the logic of initializing and authorizing the kubernetes client, the tests responsible for checking this functionality were moved to `utilities/test_kubernetes.py`.
15a04be
to
8d907cb
Compare
8d907cb
to
c6988bc
Compare
I missed that this |
Thanks for the big PR @pcieslinski! Yeah the client is mocked heavily for these tests and with this new utility could definitely be cleaned up / possibly separated into a test fixture. |
30bfd78
to
3e1aacf
Compare
@joshmeek I know that this PR has unfortunately grown quite a lot and can be difficult to check, but it is mainly because the same code was used in many places. I have improved the tests for all Kubernetes tasks and put the mocked Kubernetes client in the fixture. :) |
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.
Thanks @pcieslinski, this looks good to me! Love to see that many deleted lines of code :).
Thanks for contributing to Prefect!
Please describe your work and make sure your PR:
changes/
directory (if appropriate)docs/outline.toml
for API reference docs (if appropriate)Note that your PR will not be reviewed unless all three boxes are checked.
What does this PR change?
While working on resolving this issue: #2281, I discovered a lot of duplicate code and tests. I managed to extract into a separate utility function the logic responsible for creating and authorizing the client for Kubernetes, which is used in the task library.
get_kubernetes_client
was created in a similar way toget_boto_client
. Thanks to this, I wanted to be consistent with the rest of the codebase.Example of use:
When the logic of creating and authorizing a client for Kubernetes was extracted into a separate function, some of the tests from the tasks were removed. Now all testing is done at the level of function
get_kubernetes_client
.Why is this PR important?
Generally, this PR strives to stick to good software development practices and DRY principle. Thanks to this refactor we will have gathered in one place the logic to create and authorize the client for Kubernetes. We can use this part of the code throughout the codebase.
By removing duplicate tests, the project code will be easier to maintain.