Skip to content

Commit 6d8ffa0

Browse files
committed
k8s: add get_pod and get_service
1 parent 16f869a commit 6d8ffa0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/warnet/k8s.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import yaml
99
from kubernetes import client, config, watch
1010
from kubernetes.client.api import CoreV1Api
11-
from kubernetes.client.models import V1DeleteOptions, V1Pod, V1PodList, V1Status
11+
from kubernetes.client.models import V1DeleteOptions, V1Pod, V1PodList, V1Service, V1Status
1212
from kubernetes.client.rest import ApiException
1313
from kubernetes.dynamic import DynamicClient
1414
from kubernetes.stream import stream
@@ -44,6 +44,20 @@ def kexec(pod: str, namespace: str, cmd: [str]) -> str:
4444
return resp
4545

4646

47+
def get_service(name: str, namespace: Optional[str] = None) -> V1Service:
48+
sclient = get_static_client()
49+
if not namespace:
50+
namespace = get_default_namespace()
51+
return sclient.read_namespaced_service(name=name, namespace=namespace)
52+
53+
54+
def get_pod(name: str, namespace: Optional[str] = None) -> V1Pod:
55+
sclient = get_static_client()
56+
if not namespace:
57+
namespace = get_default_namespace()
58+
return sclient.read_namespaced_pod(name=name, namespace=namespace)
59+
60+
4761
def get_pods() -> V1PodList:
4862
sclient = get_static_client()
4963
try:

0 commit comments

Comments
 (0)