mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #91970 from SergeyKanzhelev/criLinterIssuesFix
fix linter issues for kubelet/cri/remote and ri-api/pkg/apis/testing
This commit is contained in:
commit
3e8bc58cce
@ -98,7 +98,6 @@ pkg/kubelet/apis/config/v1beta1
|
||||
pkg/kubelet/cm
|
||||
pkg/kubelet/container
|
||||
pkg/kubelet/container/testing
|
||||
pkg/kubelet/cri/remote
|
||||
pkg/kubelet/dockershim/libdocker
|
||||
pkg/kubelet/dockershim/network
|
||||
pkg/kubelet/dockershim/network/cni/testing
|
||||
@ -435,7 +434,6 @@ staging/src/k8s.io/component-base/cli/flag
|
||||
staging/src/k8s.io/component-base/config/v1alpha1
|
||||
staging/src/k8s.io/component-base/featuregate
|
||||
staging/src/k8s.io/component-base/version/verflag
|
||||
staging/src/k8s.io/cri-api/pkg/apis/testing
|
||||
staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1
|
||||
staging/src/k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1
|
||||
staging/src/k8s.io/kube-aggregator/pkg/apiserver
|
||||
|
@ -30,8 +30,8 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/cri/remote/util"
|
||||
)
|
||||
|
||||
// RemoteImageService is a gRPC implementation of internalapi.ImageManagerService.
|
||||
type RemoteImageService struct {
|
||||
// remoteImageService is a gRPC implementation of internalapi.ImageManagerService.
|
||||
type remoteImageService struct {
|
||||
timeout time.Duration
|
||||
imageClient runtimeapi.ImageServiceClient
|
||||
}
|
||||
@ -53,14 +53,14 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration) (in
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &RemoteImageService{
|
||||
return &remoteImageService{
|
||||
timeout: connectionTimeout,
|
||||
imageClient: runtimeapi.NewImageServiceClient(conn),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListImages lists available images.
|
||||
func (r *RemoteImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
||||
func (r *remoteImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -76,7 +76,7 @@ func (r *RemoteImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runt
|
||||
}
|
||||
|
||||
// ImageStatus returns the status of the image.
|
||||
func (r *RemoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
|
||||
func (r *remoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -100,7 +100,7 @@ func (r *RemoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimea
|
||||
}
|
||||
|
||||
// PullImage pulls an image with authentication config.
|
||||
func (r *RemoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
func (r *remoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
@ -124,7 +124,7 @@ func (r *RemoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtim
|
||||
}
|
||||
|
||||
// RemoveImage removes the image.
|
||||
func (r *RemoteImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
|
||||
func (r *remoteImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -140,7 +140,7 @@ func (r *RemoteImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
|
||||
}
|
||||
|
||||
// ImageFsInfo returns information of the filesystem that is used to store images.
|
||||
func (r *RemoteImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error) {
|
||||
func (r *remoteImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error) {
|
||||
// Do not set timeout, because `ImageFsInfo` takes time.
|
||||
// TODO(random-liu): Should we assume runtime should cache the result, and set timeout here?
|
||||
ctx, cancel := getContextWithCancel()
|
||||
|
@ -33,8 +33,8 @@ import (
|
||||
utilexec "k8s.io/utils/exec"
|
||||
)
|
||||
|
||||
// RemoteRuntimeService is a gRPC implementation of internalapi.RuntimeService.
|
||||
type RemoteRuntimeService struct {
|
||||
// remoteRuntimeService is a gRPC implementation of internalapi.RuntimeService.
|
||||
type remoteRuntimeService struct {
|
||||
timeout time.Duration
|
||||
runtimeClient runtimeapi.RuntimeServiceClient
|
||||
// Cache last per-container error message to reduce log spam
|
||||
@ -62,7 +62,7 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &RemoteRuntimeService{
|
||||
return &remoteRuntimeService{
|
||||
timeout: connectionTimeout,
|
||||
runtimeClient: runtimeapi.NewRuntimeServiceClient(conn),
|
||||
logReduction: logreduction.NewLogReduction(identicalErrorDelay),
|
||||
@ -70,7 +70,7 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (
|
||||
}
|
||||
|
||||
// Version returns the runtime name, runtime version and runtime API version.
|
||||
func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
|
||||
func (r *remoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Version (apiVersion=%v, timeout=%v)", apiVersion, r.timeout)
|
||||
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
@ -95,7 +95,7 @@ func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
|
||||
|
||||
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
|
||||
// the sandbox is in ready state.
|
||||
func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) {
|
||||
func (r *remoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) {
|
||||
// Use 2 times longer timeout for sandbox operation (4 mins by default)
|
||||
// TODO: Make the pod sandbox timeout configurable.
|
||||
timeout := r.timeout * 2
|
||||
@ -127,7 +127,7 @@ func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig
|
||||
|
||||
// StopPodSandbox stops the sandbox. If there are any running containers in the
|
||||
// sandbox, they should be forced to termination.
|
||||
func (r *RemoteRuntimeService) StopPodSandbox(podSandBoxID string) error {
|
||||
func (r *remoteRuntimeService) StopPodSandbox(podSandBoxID string) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StopPodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
@ -148,7 +148,7 @@ func (r *RemoteRuntimeService) StopPodSandbox(podSandBoxID string) error {
|
||||
|
||||
// RemovePodSandbox removes the sandbox. If there are any containers in the
|
||||
// sandbox, they should be forcibly removed.
|
||||
func (r *RemoteRuntimeService) RemovePodSandbox(podSandBoxID string) error {
|
||||
func (r *remoteRuntimeService) RemovePodSandbox(podSandBoxID string) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] RemovePodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -167,7 +167,7 @@ func (r *RemoteRuntimeService) RemovePodSandbox(podSandBoxID string) error {
|
||||
}
|
||||
|
||||
// PodSandboxStatus returns the status of the PodSandbox.
|
||||
func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
|
||||
func (r *remoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] PodSandboxStatus (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -191,7 +191,7 @@ func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeap
|
||||
}
|
||||
|
||||
// ListPodSandbox returns a list of PodSandboxes.
|
||||
func (r *RemoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
||||
func (r *remoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ListPodSandbox (filter=%v, timeout=%v)", filter, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -210,7 +210,7 @@ func (r *RemoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilte
|
||||
}
|
||||
|
||||
// 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 *remoteRuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] CreateContainer (podSandBoxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -236,7 +236,7 @@ func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
|
||||
}
|
||||
|
||||
// StartContainer starts the container.
|
||||
func (r *RemoteRuntimeService) StartContainer(containerID string) error {
|
||||
func (r *remoteRuntimeService) StartContainer(containerID string) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StartContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -254,7 +254,7 @@ func (r *RemoteRuntimeService) StartContainer(containerID string) error {
|
||||
}
|
||||
|
||||
// StopContainer stops a running container with a grace period (i.e., timeout).
|
||||
func (r *RemoteRuntimeService) StopContainer(containerID string, timeout int64) error {
|
||||
func (r *remoteRuntimeService) StopContainer(containerID string, timeout int64) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StopContainer (containerID=%v, timeout=%v)", containerID, timeout)
|
||||
// Use timeout + default timeout (2 minutes) as timeout to leave extra time
|
||||
// for SIGKILL container and request latency.
|
||||
@ -278,7 +278,7 @@ func (r *RemoteRuntimeService) StopContainer(containerID string, timeout int64)
|
||||
|
||||
// RemoveContainer removes the container. If the container is running, the container
|
||||
// should be forced to removal.
|
||||
func (r *RemoteRuntimeService) RemoveContainer(containerID string) error {
|
||||
func (r *remoteRuntimeService) RemoveContainer(containerID string) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] RemoveContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -297,7 +297,7 @@ func (r *RemoteRuntimeService) RemoveContainer(containerID string) error {
|
||||
}
|
||||
|
||||
// ListContainers lists containers by filters.
|
||||
func (r *RemoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
||||
func (r *remoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ListContainers (filter=%v, timeout=%v)", filter, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -315,7 +315,7 @@ func (r *RemoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter
|
||||
}
|
||||
|
||||
// ContainerStatus returns the container status.
|
||||
func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
|
||||
func (r *remoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ContainerStatus (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -344,7 +344,7 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
|
||||
}
|
||||
|
||||
// UpdateContainerResources updates a containers resource config
|
||||
func (r *RemoteRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error {
|
||||
func (r *remoteRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] UpdateContainerResources (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -364,7 +364,7 @@ func (r *RemoteRuntimeService) UpdateContainerResources(containerID string, reso
|
||||
|
||||
// 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.
|
||||
func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
|
||||
func (r *remoteRuntimeService) 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)
|
||||
// Do not set timeout when timeout is 0.
|
||||
var ctx context.Context
|
||||
@ -403,7 +403,7 @@ 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.
|
||||
func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
|
||||
func (r *remoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Exec (timeout=%v)", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -425,7 +425,7 @@ func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.Ex
|
||||
}
|
||||
|
||||
// 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 *remoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Attach (containerId=%v, timeout=%v)", req.ContainerId, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -446,7 +446,7 @@ func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeap
|
||||
}
|
||||
|
||||
// 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 *remoteRuntimeService) 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)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -470,7 +470,7 @@ func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (
|
||||
// UpdateRuntimeConfig updates the config of a runtime service. The only
|
||||
// update payload currently supported is the pod CIDR assigned to a node,
|
||||
// and the runtime service just proxies it down to the network plugin.
|
||||
func (r *RemoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error {
|
||||
func (r *remoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] UpdateRuntimeConfig (runtimeConfig=%v, timeout=%v)", runtimeConfig, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -491,7 +491,7 @@ func (r *RemoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.Run
|
||||
}
|
||||
|
||||
// Status returns the status of the runtime.
|
||||
func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
func (r *remoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Status (timeout=%v)", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -514,7 +514,7 @@ func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
}
|
||||
|
||||
// ContainerStats returns the stats of the container.
|
||||
func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
||||
func (r *remoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -534,7 +534,8 @@ func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.C
|
||||
return resp.GetStats(), nil
|
||||
}
|
||||
|
||||
func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
|
||||
// ListContainerStats returns the list of ContainerStats given the filter.
|
||||
func (r *remoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ListContainerStats (filter=%v)", filter)
|
||||
// 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?
|
||||
@ -553,7 +554,8 @@ func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerSt
|
||||
return resp.GetStats(), nil
|
||||
}
|
||||
|
||||
func (r *RemoteRuntimeService) ReopenContainerLog(containerID string) error {
|
||||
// ReopenContainerLog reopens the container log file.
|
||||
func (r *remoteRuntimeService) ReopenContainerLog(containerID string) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ReopenContainerLog (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||
)
|
||||
|
||||
// FakeImageService fakes the image service.
|
||||
type FakeImageService struct {
|
||||
sync.Mutex
|
||||
|
||||
@ -38,6 +39,7 @@ type FakeImageService struct {
|
||||
FakeFilesystemUsage []*runtimeapi.FilesystemUsage
|
||||
}
|
||||
|
||||
// SetFakeImages sets the list of fake images for the FakeImageService.
|
||||
func (r *FakeImageService) SetFakeImages(images []string) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -51,6 +53,7 @@ func (r *FakeImageService) SetFakeImages(images []string) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetFakeImagesWithAnnotations sets the list of fake images for the FakeImageService with annotations.
|
||||
func (r *FakeImageService) SetFakeImagesWithAnnotations(imageSpecs []*runtimeapi.ImageSpec) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -61,6 +64,7 @@ func (r *FakeImageService) SetFakeImagesWithAnnotations(imageSpecs []*runtimeapi
|
||||
}
|
||||
}
|
||||
|
||||
// SetFakeImageSize sets the image size for the FakeImageService.
|
||||
func (r *FakeImageService) SetFakeImageSize(size uint64) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -68,6 +72,7 @@ func (r *FakeImageService) SetFakeImageSize(size uint64) {
|
||||
r.FakeImageSize = size
|
||||
}
|
||||
|
||||
// SetFakeFilesystemUsage sets the FilesystemUsage for FakeImageService.
|
||||
func (r *FakeImageService) SetFakeFilesystemUsage(usage []*runtimeapi.FilesystemUsage) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -75,6 +80,7 @@ func (r *FakeImageService) SetFakeFilesystemUsage(usage []*runtimeapi.Filesystem
|
||||
r.FakeFilesystemUsage = usage
|
||||
}
|
||||
|
||||
// NewFakeImageService creates a new FakeImageService.
|
||||
func NewFakeImageService() *FakeImageService {
|
||||
return &FakeImageService{
|
||||
Called: make([]string, 0),
|
||||
@ -103,6 +109,7 @@ func stringInSlice(s string, list []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// InjectError sets the error message for the FakeImageService.
|
||||
func (r *FakeImageService) InjectError(f string, err error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -123,6 +130,7 @@ func (r *FakeImageService) popError(f string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// ListImages returns the list of images from FakeImageService or error if it was previously set.
|
||||
func (r *FakeImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -145,6 +153,7 @@ func (r *FakeImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtim
|
||||
return images, nil
|
||||
}
|
||||
|
||||
// ImageStatus returns the status of the image from the FakeImageService.
|
||||
func (r *FakeImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -157,6 +166,7 @@ func (r *FakeImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi
|
||||
return r.Images[image.Image], nil
|
||||
}
|
||||
|
||||
// PullImage emulate pulling the image from the FakeImageService.
|
||||
func (r *FakeImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -177,6 +187,7 @@ func (r *FakeImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimea
|
||||
return imageID, nil
|
||||
}
|
||||
|
||||
// RemoveImage removes image from the FakeImageService.
|
||||
func (r *FakeImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -205,6 +216,7 @@ func (r *FakeImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error)
|
||||
return r.FakeFilesystemUsage, nil
|
||||
}
|
||||
|
||||
// AssertImagePulledWithAuth validates whether the image was pulled with auth and asserts if it wasn't.
|
||||
func (r *FakeImageService) AssertImagePulledWithAuth(t *testing.T, image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, failMsg string) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
@ -26,12 +26,17 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// FakeVersion is a version of a fake runtime.
|
||||
FakeVersion = "0.1.0"
|
||||
|
||||
FakeRuntimeName = "fakeRuntime"
|
||||
// FakeRuntimeName is the name of the fake runtime.
|
||||
FakeRuntimeName = "fakeRuntime"
|
||||
|
||||
// FakePodSandboxIPs is an IP address of the fake runtime.
|
||||
FakePodSandboxIPs = []string{"192.168.192.168"}
|
||||
)
|
||||
|
||||
// FakePodSandbox is the fake implementation of runtimeapi.PodSandboxStatus.
|
||||
type FakePodSandbox struct {
|
||||
// PodSandboxStatus contains the runtime information for a sandbox.
|
||||
runtimeapi.PodSandboxStatus
|
||||
@ -39,6 +44,7 @@ type FakePodSandbox struct {
|
||||
RuntimeHandler string
|
||||
}
|
||||
|
||||
// FakeContainer is a fake container.
|
||||
type FakeContainer struct {
|
||||
// ContainerStatus contains the runtime information for a container.
|
||||
runtimeapi.ContainerStatus
|
||||
@ -50,6 +56,7 @@ type FakeContainer struct {
|
||||
SandboxID string
|
||||
}
|
||||
|
||||
// FakeRuntimeService is a fake runetime service.
|
||||
type FakeRuntimeService struct {
|
||||
sync.Mutex
|
||||
|
||||
@ -62,6 +69,7 @@ type FakeRuntimeService struct {
|
||||
FakeContainerStats map[string]*runtimeapi.ContainerStats
|
||||
}
|
||||
|
||||
// GetContainerID returns the unique container ID from the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) GetContainerID(sandboxID, name string, attempt uint32) (string, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -74,6 +82,7 @@ func (r *FakeRuntimeService) GetContainerID(sandboxID, name string, attempt uint
|
||||
return "", fmt.Errorf("container (name, attempt, sandboxID)=(%q, %d, %q) not found", name, attempt, sandboxID)
|
||||
}
|
||||
|
||||
// SetFakeSandboxes sets the fake sandboxes for the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) SetFakeSandboxes(sandboxes []*FakePodSandbox) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -85,6 +94,7 @@ func (r *FakeRuntimeService) SetFakeSandboxes(sandboxes []*FakePodSandbox) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetFakeContainers sets fake containers for the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) SetFakeContainers(containers []*FakeContainer) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -97,6 +107,7 @@ func (r *FakeRuntimeService) SetFakeContainers(containers []*FakeContainer) {
|
||||
|
||||
}
|
||||
|
||||
// AssertCalls validates whether specified calls were made to the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) AssertCalls(calls []string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -107,12 +118,14 @@ func (r *FakeRuntimeService) AssertCalls(calls []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCalls returns the list of calls made to the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) GetCalls() []string {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
return append([]string{}, r.Called...)
|
||||
}
|
||||
|
||||
// InjectError inject the error to the next call to the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) InjectError(f string, err error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -133,6 +146,7 @@ func (r *FakeRuntimeService) popError(f string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// NewFakeRuntimeService creates a new FakeRuntimeService.
|
||||
func NewFakeRuntimeService() *FakeRuntimeService {
|
||||
return &FakeRuntimeService{
|
||||
Called: make([]string, 0),
|
||||
@ -143,6 +157,7 @@ func NewFakeRuntimeService() *FakeRuntimeService {
|
||||
}
|
||||
}
|
||||
|
||||
// Version returns version information from the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -160,6 +175,7 @@ func (r *FakeRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResp
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Status returns runtime status of the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -172,6 +188,7 @@ func (r *FakeRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
return r.FakeStatus, nil
|
||||
}
|
||||
|
||||
// RunPodSandbox emulates the run of the pod sandbox in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -220,6 +237,7 @@ func (r *FakeRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig,
|
||||
return podSandboxID, nil
|
||||
}
|
||||
|
||||
// StopPodSandbox emulates the stop of pod sandbox in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -238,6 +256,7 @@ func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovePodSandbox emulates removal of the pod sadbox in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) RemovePodSandbox(podSandboxID string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -253,6 +272,7 @@ func (r *FakeRuntimeService) RemovePodSandbox(podSandboxID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// PodSandboxStatus returns pod sandbox status from the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) PodSandboxStatus(podSandboxID string) (*runtimeapi.PodSandboxStatus, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -271,6 +291,7 @@ func (r *FakeRuntimeService) PodSandboxStatus(podSandboxID string) (*runtimeapi.
|
||||
return &status, nil
|
||||
}
|
||||
|
||||
// ListPodSandbox returns the list of pod sandboxes in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -308,6 +329,7 @@ func (r *FakeRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// PortForward emulates the set up of port forward in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) PortForward(*runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -320,6 +342,7 @@ func (r *FakeRuntimeService) PortForward(*runtimeapi.PortForwardRequest) (*runti
|
||||
return &runtimeapi.PortForwardResponse{}, nil
|
||||
}
|
||||
|
||||
// CreateContainer emulates container creation in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) CreateContainer(podSandboxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -353,6 +376,7 @@ func (r *FakeRuntimeService) CreateContainer(podSandboxID string, config *runtim
|
||||
return containerID, nil
|
||||
}
|
||||
|
||||
// StartContainer emulates start of a container in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) StartContainer(containerID string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -374,6 +398,7 @@ func (r *FakeRuntimeService) StartContainer(containerID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// StopContainer emulates stop of a container in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) StopContainer(containerID string, timeout int64) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -397,6 +422,7 @@ func (r *FakeRuntimeService) StopContainer(containerID string, timeout int64) er
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveContainer emulates remove of a container in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) RemoveContainer(containerID string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -412,6 +438,7 @@ func (r *FakeRuntimeService) RemoveContainer(containerID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListContainers returns the list of containers in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -454,6 +481,7 @@ func (r *FakeRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ContainerStatus returns the container status given the container ID in FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -472,6 +500,7 @@ func (r *FakeRuntimeService) ContainerStatus(containerID string) (*runtimeapi.Co
|
||||
return &status, nil
|
||||
}
|
||||
|
||||
// UpdateContainerResources returns the container resource in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) UpdateContainerResources(string, *runtimeapi.LinuxContainerResources) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -480,6 +509,7 @@ func (r *FakeRuntimeService) UpdateContainerResources(string, *runtimeapi.LinuxC
|
||||
return r.popError("UpdateContainerResources")
|
||||
}
|
||||
|
||||
// ExecSync emulates the sync execution of a command in a container in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -489,6 +519,7 @@ func (r *FakeRuntimeService) ExecSync(containerID string, cmd []string, timeout
|
||||
return
|
||||
}
|
||||
|
||||
// Exec emulates the execution of a command in a container in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -501,6 +532,7 @@ func (r *FakeRuntimeService) Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResp
|
||||
return &runtimeapi.ExecResponse{}, nil
|
||||
}
|
||||
|
||||
// Attach emulates the attach request in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -513,6 +545,7 @@ func (r *FakeRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.
|
||||
return &runtimeapi.AttachResponse{}, nil
|
||||
}
|
||||
|
||||
// UpdateRuntimeConfig emulates the update of a runtime config for the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) UpdateRuntimeConfig(runtimeCOnfig *runtimeapi.RuntimeConfig) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -521,6 +554,7 @@ func (r *FakeRuntimeService) UpdateRuntimeConfig(runtimeCOnfig *runtimeapi.Runti
|
||||
return r.popError("UpdateRuntimeConfig")
|
||||
}
|
||||
|
||||
// SetFakeContainerStats sets the fake container stats in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) SetFakeContainerStats(containerStats []*runtimeapi.ContainerStats) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -531,6 +565,7 @@ func (r *FakeRuntimeService) SetFakeContainerStats(containerStats []*runtimeapi.
|
||||
}
|
||||
}
|
||||
|
||||
// ContainerStats returns the container stats in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -547,6 +582,7 @@ func (r *FakeRuntimeService) ContainerStats(containerID string) (*runtimeapi.Con
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// ListContainerStats returns the list of all container stats given the filter in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@ -579,6 +615,7 @@ func (r *FakeRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStat
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ReopenContainerLog emulates call to the reopen container log in the FakeRuntimeService.
|
||||
func (r *FakeRuntimeService) ReopenContainerLog(containerID string) error {
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
|
@ -22,11 +22,13 @@ import (
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||
)
|
||||
|
||||
// BuildContainerName creates a unique container name string.
|
||||
func BuildContainerName(metadata *runtimeapi.ContainerMetadata, sandboxID string) string {
|
||||
// include the sandbox ID to make the container ID unique.
|
||||
return fmt.Sprintf("%s_%s_%d", sandboxID, metadata.Name, metadata.Attempt)
|
||||
}
|
||||
|
||||
// BuildSandboxName creates a unique sandbox name string.
|
||||
func BuildSandboxName(metadata *runtimeapi.PodSandboxMetadata) string {
|
||||
return fmt.Sprintf("%s_%s_%s_%d", metadata.Name, metadata.Namespace, metadata.Uid, metadata.Attempt)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user