Align lint checks with containerd

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan 2020-09-30 22:30:22 -07:00
parent 83e6efc6fc
commit a3c0e8859c
11 changed files with 107 additions and 111 deletions

View File

@ -15,9 +15,6 @@ linters:
- errcheck - errcheck
run: run:
deadline: 2m timeout: 3m
skip-dirs: skip-dirs:
- integration - docs
- pkg/api
skip-files:
- ".*_test.go"

View File

@ -17,10 +17,11 @@
package integration package integration
import ( import (
"golang.org/x/net/context"
"testing" "testing"
"time" "time"
"golang.org/x/net/context"
"github.com/containerd/containerd" "github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"

View File

@ -34,7 +34,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"google.golang.org/grpc" "google.golang.org/grpc"
"k8s.io/cri-api/pkg/apis" cri "k8s.io/cri-api/pkg/apis"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
"github.com/containerd/cri/integration/remote" "github.com/containerd/cri/integration/remote"
@ -74,11 +74,11 @@ func TestMain(m *testing.M) {
// ConnectDaemons connect cri plugin and containerd, and initialize the clients. // ConnectDaemons connect cri plugin and containerd, and initialize the clients.
func ConnectDaemons() error { func ConnectDaemons() error {
var err error var err error
runtimeService, err = remote.NewRemoteRuntimeService(*criEndpoint, timeout) runtimeService, err = remote.NewRuntimeService(*criEndpoint, timeout)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create runtime service") return errors.Wrap(err, "failed to create runtime service")
} }
imageService, err = remote.NewRemoteImageService(*criEndpoint, timeout) imageService, err = remote.NewImageService(*criEndpoint, timeout)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create image service") return errors.Wrap(err, "failed to create image service")
} }

View File

@ -70,7 +70,7 @@ func TestPodHostname(t *testing.T) {
t.Fatalf("Unexpected RunPodSandbox error: %v", err) t.Fatalf("Unexpected RunPodSandbox error: %v", err)
} }
return return
} else { }
// Make sure the sandbox is cleaned up. // Make sure the sandbox is cleaned up.
defer func() { defer func() {
assert.NoError(t, runtimeService.StopPodSandbox(sb)) assert.NoError(t, runtimeService.StopPodSandbox(sb))
@ -79,7 +79,6 @@ func TestPodHostname(t *testing.T) {
if test.expectErr { if test.expectErr {
t.Fatalf("Expected RunPodSandbox to return error") t.Fatalf("Expected RunPodSandbox to return error")
} }
}
const ( const (
testImage = "busybox" testImage = "busybox"

View File

@ -47,14 +47,14 @@ import (
"github.com/containerd/cri/integration/remote/util" "github.com/containerd/cri/integration/remote/util"
) )
// RemoteImageService is a gRPC implementation of internalapi.ImageManagerService. // ImageService is a gRPC implementation of internalapi.ImageManagerService.
type RemoteImageService struct { type ImageService struct {
timeout time.Duration timeout time.Duration
imageClient runtimeapi.ImageServiceClient imageClient runtimeapi.ImageServiceClient
} }
// NewRemoteImageService creates a new internalapi.ImageManagerService. // NewImageService creates a new internalapi.ImageManagerService.
func NewRemoteImageService(endpoint string, connectionTimeout time.Duration) (internalapi.ImageManagerService, error) { func NewImageService(endpoint string, connectionTimeout time.Duration) (internalapi.ImageManagerService, error) {
klog.V(3).Infof("Connecting to image service %s", endpoint) klog.V(3).Infof("Connecting to image service %s", endpoint)
addr, dialer, err := util.GetAddressAndDialer(endpoint) addr, dialer, err := util.GetAddressAndDialer(endpoint)
if err != nil { if err != nil {
@ -70,14 +70,14 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration) (in
return nil, err return nil, err
} }
return &RemoteImageService{ return &ImageService{
timeout: connectionTimeout, timeout: connectionTimeout,
imageClient: runtimeapi.NewImageServiceClient(conn), imageClient: runtimeapi.NewImageServiceClient(conn),
}, nil }, nil
} }
// ListImages lists available images. // ListImages lists available images.
func (r *RemoteImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) { func (r *ImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -93,7 +93,7 @@ func (r *RemoteImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runt
} }
// ImageStatus returns the status of the image. // ImageStatus returns the status of the image.
func (r *RemoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) { func (r *ImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -117,7 +117,7 @@ func (r *RemoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimea
} }
// PullImage pulls an image with authentication config. // PullImage pulls an image with authentication config.
func (r *RemoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) { func (r *ImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
ctx, cancel := getContextWithCancel() ctx, cancel := getContextWithCancel()
defer cancel() defer cancel()
@ -141,7 +141,7 @@ func (r *RemoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtim
} }
// RemoveImage removes the image. // RemoveImage removes the image.
func (r *RemoteImageService) RemoveImage(image *runtimeapi.ImageSpec) error { func (r *ImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -157,7 +157,7 @@ func (r *RemoteImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
} }
// ImageFsInfo returns information of the filesystem that is used to store images. // ImageFsInfo returns information of the filesystem that is used to store images.
func (r *RemoteImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error) { func (r *ImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error) {
// Do not set timeout, because `ImageFsInfo` takes time. // Do not set timeout, because `ImageFsInfo` takes time.
// TODO(random-liu): Should we assume runtime should cache the result, and set timeout here? // TODO(random-liu): Should we assume runtime should cache the result, and set timeout here?
ctx, cancel := getContextWithCancel() ctx, cancel := getContextWithCancel()

View File

@ -50,8 +50,8 @@ import (
"github.com/containerd/cri/integration/remote/util" "github.com/containerd/cri/integration/remote/util"
) )
// RemoteRuntimeService is a gRPC implementation of internalapi.RuntimeService. // RuntimeService is a gRPC implementation of internalapi.RuntimeService.
type RemoteRuntimeService struct { type RuntimeService struct {
timeout time.Duration timeout time.Duration
runtimeClient runtimeapi.RuntimeServiceClient runtimeClient runtimeapi.RuntimeServiceClient
// Cache last per-container error message to reduce log spam // Cache last per-container error message to reduce log spam
@ -63,8 +63,8 @@ const (
identicalErrorDelay = 1 * time.Minute identicalErrorDelay = 1 * time.Minute
) )
// NewRemoteRuntimeService creates a new internalapi.RuntimeService. // NewRuntimeService creates a new internalapi.RuntimeService.
func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (internalapi.RuntimeService, error) { func NewRuntimeService(endpoint string, connectionTimeout time.Duration) (internalapi.RuntimeService, error) {
klog.V(3).Infof("Connecting to runtime service %s", endpoint) klog.V(3).Infof("Connecting to runtime service %s", endpoint)
addr, dialer, err := util.GetAddressAndDialer(endpoint) addr, dialer, err := util.GetAddressAndDialer(endpoint)
if err != nil { if err != nil {
@ -79,7 +79,7 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (
return nil, err return nil, err
} }
return &RemoteRuntimeService{ return &RuntimeService{
timeout: connectionTimeout, timeout: connectionTimeout,
runtimeClient: runtimeapi.NewRuntimeServiceClient(conn), runtimeClient: runtimeapi.NewRuntimeServiceClient(conn),
logReduction: logreduction.NewLogReduction(identicalErrorDelay), logReduction: logreduction.NewLogReduction(identicalErrorDelay),
@ -87,8 +87,8 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (
} }
// Version returns the runtime name, runtime version and runtime API version. // Version returns the runtime name, runtime version and runtime API version.
func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) { func (r *RuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
klog.V(10).Infof("[RemoteRuntimeService] Version (apiVersion=%v, timeout=%v)", apiVersion, r.timeout) klog.V(10).Infof("[RuntimeService] Version (apiVersion=%v, timeout=%v)", apiVersion, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -101,7 +101,7 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
return nil, err return nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] Version Response (typedVersion=%v)", typedVersion) klog.V(10).Infof("[RuntimeService] Version Response (typedVersion=%v)", typedVersion)
if typedVersion.Version == "" || typedVersion.RuntimeName == "" || typedVersion.RuntimeApiVersion == "" || typedVersion.RuntimeVersion == "" { if typedVersion.Version == "" || typedVersion.RuntimeName == "" || typedVersion.RuntimeApiVersion == "" || typedVersion.RuntimeVersion == "" {
return nil, fmt.Errorf("not all fields are set in VersionResponse (%q)", *typedVersion) return nil, fmt.Errorf("not all fields are set in VersionResponse (%q)", *typedVersion)
@ -112,12 +112,12 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure // RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
// the sandbox is in ready state. // the sandbox is in ready state.
func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) { func (r *RuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) {
// Use 2 times longer timeout for sandbox operation (4 mins by default) // Use 2 times longer timeout for sandbox operation (4 mins by default)
// TODO: Make the pod sandbox timeout configurable. // TODO: Make the pod sandbox timeout configurable.
timeout := r.timeout * 2 timeout := r.timeout * 2
klog.V(10).Infof("[RemoteRuntimeService] RunPodSandbox (config=%v, runtimeHandler=%v, timeout=%v)", config, runtimeHandler, timeout) klog.V(10).Infof("[RuntimeService] RunPodSandbox (config=%v, runtimeHandler=%v, timeout=%v)", config, runtimeHandler, timeout)
ctx, cancel := getContextWithTimeout(timeout) ctx, cancel := getContextWithTimeout(timeout)
defer cancel() defer cancel()
@ -137,15 +137,15 @@ func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig
return "", errors.New(errorMessage) return "", errors.New(errorMessage)
} }
klog.V(10).Infof("[RemoteRuntimeService] RunPodSandbox Response (PodSandboxId=%v)", resp.PodSandboxId) klog.V(10).Infof("[RuntimeService] RunPodSandbox Response (PodSandboxId=%v)", resp.PodSandboxId)
return resp.PodSandboxId, nil return resp.PodSandboxId, nil
} }
// StopPodSandbox stops the sandbox. If there are any running containers in the // StopPodSandbox stops the sandbox. If there are any running containers in the
// sandbox, they should be forced to termination. // sandbox, they should be forced to termination.
func (r *RemoteRuntimeService) StopPodSandbox(podSandBoxID string) error { func (r *RuntimeService) StopPodSandbox(podSandBoxID string) error {
klog.V(10).Infof("[RemoteRuntimeService] StopPodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout) klog.V(10).Infof("[RuntimeService] StopPodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -158,15 +158,15 @@ func (r *RemoteRuntimeService) StopPodSandbox(podSandBoxID string) error {
return err return err
} }
klog.V(10).Infof("[RemoteRuntimeService] StopPodSandbox Response (podSandboxID=%v)", podSandBoxID) klog.V(10).Infof("[RuntimeService] StopPodSandbox Response (podSandboxID=%v)", podSandBoxID)
return nil return nil
} }
// RemovePodSandbox removes the sandbox. If there are any containers in the // RemovePodSandbox removes the sandbox. If there are any containers in the
// sandbox, they should be forcibly removed. // sandbox, they should be forcibly removed.
func (r *RemoteRuntimeService) RemovePodSandbox(podSandBoxID string) error { func (r *RuntimeService) RemovePodSandbox(podSandBoxID string) error {
klog.V(10).Infof("[RemoteRuntimeService] RemovePodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout) klog.V(10).Infof("[RuntimeService] RemovePodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -178,14 +178,14 @@ func (r *RemoteRuntimeService) RemovePodSandbox(podSandBoxID string) error {
return err return err
} }
klog.V(10).Infof("[RemoteRuntimeService] RemovePodSandbox Response (podSandboxID=%v)", podSandBoxID) klog.V(10).Infof("[RuntimeService] RemovePodSandbox Response (podSandboxID=%v)", podSandBoxID)
return nil return nil
} }
// PodSandboxStatus returns the status of the PodSandbox. // PodSandboxStatus returns the status of the PodSandbox.
func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) { func (r *RuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
klog.V(10).Infof("[RemoteRuntimeService] PodSandboxStatus (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout) klog.V(10).Infof("[RuntimeService] PodSandboxStatus (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -196,7 +196,7 @@ func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeap
return nil, err return nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] PodSandboxStatus Response (podSandboxID=%v, status=%v)", podSandBoxID, resp.Status) klog.V(10).Infof("[RuntimeService] PodSandboxStatus Response (podSandboxID=%v, status=%v)", podSandBoxID, resp.Status)
if resp.Status != nil { if resp.Status != nil {
if err := verifySandboxStatus(resp.Status); err != nil { if err := verifySandboxStatus(resp.Status); err != nil {
@ -208,8 +208,8 @@ func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeap
} }
// ListPodSandbox returns a list of PodSandboxes. // ListPodSandbox returns a list of PodSandboxes.
func (r *RemoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) { func (r *RuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
klog.V(10).Infof("[RemoteRuntimeService] ListPodSandbox (filter=%v, timeout=%v)", filter, r.timeout) klog.V(10).Infof("[RuntimeService] ListPodSandbox (filter=%v, timeout=%v)", filter, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -221,14 +221,14 @@ func (r *RemoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilte
return nil, err return nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] ListPodSandbox Response (filter=%v, items=%v)", filter, resp.Items) klog.V(10).Infof("[RuntimeService] ListPodSandbox Response (filter=%v, items=%v)", filter, resp.Items)
return resp.Items, nil return resp.Items, nil
} }
// CreateContainer creates a new container in the specified PodSandbox. // CreateContainer creates a new container in the specified PodSandbox.
func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) { func (r *RuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
klog.V(10).Infof("[RemoteRuntimeService] CreateContainer (podSandBoxID=%v, timeout=%v)", podSandBoxID, r.timeout) klog.V(10).Infof("[RuntimeService] CreateContainer (podSandBoxID=%v, timeout=%v)", podSandBoxID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -242,7 +242,7 @@ func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
return "", err return "", err
} }
klog.V(10).Infof("[RemoteRuntimeService] CreateContainer (podSandBoxID=%v, ContainerId=%v)", podSandBoxID, resp.ContainerId) klog.V(10).Infof("[RuntimeService] CreateContainer (podSandBoxID=%v, ContainerId=%v)", podSandBoxID, resp.ContainerId)
if resp.ContainerId == "" { if resp.ContainerId == "" {
errorMessage := fmt.Sprintf("ContainerId is not set for container %q", config.GetMetadata()) errorMessage := fmt.Sprintf("ContainerId is not set for container %q", config.GetMetadata())
klog.Errorf("CreateContainer failed: %s", errorMessage) klog.Errorf("CreateContainer failed: %s", errorMessage)
@ -253,8 +253,8 @@ func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
} }
// StartContainer starts the container. // StartContainer starts the container.
func (r *RemoteRuntimeService) StartContainer(containerID string) error { func (r *RuntimeService) StartContainer(containerID string) error {
klog.V(10).Infof("[RemoteRuntimeService] StartContainer (containerID=%v, timeout=%v)", containerID, r.timeout) klog.V(10).Infof("[RuntimeService] StartContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -265,14 +265,14 @@ func (r *RemoteRuntimeService) StartContainer(containerID string) error {
klog.Errorf("StartContainer %q from runtime service failed: %v", containerID, err) klog.Errorf("StartContainer %q from runtime service failed: %v", containerID, err)
return err return err
} }
klog.V(10).Infof("[RemoteRuntimeService] StartContainer Response (containerID=%v)", containerID) klog.V(10).Infof("[RuntimeService] StartContainer Response (containerID=%v)", containerID)
return nil return nil
} }
// StopContainer stops a running container with a grace period (i.e., timeout). // StopContainer stops a running container with a grace period (i.e., timeout).
func (r *RemoteRuntimeService) StopContainer(containerID string, timeout int64) error { func (r *RuntimeService) StopContainer(containerID string, timeout int64) error {
klog.V(10).Infof("[RemoteRuntimeService] StopContainer (containerID=%v, timeout=%v)", containerID, timeout) klog.V(10).Infof("[RuntimeService] StopContainer (containerID=%v, timeout=%v)", containerID, timeout)
// Use timeout + default timeout (2 minutes) as timeout to leave extra time // Use timeout + default timeout (2 minutes) as timeout to leave extra time
// for SIGKILL container and request latency. // for SIGKILL container and request latency.
t := r.timeout + time.Duration(timeout)*time.Second t := r.timeout + time.Duration(timeout)*time.Second
@ -288,15 +288,15 @@ func (r *RemoteRuntimeService) StopContainer(containerID string, timeout int64)
klog.Errorf("StopContainer %q from runtime service failed: %v", containerID, err) klog.Errorf("StopContainer %q from runtime service failed: %v", containerID, err)
return err return err
} }
klog.V(10).Infof("[RemoteRuntimeService] StopContainer Response (containerID=%v)", containerID) klog.V(10).Infof("[RuntimeService] StopContainer Response (containerID=%v)", containerID)
return nil return nil
} }
// RemoveContainer removes the container. If the container is running, the container // RemoveContainer removes the container. If the container is running, the container
// should be forced to removal. // should be forced to removal.
func (r *RemoteRuntimeService) RemoveContainer(containerID string) error { func (r *RuntimeService) RemoveContainer(containerID string) error {
klog.V(10).Infof("[RemoteRuntimeService] RemoveContainer (containerID=%v, timeout=%v)", containerID, r.timeout) klog.V(10).Infof("[RuntimeService] RemoveContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -308,14 +308,14 @@ func (r *RemoteRuntimeService) RemoveContainer(containerID string) error {
klog.Errorf("RemoveContainer %q from runtime service failed: %v", containerID, err) klog.Errorf("RemoveContainer %q from runtime service failed: %v", containerID, err)
return err return err
} }
klog.V(10).Infof("[RemoteRuntimeService] RemoveContainer Response (containerID=%v)", containerID) klog.V(10).Infof("[RuntimeService] RemoveContainer Response (containerID=%v)", containerID)
return nil return nil
} }
// ListContainers lists containers by filters. // ListContainers lists containers by filters.
func (r *RemoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) { func (r *RuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
klog.V(10).Infof("[RemoteRuntimeService] ListContainers (filter=%v, timeout=%v)", filter, r.timeout) klog.V(10).Infof("[RuntimeService] ListContainers (filter=%v, timeout=%v)", filter, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -326,14 +326,14 @@ func (r *RemoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter
klog.Errorf("ListContainers with filter %+v from runtime service failed: %v", filter, err) klog.Errorf("ListContainers with filter %+v from runtime service failed: %v", filter, err)
return nil, err return nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] ListContainers Response (filter=%v, containers=%v)", filter, resp.Containers) klog.V(10).Infof("[RuntimeService] ListContainers Response (filter=%v, containers=%v)", filter, resp.Containers)
return resp.Containers, nil return resp.Containers, nil
} }
// ContainerStatus returns the container status. // ContainerStatus returns the container status.
func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) { func (r *RuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
klog.V(10).Infof("[RemoteRuntimeService] ContainerStatus (containerID=%v, timeout=%v)", containerID, r.timeout) klog.V(10).Infof("[RuntimeService] ContainerStatus (containerID=%v, timeout=%v)", containerID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -348,7 +348,7 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
return nil, err return nil, err
} }
r.logReduction.ClearID(containerID) r.logReduction.ClearID(containerID)
klog.V(10).Infof("[RemoteRuntimeService] ContainerStatus Response (containerID=%v, status=%v)", containerID, resp.Status) klog.V(10).Infof("[RuntimeService] ContainerStatus Response (containerID=%v, status=%v)", containerID, resp.Status)
if resp.Status != nil { if resp.Status != nil {
if err := verifyContainerStatus(resp.Status); err != nil { if err := verifyContainerStatus(resp.Status); err != nil {
@ -361,8 +361,8 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
} }
// UpdateContainerResources updates a containers resource config // UpdateContainerResources updates a containers resource config
func (r *RemoteRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error { func (r *RuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error {
klog.V(10).Infof("[RemoteRuntimeService] UpdateContainerResources (containerID=%v, timeout=%v)", containerID, r.timeout) klog.V(10).Infof("[RuntimeService] UpdateContainerResources (containerID=%v, timeout=%v)", containerID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -374,15 +374,15 @@ func (r *RemoteRuntimeService) UpdateContainerResources(containerID string, reso
klog.Errorf("UpdateContainerResources %q from runtime service failed: %v", containerID, err) klog.Errorf("UpdateContainerResources %q from runtime service failed: %v", containerID, err)
return err return err
} }
klog.V(10).Infof("[RemoteRuntimeService] UpdateContainerResources Response (containerID=%v)", containerID) klog.V(10).Infof("[RuntimeService] UpdateContainerResources Response (containerID=%v)", containerID)
return nil return nil
} }
// ExecSync executes a command in the container, and returns the stdout output. // ExecSync executes a command in the container, and returns the stdout output.
// If command exits with a non-zero exit code, an error is returned. // If command exits with a non-zero exit code, an error is returned.
func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) { func (r *RuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
klog.V(10).Infof("[RemoteRuntimeService] ExecSync (containerID=%v, timeout=%v)", containerID, timeout) klog.V(10).Infof("[RuntimeService] ExecSync (containerID=%v, timeout=%v)", containerID, timeout)
// Do not set timeout when timeout is 0. // Do not set timeout when timeout is 0.
var ctx context.Context var ctx context.Context
var cancel context.CancelFunc var cancel context.CancelFunc
@ -407,7 +407,7 @@ func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeou
return nil, nil, err return nil, nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] ExecSync Response (containerID=%v, ExitCode=%v)", containerID, resp.ExitCode) klog.V(10).Infof("[RuntimeService] ExecSync Response (containerID=%v, ExitCode=%v)", containerID, resp.ExitCode)
err = nil err = nil
if resp.ExitCode != 0 { if resp.ExitCode != 0 {
err = utilexec.CodeExitError{ err = utilexec.CodeExitError{
@ -420,8 +420,8 @@ func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeou
} }
// Exec prepares a streaming endpoint to execute a command in the container, and returns the address. // Exec prepares a streaming endpoint to execute a command in the container, and returns the address.
func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) { func (r *RuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
klog.V(10).Infof("[RemoteRuntimeService] Exec (timeout=%v)", r.timeout) klog.V(10).Infof("[RuntimeService] Exec (timeout=%v)", r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -430,7 +430,7 @@ func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.Ex
klog.Errorf("Exec %s '%s' from runtime service failed: %v", req.ContainerId, strings.Join(req.Cmd, " "), err) klog.Errorf("Exec %s '%s' from runtime service failed: %v", req.ContainerId, strings.Join(req.Cmd, " "), err)
return nil, err return nil, err
} }
klog.V(10).Info("[RemoteRuntimeService] Exec Response") klog.V(10).Info("[RuntimeService] Exec Response")
if resp.Url == "" { if resp.Url == "" {
errorMessage := "URL is not set" errorMessage := "URL is not set"
@ -442,8 +442,8 @@ func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.Ex
} }
// Attach prepares a streaming endpoint to attach to a running container, and returns the address. // Attach prepares a streaming endpoint to attach to a running container, and returns the address.
func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) { func (r *RuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
klog.V(10).Infof("[RemoteRuntimeService] Attach (containerId=%v, timeout=%v)", req.ContainerId, r.timeout) klog.V(10).Infof("[RuntimeService] Attach (containerId=%v, timeout=%v)", req.ContainerId, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -452,7 +452,7 @@ func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeap
klog.Errorf("Attach %s from runtime service failed: %v", req.ContainerId, err) klog.Errorf("Attach %s from runtime service failed: %v", req.ContainerId, err)
return nil, err return nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] Attach Response (containerId=%v)", req.ContainerId) klog.V(10).Infof("[RuntimeService] Attach Response (containerId=%v)", req.ContainerId)
if resp.Url == "" { if resp.Url == "" {
errorMessage := "URL is not set" errorMessage := "URL is not set"
@ -463,8 +463,8 @@ func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeap
} }
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address. // PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) { func (r *RuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
klog.V(10).Infof("[RemoteRuntimeService] PortForward (podSandboxID=%v, port=%v, timeout=%v)", req.PodSandboxId, req.Port, r.timeout) klog.V(10).Infof("[RuntimeService] PortForward (podSandboxID=%v, port=%v, timeout=%v)", req.PodSandboxId, req.Port, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -473,7 +473,7 @@ func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (
klog.Errorf("PortForward %s from runtime service failed: %v", req.PodSandboxId, err) klog.Errorf("PortForward %s from runtime service failed: %v", req.PodSandboxId, err)
return nil, err return nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] PortForward Response (podSandboxID=%v)", req.PodSandboxId) klog.V(10).Infof("[RuntimeService] PortForward Response (podSandboxID=%v)", req.PodSandboxId)
if resp.Url == "" { if resp.Url == "" {
errorMessage := "URL is not set" errorMessage := "URL is not set"
@ -487,8 +487,8 @@ func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (
// UpdateRuntimeConfig updates the config of a runtime service. The only // UpdateRuntimeConfig updates the config of a runtime service. The only
// update payload currently supported is the pod CIDR assigned to a node, // update payload currently supported is the pod CIDR assigned to a node,
// and the runtime service just proxies it down to the network plugin. // and the runtime service just proxies it down to the network plugin.
func (r *RemoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error { func (r *RuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error {
klog.V(10).Infof("[RemoteRuntimeService] UpdateRuntimeConfig (runtimeConfig=%v, timeout=%v)", runtimeConfig, r.timeout) klog.V(10).Infof("[RuntimeService] UpdateRuntimeConfig (runtimeConfig=%v, timeout=%v)", runtimeConfig, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -502,14 +502,14 @@ func (r *RemoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.Run
if err != nil { if err != nil {
return err return err
} }
klog.V(10).Infof("[RemoteRuntimeService] UpdateRuntimeConfig Response (runtimeConfig=%v)", runtimeConfig) klog.V(10).Infof("[RuntimeService] UpdateRuntimeConfig Response (runtimeConfig=%v)", runtimeConfig)
return nil return nil
} }
// Status returns the status of the runtime. // Status returns the status of the runtime.
func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) { func (r *RuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
klog.V(10).Infof("[RemoteRuntimeService] Status (timeout=%v)", r.timeout) klog.V(10).Infof("[RuntimeService] Status (timeout=%v)", r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -519,7 +519,7 @@ func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
return nil, err return nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] Status Response (status=%v)", resp.Status) klog.V(10).Infof("[RuntimeService] Status Response (status=%v)", resp.Status)
if resp.Status == nil || len(resp.Status.Conditions) < 2 { if resp.Status == nil || len(resp.Status.Conditions) < 2 {
errorMessage := "RuntimeReady or NetworkReady condition are not set" errorMessage := "RuntimeReady or NetworkReady condition are not set"
@ -531,8 +531,8 @@ func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
} }
// ContainerStats returns the stats of the container. // ContainerStats returns the stats of the container.
func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) { func (r *RuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
klog.V(10).Infof("[RemoteRuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout) klog.V(10).Infof("[RuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -546,13 +546,13 @@ func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.C
return nil, err return nil, err
} }
r.logReduction.ClearID(containerID) r.logReduction.ClearID(containerID)
klog.V(10).Infof("[RemoteRuntimeService] ContainerStats Response (containerID=%v, stats=%v)", containerID, resp.GetStats()) klog.V(10).Infof("[RuntimeService] ContainerStats Response (containerID=%v, stats=%v)", containerID, resp.GetStats())
return resp.GetStats(), nil return resp.GetStats(), nil
} }
func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) { func (r *RuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
klog.V(10).Infof("[RemoteRuntimeService] ListContainerStats (filter=%v)", filter) klog.V(10).Infof("[RuntimeService] ListContainerStats (filter=%v)", filter)
// Do not set timeout, because writable layer stats collection takes time. // Do not set timeout, because writable layer stats collection takes time.
// TODO(random-liu): Should we assume runtime should cache the result, and set timeout here? // TODO(random-liu): Should we assume runtime should cache the result, and set timeout here?
ctx, cancel := getContextWithCancel() ctx, cancel := getContextWithCancel()
@ -565,13 +565,13 @@ func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerSt
klog.Errorf("ListContainerStats with filter %+v from runtime service failed: %v", filter, err) klog.Errorf("ListContainerStats with filter %+v from runtime service failed: %v", filter, err)
return nil, err return nil, err
} }
klog.V(10).Infof("[RemoteRuntimeService] ListContainerStats Response (filter=%v, stats=%v)", filter, resp.GetStats()) klog.V(10).Infof("[RuntimeService] ListContainerStats Response (filter=%v, stats=%v)", filter, resp.GetStats())
return resp.GetStats(), nil return resp.GetStats(), nil
} }
func (r *RemoteRuntimeService) ReopenContainerLog(containerID string) error { func (r *RuntimeService) ReopenContainerLog(containerID string) error {
klog.V(10).Infof("[RemoteRuntimeService] ReopenContainerLog (containerID=%v, timeout=%v)", containerID, r.timeout) klog.V(10).Infof("[RuntimeService] ReopenContainerLog (containerID=%v, timeout=%v)", containerID, r.timeout)
ctx, cancel := getContextWithTimeout(r.timeout) ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel() defer cancel()
@ -581,6 +581,6 @@ func (r *RemoteRuntimeService) ReopenContainerLog(containerID string) error {
return err return err
} }
klog.V(10).Infof("[RemoteRuntimeService] ReopenContainerLog Response (containerID=%v)", containerID) klog.V(10).Infof("[RuntimeService] ReopenContainerLog Response (containerID=%v)", containerID)
return nil return nil
} }

View File

@ -35,13 +35,13 @@ func TestTruncIndex(t *testing.T) {
const appImage = "busybox" const appImage = "busybox"
imgID, err := imageService.PullImage(&runtimeapi.ImageSpec{Image: appImage}, nil, sbConfig) imgID, err := imageService.PullImage(&runtimeapi.ImageSpec{Image: appImage}, nil, sbConfig)
require.NoError(t, err) require.NoError(t, err)
imgTruncId := genTruncIndex(imgID) imgTruncID := genTruncIndex(imgID)
defer func() { defer func() {
assert.NoError(t, imageService.RemoveImage(&runtimeapi.ImageSpec{Image: imgTruncId})) assert.NoError(t, imageService.RemoveImage(&runtimeapi.ImageSpec{Image: imgTruncID}))
}() }()
t.Logf("Get image status by truncindex, truncId: %s", imgTruncId) t.Logf("Get image status by truncindex, truncID: %s", imgTruncID)
res, err := imageService.ImageStatus(&runtimeapi.ImageSpec{Image: imgTruncId}) res, err := imageService.ImageStatus(&runtimeapi.ImageSpec{Image: imgTruncID})
require.NoError(t, err) require.NoError(t, err)
require.NotEqual(t, nil, res) require.NotEqual(t, nil, res)
assert.Equal(t, imgID, res.Id) assert.Equal(t, imgID, res.Id)

View File

@ -903,7 +903,7 @@ func TestGenerateApparmorSpecOpts(t *testing.T) {
profile: runtimeDefault, profile: runtimeDefault,
privileged: true, privileged: true,
}, },
// TODO (mikebrow) add success with exising defined profile tests // TODO (mikebrow) add success with existing defined profile tests
"should return error when undefined local profile is specified": { "should return error when undefined local profile is specified": {
profile: profileNamePrefix + "test-profile", profile: profileNamePrefix + "test-profile",
expectErr: true, expectErr: true,

View File

@ -358,7 +358,7 @@ func TestImageLayersLabel(t *testing.T) {
{ {
name: "many layers", name: "many layers",
layersNum: 5, // hits sampleMaxSize (300 chars). layersNum: 5, // hits sampleMaxSize (300 chars).
wantNum: 4, // layers should be ommitted for avoiding invalid label. wantNum: 4, // layers should be omitted for avoiding invalid label.
}, },
} }

View File

@ -18,7 +18,6 @@ package sandbox
import ( import (
"errors" "errors"
"fmt"
"testing" "testing"
"time" "time"
@ -63,8 +62,8 @@ func TestStatus(t *testing.T) {
func TestStateStringConversion(t *testing.T) { func TestStateStringConversion(t *testing.T) {
assert := assertlib.New(t) assert := assertlib.New(t)
assert.Equal("SANDBOX_READY", fmt.Sprintf("%s", StateReady)) assert.Equal("SANDBOX_READY", StateReady.String())
assert.Equal("SANDBOX_NOTREADY", fmt.Sprintf("%s", StateNotReady)) assert.Equal("SANDBOX_NOTREADY", StateNotReady.String())
assert.Equal("SANDBOX_UNKNOWN", fmt.Sprintf("%s", StateUnknown)) assert.Equal("SANDBOX_UNKNOWN", StateUnknown.String())
assert.Equal("invalid sandbox state value: 123", fmt.Sprintf("%s", State(123))) assert.Equal("invalid sandbox state value: 123", State(123).String())
} }

View File

@ -26,4 +26,4 @@ cd "${ROOT}"
make install.tools make install.tools
make verify make verify
GOOS=windows make verify #GOOS=windows make verify