Skip to content

Commit 1be19cc

Browse files
auto-cherry-pick: [v4.12] auto-cherry-pick: [v4.13] Add get_client fu… (#126)
auto-cherry-pick: [v4.12] auto-cherry-pick: [v4.13] Add get_client function (#124) auto-cherry-pick: [v4.13] Add get_client function (#122) Add get_client function (#120) Co-authored-by: redhat-qe-bot <[email protected]>
1 parent 45051fa commit 1be19cc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

ocp_utilities/infra.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
1+
import kubernetes
2+
13
from ocp_utilities.exceptions import NodeNotReadyError, NodeUnschedulableError
24
from ocp_utilities.logger import get_logger
35

46

57
LOGGER = get_logger(name=__name__)
68

79

10+
def get_client(config_file=None, config_dict=None, context=None):
11+
"""
12+
Get a kubernetes client.
13+
14+
Pass either config_file or config_dict.
15+
If none of them are passed, client will be created from default OS kubeconfig
16+
(environment variable or .kube folder).
17+
18+
Args:
19+
config_file (str): path to a kubeconfig file.
20+
config_dict (dict): dict with kubeconfig configuration.
21+
context (str): name of the context to use.
22+
23+
Returns:
24+
DynamicClient: a kubernetes client.
25+
"""
26+
if config_dict:
27+
return kubernetes.dynamic.DynamicClient(
28+
client=kubernetes.config.new_client_from_config_dict(
29+
config_dict=config_dict,
30+
context=context,
31+
)
32+
)
33+
return kubernetes.dynamic.DynamicClient(
34+
client=kubernetes.config.new_client_from_config(
35+
config_file=config_file,
36+
context=context,
37+
)
38+
)
39+
40+
841
def assert_nodes_ready(nodes):
942
"""
1043
Validates all nodes are in ready

0 commit comments

Comments
 (0)