mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-18 13:41:21 +01:00
Merge pull request #12668 from chlins/fix/preheat-delete-policy
fix(preheat): check running executions when delete policy
This commit is contained in:
commit
4f90ebce9f
@ -275,6 +275,27 @@ func (api *preheatAPI) DeletePolicy(ctx context.Context, params operation.Delete
|
||||
return api.SendError(ctx, err)
|
||||
}
|
||||
|
||||
detectRunningExecutions := func(executions []*task.Execution) error {
|
||||
for _, exec := range executions {
|
||||
if exec.Status == job.RunningStatus.String() {
|
||||
return fmt.Errorf("execution %d under the policy %s is running, stop it and retry", exec.ID, policy.Name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
executions, err := api.executionCtl.List(ctx, &q.Query{Keywords: map[string]interface{}{
|
||||
"vendor_type": job.P2PPreheat,
|
||||
"vendor_id": policy.ID,
|
||||
}})
|
||||
if err != nil {
|
||||
return api.SendError(ctx, err)
|
||||
}
|
||||
|
||||
// Detecting running tasks under the policy
|
||||
if err = detectRunningExecutions(executions); err != nil {
|
||||
return api.SendError(ctx, err)
|
||||
}
|
||||
|
||||
err = api.preheatCtl.DeletePolicy(ctx, policy.ID)
|
||||
if err != nil {
|
||||
return api.SendError(ctx, err)
|
||||
|
Loading…
Reference in New Issue
Block a user