Skip to content

Commit

Permalink
Merge pull request #183 from davidwtf/fix/container-not-found
Browse files Browse the repository at this point in the history
Fix container not found error
  • Loading branch information
evol262 authored Apr 19, 2023
2 parents ac2fabe + ac510b9 commit a7a00a5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion core/container_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package core

import (
"context"

"github.com/Mirantis/cri-dockerd/libdocker"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -55,7 +57,7 @@ func (ds *dockerService) ListContainers(
}
}
containers, err := ds.client.ListContainers(opts)
if err != nil {
if err != nil && !libdocker.IsContainerNotFoundError(err) {
return nil, err
}
// Convert docker to runtime api containers.
Expand Down
10 changes: 9 additions & 1 deletion core/container_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ package core

import (
"context"
v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
"time"

"github.com/Mirantis/cri-dockerd/libdocker"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
)

// StopContainer stops a running container with a grace period (i.e., timeout).
Expand All @@ -29,6 +34,9 @@ func (ds *dockerService) StopContainer(
) (*v1.StopContainerResponse, error) {
err := ds.client.StopContainer(r.ContainerId, time.Duration(r.Timeout)*time.Second)
if err != nil {
if libdocker.IsContainerNotFoundError(err) {
err = status.Error(codes.NotFound, err.Error())
}
return nil, err
}
return &v1.StopContainerResponse{}, nil
Expand Down
4 changes: 3 additions & 1 deletion core/sandbox_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package core

import (
"context"

"github.com/Mirantis/cri-dockerd/libdocker"
"github.com/Mirantis/cri-dockerd/store"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
Expand Down Expand Up @@ -78,7 +80,7 @@ func (ds *dockerService) ListPodSandbox(
}

containers, err := ds.client.ListContainers(opts)
if err != nil {
if err != nil && !libdocker.IsContainerNotFoundError(err) {
return nil, err
}

Expand Down

0 comments on commit a7a00a5

Please sign in to comment.