Skip to content

Commit f320ff9

Browse files
authored
feat: support token to login to the cluster (#2424)
1 parent e7fbfec commit f320ff9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ocp_resources/resource.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def get_client(
195195
password: str | None = None,
196196
host: str | None = None,
197197
verify_ssl: bool | None = None,
198+
token: str | None = None,
198199
) -> DynamicClient:
199200
"""
200201
Get a kubernetes client.
@@ -218,6 +219,7 @@ def get_client(
218219
password (str): password for basic auth
219220
host (str): host for the cluster
220221
verify_ssl (bool): whether to verify ssl
222+
token (str): Use token to login
221223
222224
Returns:
223225
DynamicClient: a kubernetes client.
@@ -238,6 +240,11 @@ def get_client(
238240
username=username, password=password, host=host, configuration=client_configuration
239241
)
240242

243+
elif host and token:
244+
client_configuration.host = host
245+
client_configuration.api_key = {"authorization": f"Bearer {token}"}
246+
_client = kubernetes.client.ApiClient(client_configuration)
247+
241248
# Ref: https://github.com/kubernetes-client/python/blob/v26.1.0/kubernetes/base/config/kube_config.py
242249
elif config_dict:
243250
_client = kubernetes.config.new_client_from_config_dict(

0 commit comments

Comments
 (0)