@@ -63,7 +63,6 @@ def __init__(
6363
6464 # State tracking
6565 self ._active_creations : set [str ] = set ()
66- self ._creation_semaphore = asyncio .Semaphore (self ._settings .K8S_MAX_CONCURRENT_PODS )
6766
6867 self .logger .info (f"KubernetesWorker initialized for namespace { self ._settings .K8S_NAMESPACE } " )
6968
@@ -104,52 +103,51 @@ async def handle_delete_pod_command(self, command: DeletePodCommandEvent) -> Non
104103
105104 async def _create_pod_for_execution (self , command : CreatePodCommandEvent ) -> None :
106105 """Create pod for execution"""
107- async with self ._creation_semaphore :
108- execution_id = command .execution_id
109- self ._active_creations .add (execution_id )
110- self .metrics .update_active_pod_creations (len (self ._active_creations ))
106+ execution_id = command .execution_id
107+ self ._active_creations .add (execution_id )
108+ self .metrics .update_active_pod_creations (len (self ._active_creations ))
111109
112- start_time = time .time ()
110+ start_time = time .time ()
113111
114- try :
115- script_content = command .script
116- entrypoint_content = await self ._get_entrypoint_script ()
112+ try :
113+ script_content = command .script
114+ entrypoint_content = await self ._get_entrypoint_script ()
117115
118- # Create ConfigMap
119- config_map = self .pod_builder .build_config_map (
120- command = command , script_content = script_content , entrypoint_content = entrypoint_content
121- )
116+ # Create ConfigMap
117+ config_map = self .pod_builder .build_config_map (
118+ command = command , script_content = script_content , entrypoint_content = entrypoint_content
119+ )
122120
123- await self ._create_config_map (config_map )
121+ await self ._create_config_map (config_map )
124122
125- pod = self .pod_builder .build_pod_manifest (command = command )
126- created_pod = await self ._create_pod (pod )
123+ pod = self .pod_builder .build_pod_manifest (command = command )
124+ created_pod = await self ._create_pod (pod )
127125
128- # Set ownerReference so K8s garbage-collects the ConfigMap when the pod is deleted
129- if created_pod and created_pod .metadata and created_pod .metadata .uid :
130- await self ._set_configmap_owner (config_map , created_pod )
126+ # Set ownerReference so K8s garbage-collects the ConfigMap when the pod is deleted
127+ if created_pod and created_pod .metadata and created_pod .metadata .uid :
128+ await self ._set_configmap_owner (config_map , created_pod )
131129
132- # Publish PodCreated event
133- await self ._publish_pod_created (command , pod )
130+ # Publish PodCreated event
131+ await self ._publish_pod_created (command , pod )
134132
135- # Update metrics
136- duration = time .time () - start_time
137- self .metrics .record_k8s_pod_creation_duration (duration , command .language )
138- self .metrics .record_k8s_pod_created ("success" , command .language )
133+ # Update metrics
134+ duration = time .time () - start_time
135+ self .metrics .record_k8s_pod_creation_duration (duration , command .language )
136+ self .metrics .record_k8s_pod_created ("success" , command .language )
139137
140- self .logger .info (
141- f"Successfully created pod { pod .metadata .name } for execution { execution_id } . "
142- f"Duration: { duration :.2f} s"
143- )
138+ self .logger .info (
139+ f"Successfully created pod { pod .metadata .name } for execution { execution_id } . "
140+ f"Duration: { duration :.2f} s"
141+ )
144142
145- except Exception as e :
146- self .logger .error (f"Failed to create pod for execution { execution_id } : { e } " , exc_info = True )
147- self .metrics .record_k8s_pod_created ("failed" , "unknown" )
148- await self ._publish_pod_creation_failed (command , str (e ))
143+ except Exception as e :
144+ self .logger .error (f"Failed to create pod for execution { execution_id } : { e } " , exc_info = True )
145+ self .metrics .record_k8s_pod_created ("failed" , "unknown" )
146+ await self ._publish_pod_creation_failed (command , str (e ))
149147
150- finally :
151- self ._active_creations .discard (execution_id )
152- self .metrics .update_active_pod_creations (len (self ._active_creations ))
148+ finally :
149+ self ._active_creations .discard (execution_id )
150+ self .metrics .update_active_pod_creations (len (self ._active_creations ))
153151
154152 async def _get_entrypoint_script (self ) -> str :
155153 """Get entrypoint script content"""
@@ -257,7 +255,7 @@ async def ensure_namespace_security(self) -> None:
257255
258256 Creates:
259257 - Default-deny NetworkPolicy for executor pods (blocks lateral movement and exfiltration)
260- - ResourceQuota to cap aggregate pod/resource consumption
258+ - ResourceQuota to cap aggregate CPU/memory consumption (no pod count limit)
261259 - Pod Security Admission labels (Restricted profile)
262260 """
263261 namespace = self ._settings .K8S_NAMESPACE
@@ -293,9 +291,8 @@ async def _ensure_executor_network_policy(self, namespace: str) -> None:
293291 self .logger .info (f"NetworkPolicy '{ policy_name } ' applied in namespace { namespace } " )
294292
295293 async def _ensure_executor_resource_quota (self , namespace : str ) -> None :
296- """Create or update ResourceQuota to cap aggregate executor pod consumption ."""
294+ """Create or update ResourceQuota to cap aggregate CPU/memory in the executor namespace ."""
297295 quota_name = "executor-quota"
298- n = self ._settings .K8S_MAX_CONCURRENT_PODS
299296
300297 quota = k8s_client .V1ResourceQuota (
301298 api_version = "v1" ,
@@ -307,11 +304,10 @@ async def _ensure_executor_resource_quota(self, namespace: str) -> None:
307304 ),
308305 spec = k8s_client .V1ResourceQuotaSpec (
309306 hard = {
310- "pods" : str (n ),
311- "requests.cpu" : f"{ int (self ._settings .K8S_POD_CPU_REQUEST .removesuffix ('m' )) * n } m" ,
312- "requests.memory" : f"{ int (self ._settings .K8S_POD_MEMORY_REQUEST .removesuffix ('Mi' )) * n } Mi" ,
313- "limits.cpu" : f"{ int (self ._settings .K8S_POD_CPU_LIMIT .removesuffix ('m' )) * n } m" ,
314- "limits.memory" : f"{ int (self ._settings .K8S_POD_MEMORY_LIMIT .removesuffix ('Mi' )) * n } Mi" ,
307+ "requests.cpu" : self ._settings .K8S_QUOTA_CPU ,
308+ "requests.memory" : self ._settings .K8S_QUOTA_MEMORY ,
309+ "limits.cpu" : self ._settings .K8S_QUOTA_CPU ,
310+ "limits.memory" : self ._settings .K8S_QUOTA_MEMORY ,
315311 },
316312 ),
317313 )
0 commit comments