feat: enable cri remote client to call with grpc calloptions
Signed-off-by: haoyun <yun.hao@daocloud.io>
This commit is contained in:
parent
0f27a423ef
commit
d16942cf16
@ -37,43 +37,44 @@ package cri
|
||||
import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
)
|
||||
|
||||
// RuntimeVersioner contains methods for runtime name, version and API version.
|
||||
type RuntimeVersioner interface {
|
||||
// Version returns the runtime name, runtime version and runtime API version
|
||||
Version(apiVersion string) (*runtimeapi.VersionResponse, error)
|
||||
Version(apiVersion string, opts ...grpc.CallOption) (*runtimeapi.VersionResponse, error)
|
||||
}
|
||||
|
||||
// ContainerManager contains methods to manipulate containers managed by a
|
||||
// container runtime. The methods are thread-safe.
|
||||
type ContainerManager interface {
|
||||
// CreateContainer creates a new container in specified PodSandbox.
|
||||
CreateContainer(podSandboxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error)
|
||||
CreateContainer(podSandboxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig, opts ...grpc.CallOption) (string, error)
|
||||
// StartContainer starts the container.
|
||||
StartContainer(containerID string) error
|
||||
StartContainer(containerID string, opts ...grpc.CallOption) error
|
||||
// StopContainer stops a running container with a grace period (i.e., timeout).
|
||||
StopContainer(containerID string, timeout int64) error
|
||||
StopContainer(containerID string, timeout int64, opts ...grpc.CallOption) error
|
||||
// RemoveContainer removes the container.
|
||||
RemoveContainer(containerID string) error
|
||||
RemoveContainer(containerID string, opts ...grpc.CallOption) error
|
||||
// ListContainers lists all containers by filters.
|
||||
ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error)
|
||||
ListContainers(filter *runtimeapi.ContainerFilter, opts ...grpc.CallOption) ([]*runtimeapi.Container, error)
|
||||
// ContainerStatus returns the status of the container.
|
||||
ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error)
|
||||
ContainerStatus(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStatus, error)
|
||||
// UpdateContainerResources updates the cgroup resources for the container.
|
||||
UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error
|
||||
UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources, opts ...grpc.CallOption) error
|
||||
// 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.
|
||||
ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error)
|
||||
ExecSync(containerID string, cmd []string, timeout time.Duration, opts ...grpc.CallOption) (stdout []byte, stderr []byte, err error)
|
||||
// Exec prepares a streaming endpoint to execute a command in the container, and returns the address.
|
||||
Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error)
|
||||
Exec(req *runtimeapi.ExecRequest, opts ...grpc.CallOption) (*runtimeapi.ExecResponse, error)
|
||||
// Attach prepares a streaming endpoint to attach to a running container, and returns the address.
|
||||
Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error)
|
||||
Attach(req *runtimeapi.AttachRequest, opts ...grpc.CallOption) (*runtimeapi.AttachResponse, error)
|
||||
// ReopenContainerLog asks runtime to reopen the stdout/stderr log file
|
||||
// for the container. If it returns error, new container log file MUST NOT
|
||||
// be created.
|
||||
ReopenContainerLog(ContainerID string) error
|
||||
ReopenContainerLog(ContainerID string, opts ...grpc.CallOption) error
|
||||
}
|
||||
|
||||
// PodSandboxManager contains methods for operating on PodSandboxes. The methods
|
||||
@ -81,19 +82,19 @@ type ContainerManager interface {
|
||||
type PodSandboxManager interface {
|
||||
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
|
||||
// the sandbox is in ready state.
|
||||
RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error)
|
||||
RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string, opts ...grpc.CallOption) (string, error)
|
||||
// StopPodSandbox stops the sandbox. If there are any running containers in the
|
||||
// sandbox, they should be force terminated.
|
||||
StopPodSandbox(podSandboxID string) error
|
||||
StopPodSandbox(podSandboxID string, opts ...grpc.CallOption) error
|
||||
// RemovePodSandbox removes the sandbox. If there are running containers in the
|
||||
// sandbox, they should be forcibly removed.
|
||||
RemovePodSandbox(podSandboxID string) error
|
||||
RemovePodSandbox(podSandboxID string, opts ...grpc.CallOption) error
|
||||
// PodSandboxStatus returns the Status of the PodSandbox.
|
||||
PodSandboxStatus(podSandboxID string) (*runtimeapi.PodSandboxStatus, error)
|
||||
PodSandboxStatus(podSandboxID string, opts ...grpc.CallOption) (*runtimeapi.PodSandboxStatus, error)
|
||||
// ListPodSandbox returns a list of Sandbox.
|
||||
ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error)
|
||||
ListPodSandbox(filter *runtimeapi.PodSandboxFilter, opts ...grpc.CallOption) ([]*runtimeapi.PodSandbox, error)
|
||||
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
|
||||
PortForward(*runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error)
|
||||
PortForward(req *runtimeapi.PortForwardRequest, opts ...grpc.CallOption) (*runtimeapi.PortForwardResponse, error)
|
||||
}
|
||||
|
||||
// ContainerStatsManager contains methods for retrieving the container
|
||||
@ -101,9 +102,9 @@ type PodSandboxManager interface {
|
||||
type ContainerStatsManager interface {
|
||||
// ContainerStats returns stats of the container. If the container does not
|
||||
// exist, the call returns an error.
|
||||
ContainerStats(containerID string) (*runtimeapi.ContainerStats, error)
|
||||
ContainerStats(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStats, error)
|
||||
// ListContainerStats returns stats of all running containers.
|
||||
ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error)
|
||||
ListContainerStats(filter *runtimeapi.ContainerStatsFilter, opts ...grpc.CallOption) ([]*runtimeapi.ContainerStats, error)
|
||||
}
|
||||
|
||||
// RuntimeService interface should be implemented by a container runtime.
|
||||
@ -115,9 +116,9 @@ type RuntimeService interface {
|
||||
ContainerStatsManager
|
||||
|
||||
// UpdateRuntimeConfig updates runtime configuration if specified
|
||||
UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error
|
||||
UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig, opts ...grpc.CallOption) error
|
||||
// Status returns the status of the runtime.
|
||||
Status() (*runtimeapi.RuntimeStatus, error)
|
||||
Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeStatus, error)
|
||||
}
|
||||
|
||||
// ImageManagerService interface should be implemented by a container image
|
||||
@ -125,13 +126,13 @@ type RuntimeService interface {
|
||||
// The methods should be thread-safe.
|
||||
type ImageManagerService interface {
|
||||
// ListImages lists the existing images.
|
||||
ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error)
|
||||
ListImages(filter *runtimeapi.ImageFilter, opts ...grpc.CallOption) ([]*runtimeapi.Image, error)
|
||||
// ImageStatus returns the status of the image.
|
||||
ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error)
|
||||
ImageStatus(image *runtimeapi.ImageSpec, opts ...grpc.CallOption) (*runtimeapi.Image, error)
|
||||
// PullImage pulls an image with the authentication config.
|
||||
PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error)
|
||||
PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig, podSandboxConfig *runtimeapi.PodSandboxConfig, opts ...grpc.CallOption) (string, error)
|
||||
// RemoveImage removes the image.
|
||||
RemoveImage(image *runtimeapi.ImageSpec) error
|
||||
RemoveImage(image *runtimeapi.ImageSpec, opts ...grpc.CallOption) error
|
||||
// ImageFsInfo returns information of the filesystem that is used to store images.
|
||||
ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error)
|
||||
ImageFsInfo(opts ...grpc.CallOption) ([]*runtimeapi.FilesystemUsage, error)
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ func ConnectDaemons() error {
|
||||
}
|
||||
// Since CRI grpc client doesn't have `WithBlock` specified, we
|
||||
// need to check whether it is actually connected.
|
||||
// TODO(random-liu): Extend cri remote client to accept extra grpc options.
|
||||
// TODO(#6069) Use grpc options to block on connect and remove for this list containers request.
|
||||
_, err = runtimeService.ListContainers(&runtime.ContainerFilter{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to list containers")
|
||||
|
@ -77,13 +77,13 @@ func NewImageService(endpoint string, connectionTimeout time.Duration) (internal
|
||||
}
|
||||
|
||||
// ListImages lists available images.
|
||||
func (r *ImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
||||
func (r *ImageService) ListImages(filter *runtimeapi.ImageFilter, opts ...grpc.CallOption) ([]*runtimeapi.Image, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.imageClient.ListImages(ctx, &runtimeapi.ListImagesRequest{
|
||||
Filter: filter,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("ListImages with filter %+v from image service failed: %v", filter, err)
|
||||
return nil, err
|
||||
@ -93,13 +93,13 @@ func (r *ImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi
|
||||
}
|
||||
|
||||
// ImageStatus returns the status of the image.
|
||||
func (r *ImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
|
||||
func (r *ImageService) ImageStatus(image *runtimeapi.ImageSpec, opts ...grpc.CallOption) (*runtimeapi.Image, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.imageClient.ImageStatus(ctx, &runtimeapi.ImageStatusRequest{
|
||||
Image: image,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("ImageStatus %q from image service failed: %v", image.Image, err)
|
||||
return nil, err
|
||||
@ -117,7 +117,7 @@ func (r *ImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Ima
|
||||
}
|
||||
|
||||
// PullImage pulls an image with authentication config.
|
||||
func (r *ImageService) 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, opts ...grpc.CallOption) (string, error) {
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
@ -125,7 +125,7 @@ func (r *ImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.A
|
||||
Image: image,
|
||||
Auth: auth,
|
||||
SandboxConfig: podSandboxConfig,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("PullImage %q from image service failed: %v", image.Image, err)
|
||||
return "", err
|
||||
@ -141,13 +141,13 @@ func (r *ImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.A
|
||||
}
|
||||
|
||||
// RemoveImage removes the image.
|
||||
func (r *ImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
|
||||
func (r *ImageService) RemoveImage(image *runtimeapi.ImageSpec, opts ...grpc.CallOption) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.imageClient.RemoveImage(ctx, &runtimeapi.RemoveImageRequest{
|
||||
Image: image,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("RemoveImage %q from image service failed: %v", image.Image, err)
|
||||
return err
|
||||
@ -157,13 +157,13 @@ func (r *ImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
|
||||
}
|
||||
|
||||
// ImageFsInfo returns information of the filesystem that is used to store images.
|
||||
func (r *ImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error) {
|
||||
func (r *ImageService) ImageFsInfo(opts ...grpc.CallOption) ([]*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()
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.imageClient.ImageFsInfo(ctx, &runtimeapi.ImageFsInfoRequest{})
|
||||
resp, err := r.imageClient.ImageFsInfo(ctx, &runtimeapi.ImageFsInfoRequest{}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("ImageFsInfo from image service failed: %v", err)
|
||||
return nil, err
|
||||
|
@ -87,7 +87,7 @@ func NewRuntimeService(endpoint string, connectionTimeout time.Duration) (intern
|
||||
}
|
||||
|
||||
// Version returns the runtime name, runtime version and runtime API version.
|
||||
func (r *RuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
|
||||
func (r *RuntimeService) Version(apiVersion string, opts ...grpc.CallOption) (*runtimeapi.VersionResponse, error) {
|
||||
klog.V(10).Infof("[RuntimeService] Version (apiVersion=%v, timeout=%v)", apiVersion, r.timeout)
|
||||
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
@ -95,7 +95,7 @@ func (r *RuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse
|
||||
|
||||
typedVersion, err := r.runtimeClient.Version(ctx, &runtimeapi.VersionRequest{
|
||||
Version: apiVersion,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("Version from runtime service failed: %v", err)
|
||||
return nil, err
|
||||
@ -112,7 +112,7 @@ func (r *RuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse
|
||||
|
||||
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
|
||||
// the sandbox is in ready state.
|
||||
func (r *RuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string) (string, error) {
|
||||
func (r *RuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runtimeHandler string, opts ...grpc.CallOption) (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
|
||||
@ -125,7 +125,7 @@ func (r *RuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runt
|
||||
resp, err := r.runtimeClient.RunPodSandbox(ctx, &runtimeapi.RunPodSandboxRequest{
|
||||
Config: config,
|
||||
RuntimeHandler: runtimeHandler,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("RunPodSandbox from runtime service failed: %v", err)
|
||||
return "", err
|
||||
@ -144,7 +144,7 @@ func (r *RuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig, runt
|
||||
|
||||
// StopPodSandbox stops the sandbox. If there are any running containers in the
|
||||
// sandbox, they should be forced to termination.
|
||||
func (r *RuntimeService) StopPodSandbox(podSandBoxID string) error {
|
||||
func (r *RuntimeService) StopPodSandbox(podSandBoxID string, opts ...grpc.CallOption) error {
|
||||
klog.V(10).Infof("[RuntimeService] StopPodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
@ -152,7 +152,7 @@ func (r *RuntimeService) StopPodSandbox(podSandBoxID string) error {
|
||||
|
||||
_, err := r.runtimeClient.StopPodSandbox(ctx, &runtimeapi.StopPodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("StopPodSandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
return err
|
||||
@ -165,14 +165,14 @@ func (r *RuntimeService) StopPodSandbox(podSandBoxID string) error {
|
||||
|
||||
// RemovePodSandbox removes the sandbox. If there are any containers in the
|
||||
// sandbox, they should be forcibly removed.
|
||||
func (r *RuntimeService) RemovePodSandbox(podSandBoxID string) error {
|
||||
func (r *RuntimeService) RemovePodSandbox(podSandBoxID string, opts ...grpc.CallOption) error {
|
||||
klog.V(10).Infof("[RuntimeService] RemovePodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.RemovePodSandbox(ctx, &runtimeapi.RemovePodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("RemovePodSandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
return err
|
||||
@ -184,14 +184,14 @@ func (r *RuntimeService) RemovePodSandbox(podSandBoxID string) error {
|
||||
}
|
||||
|
||||
// PodSandboxStatus returns the status of the PodSandbox.
|
||||
func (r *RuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
|
||||
func (r *RuntimeService) PodSandboxStatus(podSandBoxID string, opts ...grpc.CallOption) (*runtimeapi.PodSandboxStatus, error) {
|
||||
klog.V(10).Infof("[RuntimeService] PodSandboxStatus (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.PodSandboxStatus(ctx, &runtimeapi.PodSandboxStatusRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -208,14 +208,14 @@ func (r *RuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodS
|
||||
}
|
||||
|
||||
// ListPodSandbox returns a list of PodSandboxes.
|
||||
func (r *RuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
||||
func (r *RuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter, opts ...grpc.CallOption) ([]*runtimeapi.PodSandbox, error) {
|
||||
klog.V(10).Infof("[RuntimeService] ListPodSandbox (filter=%v, timeout=%v)", filter, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ListPodSandbox(ctx, &runtimeapi.ListPodSandboxRequest{
|
||||
Filter: filter,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("ListPodSandbox with filter %+v from runtime service failed: %v", filter, err)
|
||||
return nil, err
|
||||
@ -227,7 +227,7 @@ func (r *RuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]
|
||||
}
|
||||
|
||||
// CreateContainer creates a new container in the specified PodSandbox.
|
||||
func (r *RuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
func (r *RuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig, opts ...grpc.CallOption) (string, error) {
|
||||
klog.V(10).Infof("[RuntimeService] CreateContainer (podSandBoxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -236,7 +236,7 @@ func (r *RuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi
|
||||
PodSandboxId: podSandBoxID,
|
||||
Config: config,
|
||||
SandboxConfig: sandboxConfig,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("CreateContainer in sandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
return "", err
|
||||
@ -253,14 +253,14 @@ func (r *RuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi
|
||||
}
|
||||
|
||||
// StartContainer starts the container.
|
||||
func (r *RuntimeService) StartContainer(containerID string) error {
|
||||
func (r *RuntimeService) StartContainer(containerID string, opts ...grpc.CallOption) error {
|
||||
klog.V(10).Infof("[RuntimeService] StartContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.StartContainer(ctx, &runtimeapi.StartContainerRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("StartContainer %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
@ -271,7 +271,7 @@ func (r *RuntimeService) StartContainer(containerID string) error {
|
||||
}
|
||||
|
||||
// StopContainer stops a running container with a grace period (i.e., timeout).
|
||||
func (r *RuntimeService) StopContainer(containerID string, timeout int64) error {
|
||||
func (r *RuntimeService) StopContainer(containerID string, timeout int64, opts ...grpc.CallOption) error {
|
||||
klog.V(10).Infof("[RuntimeService] 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.
|
||||
@ -283,7 +283,7 @@ func (r *RuntimeService) StopContainer(containerID string, timeout int64) error
|
||||
_, err := r.runtimeClient.StopContainer(ctx, &runtimeapi.StopContainerRequest{
|
||||
ContainerId: containerID,
|
||||
Timeout: timeout,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("StopContainer %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
@ -295,7 +295,7 @@ func (r *RuntimeService) StopContainer(containerID string, timeout int64) error
|
||||
|
||||
// RemoveContainer removes the container. If the container is running, the container
|
||||
// should be forced to removal.
|
||||
func (r *RuntimeService) RemoveContainer(containerID string) error {
|
||||
func (r *RuntimeService) RemoveContainer(containerID string, opts ...grpc.CallOption) error {
|
||||
klog.V(10).Infof("[RuntimeService] RemoveContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -303,7 +303,7 @@ func (r *RuntimeService) RemoveContainer(containerID string) error {
|
||||
r.logReduction.ClearID(containerID)
|
||||
_, err := r.runtimeClient.RemoveContainer(ctx, &runtimeapi.RemoveContainerRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("RemoveContainer %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
@ -314,14 +314,14 @@ func (r *RuntimeService) RemoveContainer(containerID string) error {
|
||||
}
|
||||
|
||||
// ListContainers lists containers by filters.
|
||||
func (r *RuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
||||
func (r *RuntimeService) ListContainers(filter *runtimeapi.ContainerFilter, opts ...grpc.CallOption) ([]*runtimeapi.Container, error) {
|
||||
klog.V(10).Infof("[RuntimeService] ListContainers (filter=%v, timeout=%v)", filter, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ListContainers(ctx, &runtimeapi.ListContainersRequest{
|
||||
Filter: filter,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("ListContainers with filter %+v from runtime service failed: %v", filter, err)
|
||||
return nil, err
|
||||
@ -332,14 +332,14 @@ func (r *RuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*
|
||||
}
|
||||
|
||||
// ContainerStatus returns the container status.
|
||||
func (r *RuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
|
||||
func (r *RuntimeService) ContainerStatus(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStatus, error) {
|
||||
klog.V(10).Infof("[RuntimeService] ContainerStatus (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ContainerStatus(ctx, &runtimeapi.ContainerStatusRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
// Don't spam the log with endless messages about the same failure.
|
||||
if r.logReduction.ShouldMessageBePrinted(err.Error(), containerID) {
|
||||
@ -361,7 +361,7 @@ func (r *RuntimeService) ContainerStatus(containerID string) (*runtimeapi.Contai
|
||||
}
|
||||
|
||||
// UpdateContainerResources updates a containers resource config
|
||||
func (r *RuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error {
|
||||
func (r *RuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources, opts ...grpc.CallOption) error {
|
||||
klog.V(10).Infof("[RuntimeService] UpdateContainerResources (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -369,7 +369,7 @@ func (r *RuntimeService) UpdateContainerResources(containerID string, resources
|
||||
_, err := r.runtimeClient.UpdateContainerResources(ctx, &runtimeapi.UpdateContainerResourcesRequest{
|
||||
ContainerId: containerID,
|
||||
Linux: resources,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("UpdateContainerResources %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
@ -381,7 +381,7 @@ func (r *RuntimeService) UpdateContainerResources(containerID string, resources
|
||||
|
||||
// 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 *RuntimeService) 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, opts ...grpc.CallOption) (stdout []byte, stderr []byte, err error) {
|
||||
klog.V(10).Infof("[RuntimeService] ExecSync (containerID=%v, timeout=%v)", containerID, timeout)
|
||||
// Do not set timeout when timeout is 0.
|
||||
var ctx context.Context
|
||||
@ -401,7 +401,7 @@ func (r *RuntimeService) ExecSync(containerID string, cmd []string, timeout time
|
||||
Cmd: cmd,
|
||||
Timeout: timeoutSeconds,
|
||||
}
|
||||
resp, err := r.runtimeClient.ExecSync(ctx, req)
|
||||
resp, err := r.runtimeClient.ExecSync(ctx, req, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("ExecSync %s '%s' from runtime service failed: %v", containerID, strings.Join(cmd, " "), err)
|
||||
return nil, nil, err
|
||||
@ -420,12 +420,12 @@ func (r *RuntimeService) ExecSync(containerID string, cmd []string, timeout time
|
||||
}
|
||||
|
||||
// Exec prepares a streaming endpoint to execute a command in the container, and returns the address.
|
||||
func (r *RuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
|
||||
func (r *RuntimeService) Exec(req *runtimeapi.ExecRequest, opts ...grpc.CallOption) (*runtimeapi.ExecResponse, error) {
|
||||
klog.V(10).Infof("[RuntimeService] Exec (timeout=%v)", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Exec(ctx, req)
|
||||
resp, err := r.runtimeClient.Exec(ctx, req, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("Exec %s '%s' from runtime service failed: %v", req.ContainerId, strings.Join(req.Cmd, " "), err)
|
||||
return nil, err
|
||||
@ -442,12 +442,12 @@ func (r *RuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResp
|
||||
}
|
||||
|
||||
// Attach prepares a streaming endpoint to attach to a running container, and returns the address.
|
||||
func (r *RuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
|
||||
func (r *RuntimeService) Attach(req *runtimeapi.AttachRequest, opts ...grpc.CallOption) (*runtimeapi.AttachResponse, error) {
|
||||
klog.V(10).Infof("[RuntimeService] Attach (containerId=%v, timeout=%v)", req.ContainerId, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Attach(ctx, req)
|
||||
resp, err := r.runtimeClient.Attach(ctx, req, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("Attach %s from runtime service failed: %v", req.ContainerId, err)
|
||||
return nil, err
|
||||
@ -463,12 +463,12 @@ func (r *RuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.Atta
|
||||
}
|
||||
|
||||
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
|
||||
func (r *RuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
|
||||
func (r *RuntimeService) PortForward(req *runtimeapi.PortForwardRequest, opts ...grpc.CallOption) (*runtimeapi.PortForwardResponse, error) {
|
||||
klog.V(10).Infof("[RuntimeService] PortForward (podSandboxID=%v, port=%v, timeout=%v)", req.PodSandboxId, req.Port, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.PortForward(ctx, req)
|
||||
resp, err := r.runtimeClient.PortForward(ctx, req, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("PortForward %s from runtime service failed: %v", req.PodSandboxId, err)
|
||||
return nil, err
|
||||
@ -487,7 +487,7 @@ func (r *RuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (*runti
|
||||
// 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 *RuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error {
|
||||
func (r *RuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig, opts ...grpc.CallOption) error {
|
||||
klog.V(10).Infof("[RuntimeService] UpdateRuntimeConfig (runtimeConfig=%v, timeout=%v)", runtimeConfig, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -497,7 +497,7 @@ func (r *RuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeCo
|
||||
// really looking to surface destination unreachable.
|
||||
_, err := r.runtimeClient.UpdateRuntimeConfig(ctx, &runtimeapi.UpdateRuntimeConfigRequest{
|
||||
RuntimeConfig: runtimeConfig,
|
||||
})
|
||||
}, opts...)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@ -508,12 +508,12 @@ func (r *RuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeCo
|
||||
}
|
||||
|
||||
// Status returns the status of the runtime.
|
||||
func (r *RuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
func (r *RuntimeService) Status(opts ...grpc.CallOption) (*runtimeapi.RuntimeStatus, error) {
|
||||
klog.V(10).Infof("[RuntimeService] Status (timeout=%v)", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Status(ctx, &runtimeapi.StatusRequest{})
|
||||
resp, err := r.runtimeClient.Status(ctx, &runtimeapi.StatusRequest{}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("Status from runtime service failed: %v", err)
|
||||
return nil, err
|
||||
@ -531,14 +531,14 @@ func (r *RuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
}
|
||||
|
||||
// ContainerStats returns the stats of the container.
|
||||
func (r *RuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
||||
func (r *RuntimeService) ContainerStats(containerID string, opts ...grpc.CallOption) (*runtimeapi.ContainerStats, error) {
|
||||
klog.V(10).Infof("[RuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ContainerStats(ctx, &runtimeapi.ContainerStatsRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
if r.logReduction.ShouldMessageBePrinted(err.Error(), containerID) {
|
||||
klog.Errorf("ContainerStats %q from runtime service failed: %v", containerID, err)
|
||||
@ -552,7 +552,7 @@ func (r *RuntimeService) ContainerStats(containerID string) (*runtimeapi.Contain
|
||||
}
|
||||
|
||||
// ListContainerStats lists all container stats given the provided filter
|
||||
func (r *RuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
|
||||
func (r *RuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter, opts ...grpc.CallOption) ([]*runtimeapi.ContainerStats, error) {
|
||||
klog.V(10).Infof("[RuntimeService] 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?
|
||||
@ -561,7 +561,7 @@ func (r *RuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFil
|
||||
|
||||
resp, err := r.runtimeClient.ListContainerStats(ctx, &runtimeapi.ListContainerStatsRequest{
|
||||
Filter: filter,
|
||||
})
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("ListContainerStats with filter %+v from runtime service failed: %v", filter, err)
|
||||
return nil, err
|
||||
@ -572,12 +572,14 @@ func (r *RuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFil
|
||||
}
|
||||
|
||||
// ReopenContainerLog reopens the container log for the given container ID
|
||||
func (r *RuntimeService) ReopenContainerLog(containerID string) error {
|
||||
func (r *RuntimeService) ReopenContainerLog(containerID string, opts ...grpc.CallOption) error {
|
||||
klog.V(10).Infof("[RuntimeService] ReopenContainerLog (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.ReopenContainerLog(ctx, &runtimeapi.ReopenContainerLogRequest{ContainerId: containerID})
|
||||
_, err := r.runtimeClient.ReopenContainerLog(ctx, &runtimeapi.ReopenContainerLogRequest{
|
||||
ContainerId: containerID,
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
klog.Errorf("ReopenContainerLog %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user