Skip to content

Commit ddc6d4f

Browse files
committed
kexec: add kexec to replace kubectl exec
1 parent 08d29c0 commit ddc6d4f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/warnet/k8s.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ def get_dynamic_client() -> DynamicClient:
2727
return DynamicClient(client.ApiClient())
2828

2929

30+
def kexec(pod: str, namespace: str, cmd: [str]) -> str:
31+
"""It's `kubectl exec` but with a k at the beginning so as not to conflict with python's `exec`"""
32+
sclient = get_static_client()
33+
resp = stream(
34+
sclient.connect_get_namespaced_pod_exec,
35+
pod,
36+
namespace,
37+
command=cmd,
38+
stderr=True,
39+
stdin=False,
40+
stdout=True,
41+
tty=False,
42+
)
43+
return resp
44+
45+
3046
def get_pods() -> V1PodList:
3147
sclient = get_static_client()
3248
try:

0 commit comments

Comments
 (0)