Skip to content

feat: add kubeconfig_output_path parameter to get_client #2678

@rnetser

Description

@rnetser

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",
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions