Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #116 from Crazykev/remove-stop
Browse files Browse the repository at this point in the history
remove/stop not exist pod return success
  • Loading branch information
feiskyer authored Mar 30, 2017
2 parents c006c14 + 29e0cf6 commit ccd0653
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 1 addition & 2 deletions pkg/hyper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,9 @@ func (c *Client) RemovePod(podID string) error {
&types.PodRemoveRequest{PodID: podID},
)
if err != nil {
if resp != nil && resp.Code == errorCodePodNotFound {
if isPodNotFoundError(err, podID) || (resp != nil && resp.Code == errorCodePodNotFound) {
return nil
}

return err
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/hyper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,15 @@ func isPodSandboxRunning(client *Client, podID string) (bool, error) {

return podInfo.Status.Phase == "Running", nil
}

// isPodNotFoundError returns if error type is not found in hyperd
func isPodNotFoundError(err error, podID string) bool {
if err != nil {
errString := err.Error()
if strings.Contains(errString, fmt.Sprintf("Can not get Pod info with pod ID(%s)", podID)) ||
strings.Contains(errString, fmt.Sprintf("Can not find that Pod(%s)", podID)) {
return true
}
}
return false
}
3 changes: 1 addition & 2 deletions pkg/hyper/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,11 @@ func (h *Runtime) StopPodSandbox(podSandboxID string) error {
code, cause, err := h.client.StopPod(podSandboxID)
if err != nil {
glog.Errorf("Stop pod %s failed, code: %d, cause: %s, error: %v", podSandboxID, code, cause, err)
if err.Error() == fmt.Sprintf("Can not get Pod info with pod ID(%s)", podSandboxID) || err.Error() == fmt.Sprintf("Can not find pod(%s)", podSandboxID) {
if isPodNotFoundError(err, podSandboxID) {
// destroy the network namespace
err = h.netPlugin.TearDownPod(netNsPath, podSandboxID)
if err != nil {
glog.Errorf("Destroy pod %s network namespace failed: %v", podSandboxID, err)

}

unix.Unmount(netNsPath, unix.MNT_DETACH)
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (s *FraktiManager) RemovePodSandbox(ctx context.Context, req *kubeapi.Remov
glog.V(3).Infof("RemovePodSandbox from runtime service with request %s", req.String())

runtimeService, _ := s.getRuntimeService(req.PodSandboxId)
err := s.hyperRuntimeService.RemovePodSandbox(req.PodSandboxId)
err := runtimeService.RemovePodSandbox(req.PodSandboxId)
if err != nil {
glog.Errorf("RemovePodSandbox from %s failed: %v", runtimeService.ServiceName(), err)
return nil, err
Expand Down

0 comments on commit ccd0653

Please sign in to comment.