mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 08:38:03 +01:00
fix(preheat): add precheck when delete instance
Signed-off-by: chlins <chlins.zhang@gmail.com>
This commit is contained in:
parent
19234cdb46
commit
5c433c0875
@ -887,7 +887,7 @@ paths:
|
||||
description: List preheat policies success
|
||||
headers:
|
||||
X-Total-Count:
|
||||
description: The total count of tags
|
||||
description: The total count of policies
|
||||
type: integer
|
||||
Link:
|
||||
description: Link refers to the previous page and next page
|
||||
@ -1032,7 +1032,7 @@ paths:
|
||||
description: List executions success
|
||||
headers:
|
||||
X-Total-Count:
|
||||
description: The total count of tags
|
||||
description: The total count of executions
|
||||
type: integer
|
||||
Link:
|
||||
description: Link refers to the previous page and next page
|
||||
@ -1128,7 +1128,7 @@ paths:
|
||||
description: List tasks success
|
||||
headers:
|
||||
X-Total-Count:
|
||||
description: The total count of tags
|
||||
description: The total count of tasks
|
||||
type: integer
|
||||
Link:
|
||||
description: Link refers to the previous page and next page
|
||||
|
@ -81,6 +81,22 @@ func (api *preheatAPI) DeleteInstance(ctx context.Context, params operation.Dele
|
||||
return api.SendError(ctx, err)
|
||||
}
|
||||
|
||||
// delete instance should check the instance whether be used by policies
|
||||
policies, err := api.preheatCtl.ListPolicies(ctx, &q.Query{
|
||||
Keywords: map[string]interface{}{
|
||||
"provider_id": instance.ID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return api.SendError(ctx, err)
|
||||
}
|
||||
|
||||
if len(policies) > 0 {
|
||||
return api.SendError(ctx, liberrors.New(nil).
|
||||
WithCode(liberrors.PreconditionCode).
|
||||
WithMessage("Can't delete instance %s, %d preheat policies use it as provider", instance.Name, len(policies)))
|
||||
}
|
||||
|
||||
err = api.preheatCtl.DeleteInstance(ctx, instance.ID)
|
||||
if err != nil {
|
||||
return api.SendError(ctx, err)
|
||||
@ -293,7 +309,7 @@ func (api *preheatAPI) DeletePolicy(ctx context.Context, params operation.Delete
|
||||
|
||||
// Detecting running tasks under the policy
|
||||
if err = detectRunningExecutions(executions); err != nil {
|
||||
return api.SendError(ctx, err)
|
||||
return api.SendError(ctx, liberrors.New(err).WithCode(liberrors.PreconditionCode))
|
||||
}
|
||||
|
||||
err = api.preheatCtl.DeletePolicy(ctx, policy.ID)
|
||||
|
Loading…
Reference in New Issue
Block a user