Skip to content

Commit

Permalink
[SDK] Use Training Client without Kube Config (#1740)
Browse files Browse the repository at this point in the history
* [SDK] Use Training Client without Kube Config

* Skip kube-config when using client config
  • Loading branch information
andreyvelich authored Jan 24, 2023
1 parent 307f17a commit 0736e93
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions sdk/python/kubeflow/training/api/training_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,32 @@
class TrainingClient(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,
):
"""TrainingClient 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.custom_api = client.CustomObjectsApi()
self.core_api = client.CoreV1Api()
# 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()

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

# ------------------------------------------------------------------------ #
Expand Down

0 comments on commit 0736e93

Please sign in to comment.