-
Notifications
You must be signed in to change notification settings - Fork 44
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
Added in cluster configuration support #271
Added in cluster configuration support #271
Conversation
src/codeflare_sdk/cluster/auth.py
Outdated
try: | ||
config.load_kube_config() | ||
except config.config_exception.ConfigException: | ||
try: | ||
config.load_incluster_config() | ||
except: |
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.
Anyway to avoid this nested try/except
statement? Can we check that we are in the cluster before trying to load the config?
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.
Added a check to see if the config file exists and if not a check to see if we are in the cluster before using load_incluster_config
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 I think that's much better. I'll test it this morning.
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.
Looks good, just one change needed for error handling
src/codeflare_sdk/cluster/auth.py
Outdated
elif "KUBERNETES_PORT" in os.environ: | ||
config.load_incluster_config() | ||
else: | ||
print( |
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 think this needs to raise a PermissionsError
instead of just printing. Either that, or we need to catch the ConnectionRefusedError/MaxRetryError
caused by this later down the road with the Kubernetes API. Since we are no longer blocking here, we are currently getting:
MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /apis/mcad.ibm.com/v1beta1/namespaces/openshift-operators/appwrappers (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 61] Connection refused'))
instead of:
PermissionError: Action not permitted, have you put in correct/up-to-date auth credentials?
on various API calls
976b96c
to
d8fb799
Compare
@Bobbins228 I rebased the PR 😅 |
@Bobbins228 FYI, this PR worked with my in-cluster script using codeflare SDK :) |
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.
Looks good, just one more error handling suggestion
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.
LGTM
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Maxusmusti The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
77a82e2
into
project-codeflare:main
Issue link
Closes #255
What changes have been made
Changed the config check method to load the config file first and if it doesn't work it will try load the in cluster configuration.
Verification steps
poetry build
pip uninstall codeflare-sdk -y
pip install codeflare_sdk-0.0.0.dev0-py3-none-any.whl
cluster.up()
should work without a kubernetes config file and default to using theincluster_config
Checks