@@ -266,32 +266,33 @@ async def handle_benchmark_status_changed(benchmark, **kwargs):
266
266
succeeded = benchmark .status .phase == api .BenchmarkPhase .COMPLETED
267
267
benchmark_set .status .completed [benchmark .metadata .name ] = succeeded
268
268
_ = await save_benchmark_status (benchmark_set )
269
- return
270
- # The only other phase we want to act on is summarising
271
- if benchmark .status .phase != api .BenchmarkPhase .SUMMARISING :
272
- return
273
- # Allow the benchmark to summarise itself and save
274
- try :
275
- benchmark .summarise ()
276
- except errors .PodResultsIncompleteError as exc :
277
- # Convert this into a temporary error with a short delay, as it is likely
278
- # to be resolved quickly
279
- raise kopf .TemporaryError (str (exc ), delay = 1 )
280
- else :
281
- benchmark = await save_benchmark_status (benchmark )
282
- # Once the benchmark summary has been saved successfully, we can delete the managed resources
283
- for ref in benchmark .status .managed_resources :
284
- ekapi = EK_CLIENT .api (ref .api_version )
285
- resource = await ekapi .resource (ref .kind )
286
- await resource .delete (ref .name , namespace = benchmark .metadata .namespace )
287
- # Make sure to delete the priority class
288
- ekapi = EK_CLIENT .api ("scheduling.k8s.io/v1" )
289
- resource = await ekapi .resource ("priorityclasses" )
290
- _ = await resource .delete (benchmark .status .priority_class_name )
291
- # Once the resources are deleted, we can mark the benchmark as completed
292
- benchmark .status .phase = api .BenchmarkPhase .COMPLETED
293
- benchmark .status .managed_resources = []
294
- _ = await save_benchmark_status (benchmark )
269
+ elif benchmark .status .phase == api .BenchmarkPhase .RUNNING :
270
+ if not benchmark .status .started_at :
271
+ benchmark .status .started_at = datetime .datetime .now ()
272
+ _ = await save_benchmark_status (benchmark )
273
+ elif benchmark .status .phase == api .BenchmarkPhase .SUMMARISING :
274
+ # Allow the benchmark to summarise itself and save
275
+ try :
276
+ benchmark .summarise ()
277
+ except errors .PodResultsIncompleteError as exc :
278
+ # Convert this into a temporary error with a short delay, as it is likely
279
+ # to be resolved quickly
280
+ raise kopf .TemporaryError (str (exc ), delay = 1 )
281
+ else :
282
+ benchmark = await save_benchmark_status (benchmark )
283
+ # Once the benchmark summary has been saved successfully, we can delete the managed resources
284
+ for ref in benchmark .status .managed_resources :
285
+ ekapi = EK_CLIENT .api (ref .api_version )
286
+ resource = await ekapi .resource (ref .kind )
287
+ await resource .delete (ref .name , namespace = benchmark .metadata .namespace )
288
+ # Make sure to delete the priority class
289
+ ekapi = EK_CLIENT .api ("scheduling.k8s.io/v1" )
290
+ resource = await ekapi .resource ("priorityclasses" )
291
+ _ = await resource .delete (benchmark .status .priority_class_name )
292
+ # Once the resources are deleted, we can mark the benchmark as completed
293
+ benchmark .status .phase = api .BenchmarkPhase .COMPLETED
294
+ benchmark .status .managed_resources = []
295
+ _ = await save_benchmark_status (benchmark )
295
296
296
297
297
298
@benchmark_handler (kopf .on .delete )
@@ -349,6 +350,8 @@ async def handle_job_event(benchmark, body, **kwargs):
349
350
"""
350
351
Executes whenever an event occurs for a Volcano job that is part of a benchmark.
351
352
"""
353
+ if type == "DELETED" :
354
+ return
352
355
# If the benchmark is completed, there is nothing to do
353
356
if benchmark .status .phase == api .BenchmarkPhase .COMPLETED :
354
357
return
@@ -422,7 +425,7 @@ async def handle_endpoints_event(type, benchmark, body, name, namespace, **kwarg
422
425
},
423
426
"data" : {
424
427
"hosts" : hosts ,
425
- }
428
+ },
426
429
},
427
430
namespace = configmap .metadata .namespace
428
431
)
0 commit comments