Skip to content

Commit efc4bad

Browse files
committed
k8s: add get_pod and get_service
1 parent 7eed5ef commit efc4bad

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
@@ -52,6 +52,20 @@ def kexec(pod: str, namespace: str, cmd: [str]) -> str:
5252
return resp
5353

5454

55+
def get_service(name: str, namespace: Optional[str] = None) -> V1Service:
56+
sclient = get_static_client()
57+
if not namespace:
58+
namespace = get_default_namespace()
59+
return sclient.read_namespaced_service(name=name, namespace=namespace)
60+
61+
62+
def get_pod(name: str, namespace: Optional[str] = None) -> V1Pod:
63+
sclient = get_static_client()
64+
if not namespace:
65+
namespace = get_default_namespace()
66+
return sclient.read_namespaced_pod(name=name, namespace=namespace)
67+
68+
5569
def get_pods() -> V1PodList:
5670
sclient = get_static_client()
5771
try:

0 commit comments

Comments
 (0)