Skip to content

Commit

Permalink
Fix terrible interface name
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Barry committed Dec 10, 2021
1 parent 11daf83 commit 31843be
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
vendor
src/cri-dockerd
4 changes: 2 additions & 2 deletions src/cm/container_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var (
)

// NewContainerManager creates a new instance of ContainerManager
func NewContainerManager(cgroupsName string, client libdocker.Interface) ContainerManager {
func NewContainerManager(cgroupsName string, client libdocker.DockerClientInterface) ContainerManager {
return &containerManager{
cgroupsName: cgroupsName,
client: client,
Expand All @@ -65,7 +65,7 @@ func NewContainerManager(cgroupsName string, client libdocker.Interface) Contain

type containerManager struct {
// Docker client.
client libdocker.Interface
client libdocker.DockerClientInterface
// Name of the cgroups.
cgroupsName string
// Manager for the cgroups.
Expand Down
2 changes: 1 addition & 1 deletion src/cm/container_manager_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type unsupportedContainerManager struct {
}

// NewContainerManager creates a new instance of ContainerManager
func NewContainerManager(_ string, _ libdocker.Interface) ContainerManager {
func NewContainerManager(_ string, _ libdocker.DockerClientInterface) ContainerManager {
return &unsupportedContainerManager{}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cm/container_manager_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type containerManager struct {
}

// NewContainerManager creates a new instance of ContainerManager
func NewContainerManager(_ string, _ libdocker.Interface) ContainerManager {
func NewContainerManager(_ string, _ libdocker.DockerClientInterface) ContainerManager {
return &containerManager{}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/docker_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (ds *dockerService) RemoveImage(
}

// getImageRef returns the image digest if exists, or else returns the image ID.
func getImageRef(client libdocker.Interface, image string) (string, error) {
func getImageRef(client libdocker.DockerClientInterface, image string) (string, error) {
img, err := client.InspectImageByRef(image)
if err != nil {
return "", err
Expand Down
4 changes: 2 additions & 2 deletions src/core/docker_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ type ClientConfig struct {

// NewDockerClientFromConfig create a docker client from given configure
// return nil if nil configure is given.
func NewDockerClientFromConfig(config *ClientConfig) libdocker.Interface {
func NewDockerClientFromConfig(config *ClientConfig) libdocker.DockerClientInterface {
if config != nil {
// Create docker client.
client := libdocker.ConnectToDockerOrDie(
Expand Down Expand Up @@ -338,7 +338,7 @@ func NewDockerService(
}

type dockerService struct {
client libdocker.Interface
client libdocker.DockerClientInterface
os kubecontainer.OSInterface
podSandboxImage string
streamingRuntime *streamingRuntime
Expand Down
6 changes: 3 additions & 3 deletions src/core/docker_streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
)

type streamingRuntime struct {
client libdocker.Interface
client libdocker.DockerClientInterface
execHandler ExecHandler
}

Expand Down Expand Up @@ -199,7 +199,7 @@ func (ds *dockerService) PortForward(
}

func checkContainerStatus(
client libdocker.Interface,
client libdocker.DockerClientInterface,
containerID string,
) (*dockertypes.ContainerJSON, error) {
container, err := client.InspectContainer(containerID)
Expand All @@ -213,7 +213,7 @@ func checkContainerStatus(
}

func attachContainer(
client libdocker.Interface,
client libdocker.DockerClientInterface,
containerID string,
stdin io.Reader,
stdout, stderr io.WriteCloser,
Expand Down
4 changes: 2 additions & 2 deletions src/core/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
type ExecHandler interface {
ExecInContainer(
ctx context.Context,
client libdocker.Interface,
client libdocker.DockerClientInterface,
container *dockertypes.ContainerJSON,
cmd []string,
stdin io.Reader,
Expand Down Expand Up @@ -73,7 +73,7 @@ type NativeExecHandler struct{}
// ExecInContainer executes the cmd in container using the Docker's exec API
func (*NativeExecHandler) ExecInContainer(
ctx context.Context,
client libdocker.Interface,
client libdocker.DockerClientInterface,
container *dockertypes.ContainerJSON,
cmd []string,
stdin io.Reader,
Expand Down
4 changes: 2 additions & 2 deletions src/core/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func getUserFromImageUser(imageUser string) (*int64, string) {
// See #40443. Sometimes even removal may fail with "no such container" error.
// In that case we have to create the container with a randomized name.
func recoverFromCreationConflictIfNeeded(
client libdocker.Interface,
client libdocker.DockerClientInterface,
createConfig dockertypes.ContainerCreateConfig,
err error,
) (*dockercontainer.ContainerCreateCreatedBody, error) {
Expand Down Expand Up @@ -339,7 +339,7 @@ func transformStartContainerError(err error) error {
}

// ensureSandboxImageExists pulls the sandbox image when it's not present.
func ensureSandboxImageExists(client libdocker.Interface, image string) error {
func ensureSandboxImageExists(client libdocker.DockerClientInterface, image string) error {
_, err := client.InspectImageByRef(image)
if err == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions src/libdocker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const (
FakeDockerEndpoint = "fake://"
)

// Interface is an abstract interface for testability. It abstracts the interface of docker client.
type Interface interface {
// DockerClientInterface is an abstract interface for testability. It abstracts the interface of docker client.
type DockerClientInterface interface {
ListContainers(options dockertypes.ContainerListOptions) ([]dockertypes.Container, error)
InspectContainer(id string) (*dockertypes.ContainerJSON, error)
InspectContainerWithSize(id string) (*dockertypes.ContainerJSON, error)
Expand Down Expand Up @@ -98,7 +98,7 @@ func getDockerClient(dockerEndpoint string) (*dockerapi.Client, error) {
func ConnectToDockerOrDie(
dockerEndpoint string,
requestTimeout, imagePullProgressDeadline time.Duration,
) Interface {
) DockerClientInterface {
client, err := getDockerClient(dockerEndpoint)
if err != nil {
klog.ErrorS(err, "Couldn't connect to docker")
Expand Down
22 changes: 11 additions & 11 deletions src/libdocker/fake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (f *FakeDockerClient) popError(op string) error {
return nil
}

// ListContainers is a test-spy implementation of Interface.ListContainers.
// ListContainers is a test-spy implementation of DockerClientInterface.ListContainers.
// It adds an entry "list" to the internal method call record.
func (f *FakeDockerClient) ListContainers(
options dockertypes.ContainerListOptions,
Expand Down Expand Up @@ -389,7 +389,7 @@ func toDockerContainerStatus(state string) string {
}
}

// InspectContainer is a test-spy implementation of Interface.InspectContainer.
// InspectContainer is a test-spy implementation of DockerClientInterface.InspectContainer.
// It adds an entry "inspect" to the internal method call record.
func (f *FakeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJSON, error) {
f.Lock()
Expand All @@ -406,7 +406,7 @@ func (f *FakeDockerClient) InspectContainer(id string) (*dockertypes.ContainerJS
return nil, fmt.Errorf("container %q not found", id)
}

// InspectContainerWithSize is a test-spy implementation of Interface.InspectContainerWithSize.
// InspectContainerWithSize is a test-spy implementation of DockerClientInterface.InspectContainerWithSize.
// It adds an entry "inspect" to the internal method call record.
func (f *FakeDockerClient) InspectContainerWithSize(id string) (*dockertypes.ContainerJSON, error) {
f.Lock()
Expand All @@ -423,7 +423,7 @@ func (f *FakeDockerClient) InspectContainerWithSize(id string) (*dockertypes.Con
return nil, fmt.Errorf("container %q not found", id)
}

// InspectImageByRef is a test-spy implementation of Interface.InspectImageByRef.
// InspectImageByRef is a test-spy implementation of DockerClientInterface.InspectImageByRef.
// It adds an entry "inspect" to the internal method call record.
func (f *FakeDockerClient) InspectImageByRef(name string) (*dockertypes.ImageInspect, error) {
f.Lock()
Expand All @@ -438,7 +438,7 @@ func (f *FakeDockerClient) InspectImageByRef(name string) (*dockertypes.ImageIns
return nil, ImageNotFoundError{name}
}

// InspectImageByID is a test-spy implementation of Interface.InspectImageByID.
// InspectImageByID is a test-spy implementation of DockerClientInterface.InspectImageByID.
// It adds an entry "inspect" to the internal method call record.
func (f *FakeDockerClient) InspectImageByID(name string) (*dockertypes.ImageInspect, error) {
f.Lock()
Expand Down Expand Up @@ -476,7 +476,7 @@ func GetFakeContainerID(name string) string {
return strconv.FormatUint(hash.Sum64(), 16)
}

// CreateContainer is a test-spy implementation of Interface.CreateContainer.
// CreateContainer is a test-spy implementation of DockerClientInterface.CreateContainer.
// It adds an entry "create" to the internal method call record.
func (f *FakeDockerClient) CreateContainer(
c dockertypes.ContainerCreateConfig,
Expand Down Expand Up @@ -511,7 +511,7 @@ func (f *FakeDockerClient) CreateContainer(
return &dockercontainer.ContainerCreateCreatedBody{ID: id}, nil
}

// StartContainer is a test-spy implementation of Interface.StartContainer.
// StartContainer is a test-spy implementation of DockerClientInterface.StartContainer.
// It adds an entry "start" to the internal method call record.
func (f *FakeDockerClient) StartContainer(id string) error {
f.Lock()
Expand Down Expand Up @@ -558,7 +558,7 @@ func (f *FakeDockerClient) StartContainer(id string) error {
return nil
}

// StopContainer is a test-spy implementation of Interface.StopContainer.
// StopContainer is a test-spy implementation of DockerClientInterface.StopContainer.
// It adds an entry "stop" to the internal method call record.
func (f *FakeDockerClient) StopContainer(id string, timeout time.Duration) error {
f.Lock()
Expand Down Expand Up @@ -644,7 +644,7 @@ func (f *FakeDockerClient) UpdateContainerResources(
return nil
}

// Logs is a test-spy implementation of Interface.Logs.
// Logs is a test-spy implementation of DockerClientInterface.Logs.
// It adds an entry "logs" to the internal method call record.
func (f *FakeDockerClient) Logs(
id string,
Expand All @@ -665,7 +665,7 @@ func (f *FakeDockerClient) isAuthorizedForImage(image string, auth dockertypes.A
}
}

// PullImage is a test-spy implementation of Interface.PullImage.
// PullImage is a test-spy implementation of DockerClientInterface.PullImage.
// It adds an entry "pull" to the internal method call record.
func (f *FakeDockerClient) PullImage(
image string,
Expand Down Expand Up @@ -884,7 +884,7 @@ func (f *FakeDockerClient) InjectImageHistory(
// FakeDockerPuller is meant to be a simple wrapper around FakeDockerClient.
// Please do not add more functionalities to it.
type FakeDockerPuller struct {
client Interface
client DockerClientInterface
}

func (f *FakeDockerPuller) Pull(image string, _ []v1.Secret) error {
Expand Down
2 changes: 1 addition & 1 deletion src/libdocker/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"k8s.io/klog/v2"
)

// ParseDockerTimestamp parses the timestamp returned by Interface from string to time.Time
// ParseDockerTimestamp parses the timestamp returned by DockerClientInterface from string to time.Time
func ParseDockerTimestamp(s string) (time.Time, error) {
// Timestamp returned by Docker is in time.RFC3339Nano format.
return time.Parse(time.RFC3339Nano, s)
Expand Down
8 changes: 4 additions & 4 deletions src/libdocker/instrumented_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import (
"github.com/Mirantis/cri-dockerd/metrics"
)

// instrumentedInterface wraps the Interface and records the operations
// instrumentedInterface wraps the DockerClientInterface and records the operations
// and errors metrics.
type instrumentedInterface struct {
client Interface
client DockerClientInterface
}

// NewInstrumentedInterface creates an instrumented Interface from an existing Interface.
func NewInstrumentedInterface(dockerClient Interface) Interface {
// NewInstrumentedInterface creates an instrumented DockerClientInterface from an existing DockerClientInterface.
func NewInstrumentedInterface(dockerClient DockerClientInterface) DockerClientInterface {
return instrumentedInterface{
client: dockerClient,
}
Expand Down
8 changes: 4 additions & 4 deletions src/libdocker/kube_docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (

// kubeDockerClient is a wrapped layer of docker client for kubelet internal use. This layer is added to:
// 1) Redirect stream for exec and attach operations.
// 2) Wrap the context in this layer to make the Interface cleaner.
// 2) Wrap the context in this layer to make the DockerClientInterface cleaner.
type kubeDockerClient struct {
// timeout is the timeout of short running docker operations.
timeout time.Duration
Expand All @@ -53,8 +53,8 @@ type kubeDockerClient struct {
client *dockerapi.Client
}

// Make sure that kubeDockerClient implemented the Interface.
var _ Interface = &kubeDockerClient{}
// Make sure that kubeDockerClient implemented the DockerClientInterface.
var _ DockerClientInterface = &kubeDockerClient{}

// There are 2 kinds of docker operations categorized by running time:
// * Long running operation: The long running operation could run for arbitrary long time, and the running time
Expand All @@ -80,7 +80,7 @@ const (
func newKubeDockerClient(
dockerClient *dockerapi.Client,
requestTimeout, imagePullProgressDeadline time.Duration,
) Interface {
) DockerClientInterface {
if requestTimeout == 0 {
requestTimeout = defaultTimeout
}
Expand Down
2 changes: 1 addition & 1 deletion src/libdocker/testing/mock_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
time "time"
)

// MockInterface is a mock of Interface interface
// MockInterface is a mock of DockerClientInterface interface
type MockInterface struct {
ctrl *gomock.Controller
recorder *MockInterfaceMockRecorder
Expand Down

0 comments on commit 31843be

Please sign in to comment.