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

[SDK] Use Katib Client without Kube Config #2098

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions sdk/python/v1beta1/kubeflow/katib/api/katib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,33 @@
class KatibClient(object):
def __init__(
self,
config_file=None,
context=None,
client_configuration=None,
persist_config=True,
config_file: str = None,
context: str = None,
client_configuration: client.Configuration = None,
):
"""KatibClient constructor.

Args:
config_file: Name of the kube-config file. Defaults to ~/.kube/config.
config_file: Path to the kube-config file. Defaults to ~/.kube/config.
context: Set the active context. Defaults to current_context from the kube-config.
client_configuration: The kubernetes.client.Configuration to set configs to.
persist_config: If True, config file will be updated when changed.
client_configuration: Client configuration for cluster authentication.
You have to provide valid configuration with Bearer token or
with username and password.
You can find an example here: https://github.com/kubernetes-client/python/blob/67f9c7a97081b4526470cad53576bc3b71fa6fcc/examples/remote_cluster.py#L31
"""

self.in_cluster = None
if config_file or not utils.is_running_in_k8s():
config.load_kube_config(
config_file=config_file,
context=context,
client_configuration=client_configuration,
persist_config=persist_config,
)
self.in_cluster = False
else:
config.load_incluster_config()
self.in_cluster = True
self.in_cluster = False
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a var, in_cluster?

Copy link
Member Author

@andreyvelich andreyvelich Jan 24, 2023

Choose a reason for hiding this comment

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

@tenzen-y Currently, we use it when Katib is deployed as part of Kubeflow Central Dashboard: https://github.com/kubeflow/katib/blob/master/sdk/python/v1beta1/kubeflow/katib/api/katib_client.py#L112-L124.
Although, it can generate incorrect links when user relies on load_incluster_config() and doesn't run it from Kubeflow Notebooks.
We will discuss about it in the future.

Copy link
Member

Choose a reason for hiding this comment

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

I see.
Thanks for clarifying! Could you create an issue to keep tracking this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, let's track this.

# If client configuration is not set, use kube-config to access Kubernetes APIs.
if client_configuration is None:
# Load kube-config or in-cluster config.
if config_file or not utils.is_running_in_k8s():
config.load_kube_config(config_file=config_file, context=context)
else:
config.load_incluster_config()
self.in_cluster = True

self.custom_api = client.CustomObjectsApi()
k8s_client = client.ApiClient(client_configuration)
self.custom_api = client.CustomObjectsApi(k8s_client)
self.api_client = ApiClient()

def _is_ipython(self):
Expand Down