Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix container not found error #183

Merged
merged 5 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
evol262 marked this conversation as resolved.
Show resolved Hide resolved
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)) {
evol262 marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

Expand Down