-
Notifications
You must be signed in to change notification settings - Fork 725
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 Training Client without Kube Config #1740
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,35 +36,43 @@ | |
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, | ||
no_config: bool = False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not necessary? If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tenzen-y is right . I did this since user can set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had discussion with @johnugeorge around this. I guess kube-config supports all configuration that user can set via If not, we can do this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I have not seen that use case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tenzen-y @terrytangyuan @johnugeorge I modified the PR to ignore kube config when |
||
persist_config: bool = True, | ||
): | ||
"""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. | ||
no_config: Whether to ignore the kube-config for cluster authentication. | ||
In that case, you have to provide the client configuration | ||
with the Bearer token to use the client. | ||
You can find an example here: https://github.com/kubernetes-client/python/blob/67f9c7a97081b4526470cad53576bc3b71fa6fcc/examples/remote_cluster.py#L31 | ||
persist_config: If True, config file will be updated when changed. | ||
""" | ||
|
||
self.in_cluster = None | ||
if config_file or not utils.is_running_in_k8s(): | ||
if no_config and client_configuration is None: | ||
raise ValueError( | ||
"Client configuration must be set when kube-config is ignored" | ||
) | ||
|
||
if config_file or (not utils.is_running_in_k8s() and not no_config): | ||
config.load_kube_config( | ||
config_file=config_file, | ||
context=context, | ||
client_configuration=client_configuration, | ||
persist_config=persist_config, | ||
) | ||
self.in_cluster = False | ||
else: | ||
elif not no_config: | ||
config.load_incluster_config() | ||
self.in_cluster = True | ||
|
||
self.custom_api = client.CustomObjectsApi() | ||
self.core_api = client.CoreV1Api() | ||
k8s_client = client.ApiClient(client_configuration) | ||
self.custom_api = client.CustomObjectsApi(k8s_client) | ||
self.core_api = client.CoreV1Api(k8s_client) | ||
self.api_client = ApiClient() | ||
|
||
# ------------------------------------------------------------------------ # | ||
|
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.
@andreyvelich Is it possible to set a
persistent_config
with aclient_configuration
?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
persistent_config
is used when we send client_configuration toload_kube_config()
for Kubernetes python client.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.
It makes sense.