@@ -110,45 +110,58 @@ async def get_deployment_marker(kube_client, generated_data, marker: str):
110110
111111async def run_pod_with_args (kube_client : AsyncClient , namespace , image_name , pod_name , args ):
112112 pod = Pod (
113- metadata = ObjectMeta (name = pod_name + "-" + str (int (time .time ()* 1000 )), namespace = namespace ),
114- spec = PodSpec (restartPolicy = "Never" ,
115- containers = [Container (name = "cmd" , image = image_name , args = args ,
116- securityContext = SecurityContext (
117- seccompProfile = SeccompProfile (type = "RuntimeDefault" ),
118- capabilities = Capabilities (drop = ["ALL" ]),
119- readOnlyRootFilesystem = True ,
120- allowPrivilegeEscalation = False ,
121- runAsNonRoot = True ,
122- runAsUser = 3000 ,
123- runAsGroup = 3000 ,
124- ),
125- )
126- ])
127- )
113+ metadata = ObjectMeta (name = pod_name + "-" + str (int (time .time () * 1000 )), namespace = namespace ),
114+ spec = PodSpec (
115+ restartPolicy = "Never" ,
116+ containers = [
117+ Container (
118+ name = "cmd" ,
119+ image = image_name ,
120+ args = args ,
121+ securityContext = SecurityContext (
122+ seccompProfile = SeccompProfile (type = "RuntimeDefault" ),
123+ capabilities = Capabilities (drop = ["ALL" ]),
124+ readOnlyRootFilesystem = True ,
125+ allowPrivilegeEscalation = False ,
126+ runAsNonRoot = True ,
127+ runAsUser = 3000 ,
128+ runAsGroup = 3000 ,
129+ ),
130+ )
131+ ],
132+ ),
133+ )
134+ assert pod .metadata
135+ assert pod .metadata .name
136+ assert pod .metadata .namespace
128137 try :
129138 await kube_client .create (pod )
130139 start_time = time .time ()
131140 now = time .time ()
132141 completed = False
133142 while start_time + 30 > now and not completed :
134143 found_pod = await kube_client .get (Pod , name = pod .metadata .name , namespace = pod .metadata .namespace )
135- if (found_pod .status .containerStatuses
144+ if (
145+ found_pod .status
146+ and found_pod .status .containerStatuses
136147 and found_pod .status .containerStatuses [0 ].lastState
137148 and found_pod .status .containerStatuses [0 ].lastState .terminated
138- and found_pod .status .containerStatuses [0 ].lastState .terminated .reason == "Completed" ):
149+ and found_pod .status .containerStatuses [0 ].lastState .terminated .reason == "Completed"
150+ ):
139151 completed = True
140152 else :
141153 now = time .time ()
142154 await asyncio .sleep (1 )
143155 else :
144156 if start_time + 30 > now :
145- raise RuntimeError (f"Pod { pod .metadata .name } did not start in time "
146- f"(failed after { time .time () - now } seconds), "
147- f"pod status: { found_pod .status } " )
157+ raise RuntimeError (
158+ f"Pod { pod .metadata .name } did not start in time "
159+ f"(failed after { time .time () - now } seconds), "
160+ f"pod status: { found_pod .status } "
161+ )
148162
149163 log_lines = ""
150- async for log_line in kube_client .log (pod .metadata .name , namespace = pod .metadata .namespace ,
151- container = "cmd" ):
164+ async for log_line in kube_client .log (pod .metadata .name , namespace = pod .metadata .namespace , container = "cmd" ):
152165 log_lines += log_line
153166 return log_lines
154167 finally :
0 commit comments