mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix: fail to delete pod not found at host (#20991)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -16,6 +16,7 @@ package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -41,6 +42,11 @@ func (t *ContainerDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneMode
|
||||
func (t *ContainerDeleteTask) requestDelete(ctx context.Context, container *models.SContainer) {
|
||||
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)
|
||||
return
|
||||
}
|
||||
t.OnDeleteFailed(ctx, container, jsonutils.NewString(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ package tasks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
@@ -34,11 +36,18 @@ type ContainerSyncStatusTask struct {
|
||||
}
|
||||
|
||||
func (t *ContainerSyncStatusTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
|
||||
t.SetStage("OnSyncStatus", nil)
|
||||
if err := t.GetPodDriver().RequestSyncContainerStatus(ctx, t.GetUserCred(), t); err != nil {
|
||||
log.Errorf("t.GetPodDriver().RequestSyncContainerStatus fail %s", err)
|
||||
if strings.Contains(err.Error(), "NotFoundError") {
|
||||
// already deleted
|
||||
obj.(*models.SContainer).SetStatus(ctx, t.GetUserCred(), api.CONTAINER_STATUS_UNKNOWN, "not found")
|
||||
t.SetStageComplete(ctx, nil)
|
||||
return
|
||||
}
|
||||
t.OnSyncStatusFailed(ctx, obj.(*models.SContainer), jsonutils.NewString(err.Error()))
|
||||
return
|
||||
}
|
||||
t.SetStage("OnSyncStatus", nil)
|
||||
}
|
||||
|
||||
func (t *ContainerSyncStatusTask) OnSyncStatus(ctx context.Context, container *models.SContainer, data jsonutils.JSONObject) {
|
||||
@@ -49,6 +58,7 @@ func (t *ContainerSyncStatusTask) OnSyncStatus(ctx context.Context, container *m
|
||||
}
|
||||
|
||||
func (t *ContainerSyncStatusTask) OnSyncStatusFailed(ctx context.Context, container *models.SContainer, reason jsonutils.JSONObject) {
|
||||
log.Errorf("ContainerSyncStatusTask.OnSyncStatusFailed fail %s", reason.String())
|
||||
container.SetStatus(ctx, t.GetUserCred(), api.CONTAINER_STATUS_SYNC_STATUS_FAILED, reason.String())
|
||||
t.SetStageFailed(ctx, reason)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/models"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
)
|
||||
|
||||
type PodDeleteTask struct {
|
||||
@@ -45,6 +44,11 @@ func (t *PodDeleteTask) OnWaitContainerDeleted(ctx context.Context, pod *models.
|
||||
pod.SetStatus(ctx, t.GetUserCred(), api.POD_STATUS_DELETING_CONTAINER, "")
|
||||
ctrs, err := models.GetContainerManager().GetContainersByPod(pod.GetId())
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "NotFoundError") {
|
||||
// already deleted
|
||||
t.OnContainerDeleted(ctx, pod)
|
||||
return
|
||||
}
|
||||
t.OnWaitContainerDeletedFailed(ctx, pod, jsonutils.NewString(errors.Wrap(err, "GetContainersByPod").Error()))
|
||||
return
|
||||
}
|
||||
@@ -74,7 +78,7 @@ func (t *PodDeleteTask) OnContainerDeleted(ctx context.Context, pod *models.SGue
|
||||
return
|
||||
}
|
||||
if err := drv.StartGuestStopTask(pod, ctx, t.GetUserCred(), nil, t.GetTaskId()); err != nil {
|
||||
if errors.Cause(err) == httperrors.ErrNotFound {
|
||||
if strings.Contains(err.Error(), "NotFoundError") {
|
||||
t.OnPodStopped(ctx, pod, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -879,11 +879,17 @@ func (m *SGuestManager) GetGuestStatus(ctx context.Context, params interface{})
|
||||
sid := params.(string)
|
||||
status := m.getStatus(sid)
|
||||
guest, _ := m.GetServer(sid)
|
||||
|
||||
body := jsonutils.NewDict()
|
||||
if guest != nil {
|
||||
body.Set("power_status", jsonutils.NewString(GetPowerStates(guest)))
|
||||
|
||||
if guest == nil {
|
||||
body.Set("status", jsonutils.NewString(status))
|
||||
hostutils.TaskComplete(ctx, body)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
body.Set("power_status", jsonutils.NewString(GetPowerStates(guest)))
|
||||
|
||||
return guest.HandleGuestStatus(ctx, status, body)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user