Skip to content

Commit

Permalink
fix(region): server-purge failed on pod (#21789)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi authored Dec 12, 2024
1 parent 0cdbc21 commit c1610ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions pkg/compute/models/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,12 +595,14 @@ func (c *SContainer) StartSyncStatusTask(ctx context.Context, userCred mcclient.
}

func (c *SContainer) CustomizeDelete(ctx context.Context, userCred mcclient.TokenCredential, query, data jsonutils.JSONObject) error {
return c.StartDeleteTask(ctx, userCred, "")
return c.StartDeleteTask(ctx, userCred, "", jsonutils.QueryBoolean(data, "purge", false))
}

func (c *SContainer) StartDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string) error {
func (c *SContainer) StartDeleteTask(ctx context.Context, userCred mcclient.TokenCredential, parentTaskId string, purge bool) error {
c.SetStatus(ctx, userCred, api.CONTAINER_STATUS_DELETING, "")
task, err := taskman.TaskManager.NewTask(ctx, "ContainerDeleteTask", c, userCred, nil, parentTaskId, "", nil)
task, err := taskman.TaskManager.NewTask(ctx, "ContainerDeleteTask", c, userCred, jsonutils.Marshal(map[string]interface{}{
"purge": purge,
}).(*jsonutils.JSONDict), parentTaskId, "", nil)
if err != nil {
return errors.Wrap(err, "NewTask")
}
Expand Down
18 changes: 12 additions & 6 deletions pkg/compute/tasks/container_delete_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,21 @@ func (t *ContainerDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneMode
}

func (t *ContainerDeleteTask) requestDelete(ctx context.Context, container *models.SContainer) {
isPurge := jsonutils.QueryBoolean(t.GetParams(), "purge", false)
t.SetStage("OnDeleted", nil)
if err := t.GetPodDriver().RequestDeleteContainer(ctx, t.GetUserCred(), t); err != nil {
if strings.Contains(err.Error(), "NotFoundError") {
// already deleted
t.OnDeleted(ctx, container, nil)
if isPurge {
t.ScheduleRun(nil)
return
} else {
if err := t.GetPodDriver().RequestDeleteContainer(ctx, t.GetUserCred(), t); err != nil {
if strings.Contains(err.Error(), "NotFoundError") {
// already deleted
t.OnDeleted(ctx, container, nil)
return
}
t.OnDeleteFailed(ctx, container, jsonutils.NewString(err.Error()))
return
}
t.OnDeleteFailed(ctx, container, jsonutils.NewString(err.Error()))
return
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/compute/tasks/pod_delete_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (t *PodDeleteTask) OnWaitContainerDeleted(ctx context.Context, pod *models.
return
}
curCtr := ctrs[0]
curCtr.StartDeleteTask(ctx, t.GetUserCred(), t.GetTaskId())
curCtr.StartDeleteTask(ctx, t.GetUserCred(), t.GetTaskId(), jsonutils.QueryBoolean(t.GetParams(), "purge", false))
}

func (t *PodDeleteTask) OnWaitContainerDeletedFailed(ctx context.Context, pod *models.SGuest, data jsonutils.JSONObject) {
Expand Down

0 comments on commit c1610ce

Please sign in to comment.