3
3
from typing import List , Dict , TYPE_CHECKING
4
4
5
5
from gefyra .exceptions import CommandTimeoutError , GefyraBridgeError
6
+ from kubernetes .client .exceptions import ApiException
6
7
7
8
if TYPE_CHECKING :
8
9
from gefyra .configuration import ClientConfiguration
@@ -37,12 +38,12 @@ def get_pods_to_intercept(
37
38
38
39
39
40
def check_workloads (
40
- pods_to_intercept ,
41
+ pods_to_intercept : dict ,
41
42
workload_type : str ,
42
43
workload_name : str ,
43
44
container_name : str ,
44
45
namespace : str ,
45
- config ,
46
+ config : "ClientConfiguration" ,
46
47
):
47
48
from gefyra .cluster .resources import check_pod_valid_for_bridge
48
49
@@ -57,11 +58,45 @@ def check_workloads(
57
58
f"Could not find { workload_type } /{ workload_name } to bridge. Available"
58
59
f" { workload_type } : { ', ' .join (cleaned_names )} "
59
60
)
61
+
60
62
if container_name not in [
61
63
container for c_list in pods_to_intercept .values () for container in c_list
62
64
]:
63
65
raise RuntimeError (f"Could not find container { container_name } to bridge." )
64
66
67
+ # Validate workload and probes
68
+ api = config .K8S_APP_API
69
+ try :
70
+ if workload_type == "deployment" :
71
+ workload = api .read_namespaced_deployment (workload_name , namespace )
72
+ elif workload_type == "statefulset" :
73
+ workload = api .read_namespaced_stateful_set (workload_name , namespace )
74
+ elif workload_type == "daemonset" :
75
+ workload = api .read_namespaced_daemon_set (workload_name , namespace )
76
+ else :
77
+ raise RuntimeError (f"Unsupported workload type: { workload_type } " )
78
+ except ApiException as e :
79
+ raise RuntimeError (f"Error fetching workload { workload_type } /{ workload_name } : { e } " )
80
+
81
+ containers = workload .spec .template .spec .containers
82
+ target_container = next (
83
+ (c for c in containers if c .name == container_name ), None
84
+ )
85
+ if not target_container :
86
+ raise RuntimeError (f"Container { container_name } not found in workload { workload_type } /{ workload_name } ." )
87
+
88
+ def validate_http_probe (probe , probe_type ):
89
+ if probe and probe .http_get is None :
90
+ raise RuntimeError (
91
+ f"{ probe_type } in container { container_name } does not use httpGet. "
92
+ f"Only HTTP-based probes are supported."
93
+ )
94
+
95
+ # Check for HTTP probes only
96
+ validate_http_probe (target_container .liveness_probe , "LivenessProbe" )
97
+ validate_http_probe (target_container .readiness_probe , "ReadinessProbe" )
98
+ validate_http_probe (target_container .startup_probe , "StartupProbe" )
99
+
65
100
for name in pod_names :
66
101
check_pod_valid_for_bridge (config , name , namespace , container_name )
67
102
0 commit comments