Description
Add a kubeconfig_output_path parameter to get_client() that saves the kubeconfig to a file after creating the client.
Problem
Currently, when using get_client() with host + token or host + username + password, there's no way to save the resulting kubeconfig to a file. Users who need a kubeconfig file for later use (e.g., passing to other tools, reloading in a different session) have to manually construct and write it.
Solution
- New
kubeconfig_output_path parameter in get_client() — when provided, saves the kubeconfig to the specified path
- New
save_kubeconfig() utility function in ocp_resources/utils/kubeconfig.py
- Token resolution: when authenticating via username+password (OAuth), the resolved token is saved (not the credentials)
- File permissions set to
0o600 atomically (credentials never world-readable)
- File write errors are caught and logged without breaking client creation
Supported flows
| Auth method |
What gets saved |
host + username + password |
OAuth token (extracted after auth) |
host + token |
Token as-is |
config_dict |
Dict as-is |
config_file |
File content copied |
Usage
client = get_client(
host="https://api.cluster.example.com:6443",
token="sha256~xxx",
verify_ssl=False,
kubeconfig_output_path="/tmp/kubeconfig",
)
Description
Add a
kubeconfig_output_pathparameter toget_client()that saves the kubeconfig to a file after creating the client.Problem
Currently, when using
get_client()withhost + tokenorhost + username + password, there's no way to save the resulting kubeconfig to a file. Users who need a kubeconfig file for later use (e.g., passing to other tools, reloading in a different session) have to manually construct and write it.Solution
kubeconfig_output_pathparameter inget_client()— when provided, saves the kubeconfig to the specified pathsave_kubeconfig()utility function inocp_resources/utils/kubeconfig.py0o600atomically (credentials never world-readable)Supported flows
host + username + passwordhost + tokenconfig_dictconfig_fileUsage