1919import tempfile
2020import os
2121import random
22- import time
22+ import logging
2323from typing import List
2424
2525from airflow import models
@@ -66,11 +66,7 @@ def trigger_oom_failure(info, pod_name: str, namespace: str):
6666 the expected connection loss during an OOM event.
6767 """
6868
69- wait_time = 60
70- print (
71- f"Waiting { wait_time } s for Pod { pod_name } to stabilize before OOM Test..."
72- )
73- time .sleep (wait_time )
69+ logging .info (f"Checking status for Pod { pod_name } ..." )
7470
7571 python_logic = (
7672 "import time\n "
@@ -87,19 +83,26 @@ def trigger_oom_failure(info, pod_name: str, namespace: str):
8783 env ["KUBECONFIG" ] = temp_config_file .name
8884
8985 credentials_cmd = jobset .Command .get_credentials_command (info )
86+
87+ wait_cmd = (
88+ f"kubectl wait --for=condition=Ready pod/{ pod_name } "
89+ f"-n { namespace } --timeout=60s"
90+ )
91+
9092 exec_cmd = (
9193 f'kubectl exec { pod_name } -n { namespace } -- python3 -c "{ python_logic } "'
9294 )
9395
94- full_command = f"{ credentials_cmd } && { exec_cmd } "
96+ full_command = f"{ credentials_cmd } && { wait_cmd } && { exec_cmd } "
9597
9698 try :
97- print (f"Blasting { pod_name } memory now..." )
99+ logging . info (f"Blasting { pod_name } memory now..." )
98100 subprocess .run_exec (full_command , env = env )
99101 except subprocess .ProcessKilledException :
100- print (f"Success: Pod { pod_name } was OOMKilled." )
102+ logging . info (f"Success: Pod { pod_name } was OOMKilled." )
101103 except Exception as e :
102- print (f"Connection lost or other error: { e } " )
104+ logging .error (f"Connection lost or other error: { e } " )
105+ raise e
103106
104107
105108@task
@@ -120,7 +123,7 @@ def pick_random_pod(active_pods: List[str]) -> str:
120123 if not active_pods :
121124 raise ValueError ("No pods found to attack!" )
122125 chosen_pod = random .choice (active_pods )
123- print (f"Randomly selected pod for OOM test: { chosen_pod } " )
126+ logging . info (f"Randomly selected pod for OOM test: { chosen_pod } " )
124127 return chosen_pod
125128
126129
0 commit comments