Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions core/container_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"time"

"github.com/Mirantis/cri-dockerd/libdocker"
"github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
)
Expand Down Expand Up @@ -77,7 +76,7 @@ func (ds *dockerService) clearContainerCleanupInfo(containerID string) {
delete(ds.containerCleanupInfos, containerID)
}

func getContainerTimestamps(r *types.ContainerJSON) (time.Time, time.Time, time.Time, error) {
func getContainerTimestamps(r *dockercontainer.InspectResponse) (time.Time, time.Time, time.Time, error) {
var createdAt, startedAt, finishedAt time.Time
var err error

Expand Down
23 changes: 11 additions & 12 deletions core/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"strings"
"time"

dockertypes "github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
dockerimagetypes "github.com/docker/docker/api/types/image"

Expand Down Expand Up @@ -51,7 +50,7 @@ func imageToRuntimeAPIImage(image *dockerimagetypes.Summary, pinned bool) (*runt
}, nil
}

func imageInspectToRuntimeAPIImage(image *dockertypes.ImageInspect, pinned bool) (*runtimeapi.Image, error) {
func imageInspectToRuntimeAPIImage(image *dockerimagetypes.InspectResponse, pinned bool) (*runtimeapi.Image, error) {
if image == nil || image.Config == nil {
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime API image")
}
Expand All @@ -77,7 +76,7 @@ type verboseImageInfo struct {
ImageSpec imagespec.Image `json:"imageSpec"`
}

func imageInspectToRuntimeAPIImageInfo(image *dockertypes.ImageInspect, history []dockerimagetypes.HistoryResponseItem) (map[string]string, error) {
func imageInspectToRuntimeAPIImageInfo(image *dockerimagetypes.InspectResponse, history []dockerimagetypes.HistoryResponseItem) (map[string]string, error) {
info := make(map[string]string)

createdAt, err := libdocker.ParseDockerTimestamp(image.Created)
Expand Down Expand Up @@ -117,7 +116,7 @@ type verboseContainerInfo struct {
Pid int `json:"pid"`
}

func containerInspectToRuntimeAPIContainerInfo(container *dockertypes.ContainerJSON) (map[string]string, error) {
func containerInspectToRuntimeAPIContainerInfo(container *dockercontainer.InspectResponse) (map[string]string, error) {
info := make(map[string]string)

cti := &verboseContainerInfo{
Expand Down Expand Up @@ -153,7 +152,7 @@ func toRuntimeAPIConfig(config *dockercontainer.Config) imagespec.ImageConfig {
}
}

func toRuntimeAPIRootFS(rootfs dockertypes.RootFS) imagespec.RootFS {
func toRuntimeAPIRootFS(rootfs dockerimagetypes.RootFS) imagespec.RootFS {
digests := []digest.Digest{}
for _, l := range rootfs.Layers {
digest, _ := digest.Parse(l)
Expand Down Expand Up @@ -183,7 +182,7 @@ func toRuntimeAPIHistory(history []dockerimagetypes.HistoryResponseItem) []image
return result
}

func toPullableImageID(id string, image *dockertypes.ImageInspect) string {
func toPullableImageID(id string, image *dockerimagetypes.InspectResponse) string {
// Default to the image ID, but if RepoDigests is not empty, use
// the first digest instead.
imageID := DockerImageIDPrefix + id
Expand All @@ -193,7 +192,7 @@ func toPullableImageID(id string, image *dockertypes.ImageInspect) string {
return imageID
}

func toRuntimeAPIContainer(c *dockertypes.Container) (*runtimeapi.Container, error) {
func toRuntimeAPIContainer(c *dockercontainer.Summary) (*runtimeapi.Container, error) {
state := toRuntimeAPIContainerState(c.Status)
if len(c.Names) == 0 {
return nil, fmt.Errorf("unexpected empty container name: %+v", c)
Expand All @@ -204,7 +203,7 @@ func toRuntimeAPIContainer(c *dockertypes.Container) (*runtimeapi.Container, err
}
labels, annotations := extractLabels(c.Labels)
sandboxID := c.Labels[sandboxIDLabelKey]
// The timestamp in dockertypes.Container is in seconds.
// The timestamp in dockercontainer.Summary is in seconds.
createdAt := c.Created * int64(time.Second)
return &runtimeapi.Container{
Id: c.ID,
Expand Down Expand Up @@ -235,7 +234,7 @@ func toDockerContainerStatus(state runtimeapi.ContainerState) string {
}

func toRuntimeAPIContainerState(state string) runtimeapi.ContainerState {
// Parse the state string in dockertypes.Container. This could break when
// Parse the state string in dockercontainer.Summary. This could break when
// we upgrade docker.
switch {
case strings.HasPrefix(state, libdocker.StatusRunningPrefix):
Expand All @@ -250,7 +249,7 @@ func toRuntimeAPIContainerState(state string) runtimeapi.ContainerState {
}

func toRuntimeAPISandboxState(state string) runtimeapi.PodSandboxState {
// Parse the state string in dockertypes.Container. This could break when
// Parse the state string in dockercontainer.Summary. This could break when
// we upgrade docker.
switch {
case strings.HasPrefix(state, libdocker.StatusRunningPrefix):
Expand All @@ -260,7 +259,7 @@ func toRuntimeAPISandboxState(state string) runtimeapi.PodSandboxState {
}
}

func containerToRuntimeAPISandbox(c *dockertypes.Container) (*runtimeapi.PodSandbox, error) {
func containerToRuntimeAPISandbox(c *dockercontainer.Summary) (*runtimeapi.PodSandbox, error) {
state := toRuntimeAPISandboxState(c.Status)
if len(c.Names) == 0 {
return nil, fmt.Errorf("unexpected empty sandbox name: %+v", c)
Expand All @@ -270,7 +269,7 @@ func containerToRuntimeAPISandbox(c *dockertypes.Container) (*runtimeapi.PodSand
return nil, err
}
labels, annotations := extractLabels(c.Labels)
// The timestamp in dockertypes.Container is in seconds.
// The timestamp in dockercontainer.Summary is in seconds.
createdAt := c.Created * int64(time.Second)
return &runtimeapi.PodSandbox{
Id: c.ID,
Expand Down
8 changes: 4 additions & 4 deletions core/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package core
import (
"testing"

dockertypes "github.com/docker/docker/api/types"
dockerimagetypes "github.com/docker/docker/api/types/image"
"github.com/stretchr/testify/assert"

runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
Expand All @@ -45,19 +45,19 @@ func TestConvertDockerStatusToRuntimeAPIState(t *testing.T) {
func TestConvertToPullableImageID(t *testing.T) {
testCases := []struct {
id string
image *dockertypes.ImageInspect
image *dockerimagetypes.InspectResponse
expected string
}{
{
id: "image-1",
image: &dockertypes.ImageInspect{
image: &dockerimagetypes.InspectResponse{
RepoDigests: []string{"digest-1"},
},
expected: DockerPullableImageIDPrefix + "digest-1",
},
{
id: "image-2",
image: &dockertypes.ImageInspect{
image: &dockerimagetypes.InspectResponse{
RepoDigests: []string{},
},
expected: DockerImageIDPrefix + "image-2",
Expand Down
3 changes: 1 addition & 2 deletions core/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"io"
"time"

dockertypes "github.com/docker/docker/api/types"
"k8s.io/client-go/tools/remotecommand"

dockercontainer "github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -77,7 +76,7 @@ type NativeExecHandler struct{}
func (*NativeExecHandler) ExecInContainer(
ctx context.Context,
client libdocker.DockerClientInterface,
container *dockertypes.ContainerJSON,
container *dockercontainer.InspectResponse,
cmd []string,
stdin io.Reader,
stdout, stderr io.WriteCloser,
Expand Down
21 changes: 10 additions & 11 deletions core/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"testing"
"time"

dockertypes "github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
Expand All @@ -37,7 +36,7 @@ func TestExecInContainer(t *testing.T) {
testcases := []struct {
description string
timeout time.Duration
returnCreateExec1 *dockertypes.IDResponse
returnCreateExec1 *dockercontainer.ExecCreateResponse
returnCreateExec2 error
returnStartExec error
returnInspectExec1 *dockercontainer.ExecInspect
Expand All @@ -46,7 +45,7 @@ func TestExecInContainer(t *testing.T) {
}{{
description: "ExecInContainer succeeds",
timeout: time.Minute,
returnCreateExec1: &dockertypes.IDResponse{ID: "12345678"},
returnCreateExec1: &dockercontainer.ExecCreateResponse{ID: "12345678"},
returnCreateExec2: nil,
returnStartExec: nil,
returnInspectExec1: &dockercontainer.ExecInspect{
Expand All @@ -71,7 +70,7 @@ func TestExecInContainer(t *testing.T) {
}, {
description: "StartExec returns an error",
timeout: time.Minute,
returnCreateExec1: &dockertypes.IDResponse{ID: "12345678"},
returnCreateExec1: &dockercontainer.ExecCreateResponse{ID: "12345678"},
returnCreateExec2: nil,
returnStartExec: fmt.Errorf("error in StartExec()"),
returnInspectExec1: nil,
Expand All @@ -80,7 +79,7 @@ func TestExecInContainer(t *testing.T) {
}, {
description: "InspectExec returns an error",
timeout: time.Minute,
returnCreateExec1: &dockertypes.IDResponse{ID: "12345678"},
returnCreateExec1: &dockercontainer.ExecCreateResponse{ID: "12345678"},
returnCreateExec2: nil,
returnStartExec: nil,
returnInspectExec1: nil,
Expand All @@ -89,7 +88,7 @@ func TestExecInContainer(t *testing.T) {
}, {
description: "ExecInContainer returns context DeadlineExceeded",
timeout: 1 * time.Second,
returnCreateExec1: &dockertypes.IDResponse{ID: "12345678"},
returnCreateExec1: &dockercontainer.ExecCreateResponse{ID: "12345678"},
returnCreateExec2: nil,
returnStartExec: context.DeadlineExceeded,
returnInspectExec1: &dockercontainer.ExecInspect{
Expand Down Expand Up @@ -150,13 +149,13 @@ func TestExecInContainer(t *testing.T) {
}
}

func getFakeContainerJSON() *dockertypes.ContainerJSON {
return &dockertypes.ContainerJSON{
ContainerJSONBase: &dockertypes.ContainerJSONBase{
func getFakeContainerJSON() *dockercontainer.InspectResponse {
return &dockercontainer.InspectResponse{
ContainerJSONBase: &dockercontainer.ContainerJSONBase{
ID: "12345678",
Name: "fake_name",
Image: "fake_image",
State: &dockertypes.ContainerState{
State: &dockercontainer.State{
Running: false,
ExitCode: 0,
Pid: 100,
Expand All @@ -167,6 +166,6 @@ func getFakeContainerJSON() *dockertypes.ContainerJSON {
HostConfig: nil,
},
Config: nil,
NetworkSettings: &dockertypes.NetworkSettings{},
NetworkSettings: &dockercontainer.NetworkSettings{},
}
}
3 changes: 1 addition & 2 deletions core/helpers_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"

"github.com/blang/semver"
dockertypes "github.com/docker/docker/api/types"
dockerbackend "github.com/docker/docker/api/types/backend"
dockercontainer "github.com/docker/docker/api/types/container"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -89,7 +88,7 @@ func (ds *dockerService) determinePodIPBySandboxID(uid string) []string {
return nil
}

func getNetworkNamespace(c *dockertypes.ContainerJSON) (string, error) {
func getNetworkNamespace(c *dockercontainer.InspectResponse) (string, error) {
if c.State.Pid == 0 {
// Docker reports pid 0 for an exited container.
return "", fmt.Errorf("cannot find network namespace for the terminated container %q", c.ID)
Expand Down
4 changes: 2 additions & 2 deletions core/helpers_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"fmt"

"github.com/blang/semver"
dockertypes "github.com/docker/docker/api/types"
dockerbackend "github.com/docker/docker/api/types/backend"
dockercontainer "github.com/docker/docker/api/types/container"
"github.com/sirupsen/logrus"
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
)
Expand Down Expand Up @@ -61,7 +61,7 @@ func (ds *dockerService) determinePodIPBySandboxID(uid string) []string {
return nil
}

func getNetworkNamespace(c *dockertypes.ContainerJSON) (string, error) {
func getNetworkNamespace(c *dockercontainer.InspectResponse) (string, error) {
return "", fmt.Errorf("unsupported platform")
}

Expand Down
3 changes: 1 addition & 2 deletions core/helpers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"golang.org/x/sys/windows/registry"

"github.com/blang/semver"
dockertypes "github.com/docker/docker/api/types"
dockerbackend "github.com/docker/docker/api/types/backend"
dockercontainer "github.com/docker/docker/api/types/container"
dockerfilters "github.com/docker/docker/api/types/filters"
Expand Down Expand Up @@ -138,7 +137,7 @@ func (ds *dockerService) determinePodIPBySandboxID(sandboxID string) []string {
return nil
}

func getNetworkNamespace(c *dockertypes.ContainerJSON) (string, error) {
func getNetworkNamespace(c *dockercontainer.InspectResponse) (string, error) {
// Currently in windows there is no identifier exposed for network namespace
// Like docker, the referenced container id is used to figure out the network namespace id internally by the platform
// so returning the docker networkMode (which holds container:<ref containerid> for network namespace here
Expand Down
13 changes: 6 additions & 7 deletions core/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"testing"

dockertypes "github.com/docker/docker/api/types"
dockerimage "github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/stretchr/testify/assert"
Expand All @@ -33,11 +32,11 @@ import (

func TestRemoveImage(t *testing.T) {
tests := map[string]struct {
image dockertypes.ImageInspect
image dockerimage.InspectResponse
calledDetails []libdocker.CalledDetail
}{
"single tag": {
dockertypes.ImageInspect{ID: "1111", RepoTags: []string{"foo"}},
dockerimage.InspectResponse{ID: "1111", RepoTags: []string{"foo"}},
[]libdocker.CalledDetail{
libdocker.NewCalledDetail("inspect_image", nil),
libdocker.NewCalledDetail(
Expand All @@ -51,7 +50,7 @@ func TestRemoveImage(t *testing.T) {
},
},
"multiple tags": {
dockertypes.ImageInspect{ID: "2222", RepoTags: []string{"foo", "bar"}},
dockerimage.InspectResponse{ID: "2222", RepoTags: []string{"foo", "bar"}},
[]libdocker.CalledDetail{
libdocker.NewCalledDetail("inspect_image", nil),
libdocker.NewCalledDetail(
Expand All @@ -69,7 +68,7 @@ func TestRemoveImage(t *testing.T) {
},
},
"single tag multiple repo digests": {
dockertypes.ImageInspect{
dockerimage.InspectResponse{
ID: "3333",
RepoTags: []string{"foo"},
RepoDigests: []string{"foo@3333", "example.com/foo@3333"},
Expand Down Expand Up @@ -98,7 +97,7 @@ func TestRemoveImage(t *testing.T) {
},
},
"no tags multiple repo digests": {
dockertypes.ImageInspect{
dockerimage.InspectResponse{
ID: "4444",
RepoTags: []string{},
RepoDigests: []string{"foo@4444", "example.com/foo@4444"},
Expand Down Expand Up @@ -127,7 +126,7 @@ func TestRemoveImage(t *testing.T) {
for name, test := range tests {
t.Run(name, func(t *testing.T) {
ds, fakeDocker, _ := newTestDockerService()
fakeDocker.InjectImageInspects([]dockertypes.ImageInspect{test.image})
fakeDocker.InjectImageInspects([]dockerimage.InspectResponse{test.image})
ds.RemoveImage(
getTestCTX(),
&runtimeapi.RemoveImageRequest{Image: &runtimeapi.ImageSpec{Image: test.image.ID}},
Expand Down
Loading