Skip to content

Commit d8d4405

Browse files
committed
kexec: add kexec to replace kubectl exec
1 parent ac65cb8 commit d8d4405

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
@@ -33,6 +33,22 @@ def get_dynamic_client() -> DynamicClient:
3333
return DynamicClient(client.ApiClient())
3434

3535

36+
def kexec(pod: str, namespace: str, cmd: [str]) -> str:
37+
"""It's `kubectl exec` but with a k at the beginning so as not to conflict with python's `exec`"""
38+
sclient = get_static_client()
39+
resp = stream(
40+
sclient.connect_get_namespaced_pod_exec,
41+
pod,
42+
namespace,
43+
command=cmd,
44+
stderr=True,
45+
stdin=False,
46+
stdout=True,
47+
tty=False,
48+
)
49+
return resp
50+
51+
3652
def get_pods() -> V1PodList:
3753
sclient = get_static_client()
3854
try:

0 commit comments

Comments
 (0)