Skip to content

Commit

Permalink
fix container not found error, see: Mirantis/cri-dockerd#183
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwtf committed May 11, 2023
1 parent 7ececb3 commit ed72318
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/kubelet/dockershim/docker_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
dockercontainer "github.com/docker/docker/api/types/container"
dockerfilters "github.com/docker/docker/api/types/filters"
dockerstrslice "github.com/docker/docker/api/types/strslice"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"

runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
Expand Down Expand Up @@ -64,7 +66,7 @@ func (ds *dockerService) ListContainers(_ context.Context, r *runtimeapi.ListCon
}
}
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 Expand Up @@ -308,6 +310,9 @@ func (ds *dockerService) StartContainer(_ context.Context, r *runtimeapi.StartCo
func (ds *dockerService) StopContainer(_ context.Context, r *runtimeapi.StopContainerRequest) (*runtimeapi.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 &runtimeapi.StopContainerResponse{}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/dockershim/docker_sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (ds *dockerService) ListPodSandbox(_ context.Context, r *runtimeapi.ListPod
}

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

Expand Down

0 comments on commit ed72318

Please sign in to comment.