mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 15:58:37 +00:00
pkg/kubelet/cri/remote: migrate to structured logs
This commit is contained in:
parent
972ae2f2c2
commit
8d86470417
@ -38,7 +38,7 @@ type remoteImageService struct {
|
||||
|
||||
// NewRemoteImageService creates a new internalapi.ImageManagerService.
|
||||
func NewRemoteImageService(endpoint string, connectionTimeout time.Duration) (internalapi.ImageManagerService, error) {
|
||||
klog.V(3).Infof("Connecting to image service %s", endpoint)
|
||||
klog.V(3).InfoS("Connecting to image service", "endpoint", endpoint)
|
||||
addr, dialer, err := util.GetAddressAndDialer(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -49,7 +49,7 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration) (in
|
||||
|
||||
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
||||
if err != nil {
|
||||
klog.Errorf("Connect remote image service %s failed: %v", addr, err)
|
||||
klog.ErrorS(err, "Connect remote image service failed", "address", addr)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func (r *remoteImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runt
|
||||
Filter: filter,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("ListImages with filter %+v from image service failed: %v", filter, err)
|
||||
klog.ErrorS(err, "ListImages with filter from image service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -84,15 +84,16 @@ func (r *remoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimea
|
||||
Image: image,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("ImageStatus %q from image service failed: %v", image.Image, err)
|
||||
klog.ErrorS(err, "Get ImageStatus from image service failed", "image", image.Image)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Image != nil {
|
||||
if resp.Image.Id == "" || resp.Image.Size_ == 0 {
|
||||
errorMessage := fmt.Sprintf("Id or size of image %q is not set", image.Image)
|
||||
klog.Errorf("ImageStatus failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "ImageStatus failed", "image", image.Image)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,13 +111,13 @@ func (r *remoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtim
|
||||
SandboxConfig: podSandboxConfig,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("PullImage %q from image service failed: %v", image.Image, err)
|
||||
klog.ErrorS(err, "PullImage from image service failed", "image", image.Image)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if resp.ImageRef == "" {
|
||||
klog.ErrorS(errors.New("PullImage failed"), "ImageRef of image is not set", "image", image.Image)
|
||||
errorMessage := fmt.Sprintf("imageRef of image %q is not set", image.Image)
|
||||
klog.Errorf("PullImage failed: %s", errorMessage)
|
||||
return "", errors.New(errorMessage)
|
||||
}
|
||||
|
||||
@ -132,7 +133,7 @@ func (r *remoteImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
|
||||
Image: image,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("RemoveImage %q from image service failed: %v", image.Image, err)
|
||||
klog.ErrorS(err, "RemoveImage from image service failed", "image", image.Image)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -148,7 +149,7 @@ func (r *remoteImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error
|
||||
|
||||
resp, err := r.imageClient.ImageFsInfo(ctx, &runtimeapi.ImageFsInfoRequest{})
|
||||
if err != nil {
|
||||
klog.Errorf("ImageFsInfo from image service failed: %v", err)
|
||||
klog.ErrorS(err, "ImageFsInfo from image service failed")
|
||||
return nil, err
|
||||
}
|
||||
return resp.GetImageFilesystems(), nil
|
||||
|
@ -51,7 +51,7 @@ const (
|
||||
|
||||
// NewRemoteRuntimeService creates a new internalapi.RuntimeService.
|
||||
func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (internalapi.RuntimeService, error) {
|
||||
klog.V(3).Infof("Connecting to runtime service %s", endpoint)
|
||||
klog.V(3).InfoS("Connecting to runtime service", "endpoint", endpoint)
|
||||
addr, dialer, err := util.GetAddressAndDialer(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -61,7 +61,7 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (
|
||||
|
||||
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
||||
if err != nil {
|
||||
klog.Errorf("Connect remote runtime %s failed: %v", addr, err)
|
||||
klog.ErrorS(err, "Connect remote runtime failed", "address", addr)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -74,7 +74,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) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Version (apiVersion=%v, timeout=%v)", apiVersion, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Version", "apiVersion", apiVersion, "timeout", r.timeout)
|
||||
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -83,11 +83,11 @@ func (r *remoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionRe
|
||||
Version: apiVersion,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("Version from runtime service failed: %v", err)
|
||||
klog.ErrorS(err, "Version from runtime service failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Version Response (typedVersion=%v)", typedVersion)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Version Response", "apiVersion", typedVersion)
|
||||
|
||||
if typedVersion.Version == "" || typedVersion.RuntimeName == "" || typedVersion.RuntimeApiVersion == "" || typedVersion.RuntimeVersion == "" {
|
||||
return nil, fmt.Errorf("not all fields are set in VersionResponse (%q)", *typedVersion)
|
||||
@ -103,7 +103,7 @@ func (r *remoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig
|
||||
// TODO: Make the pod sandbox timeout configurable.
|
||||
timeout := r.timeout * 2
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] RunPodSandbox (config=%v, runtimeHandler=%v, timeout=%v)", config, runtimeHandler, timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] RunPodSandbox", "config", config, "runtimeHandler", runtimeHandler, "timeout", timeout)
|
||||
|
||||
ctx, cancel := getContextWithTimeout(timeout)
|
||||
defer cancel()
|
||||
@ -113,17 +113,18 @@ func (r *remoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig
|
||||
RuntimeHandler: runtimeHandler,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("RunPodSandbox from runtime service failed: %v", err)
|
||||
klog.ErrorS(err, "RunPodSandbox from runtime service failed")
|
||||
return "", err
|
||||
}
|
||||
|
||||
if resp.PodSandboxId == "" {
|
||||
errorMessage := fmt.Sprintf("PodSandboxId is not set for sandbox %q", config.GetMetadata())
|
||||
klog.Errorf("RunPodSandbox failed: %s", errorMessage)
|
||||
return "", errors.New(errorMessage)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "RunPodSandbox failed")
|
||||
return "", err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] RunPodSandbox Response (PodSandboxId=%v)", resp.PodSandboxId)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] RunPodSandbox Response", "podSandboxID", resp.PodSandboxId)
|
||||
|
||||
return resp.PodSandboxId, nil
|
||||
}
|
||||
@ -131,7 +132,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 {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StopPodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] StopPodSandbox", "podSandboxID", podSandBoxID, "timeout", r.timeout)
|
||||
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
@ -140,11 +141,11 @@ func (r *remoteRuntimeService) StopPodSandbox(podSandBoxID string) error {
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("StopPodSandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
klog.ErrorS(err, "StopPodSandbox from runtime service failed", "podSandboxID", podSandBoxID)
|
||||
return err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StopPodSandbox Response (podSandboxID=%v)", podSandBoxID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] StopPodSandbox Response", "podSandboxID", podSandBoxID)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -152,7 +153,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 {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] RemovePodSandbox (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] RemovePodSandbox", "podSandboxID", podSandBoxID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -160,18 +161,18 @@ func (r *remoteRuntimeService) RemovePodSandbox(podSandBoxID string) error {
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("RemovePodSandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
klog.ErrorS(err, "RemovePodSandbox from runtime service failed", "podSandboxID", podSandBoxID)
|
||||
return err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] RemovePodSandbox Response (podSandboxID=%v)", podSandBoxID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] RemovePodSandbox Response", "podSandboxID", podSandBoxID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PodSandboxStatus returns the status of the PodSandbox.
|
||||
func (r *remoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] PodSandboxStatus (podSandboxID=%v, timeout=%v)", podSandBoxID, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] PodSandboxStatus", "podSandboxID", podSandBoxID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -182,7 +183,7 @@ func (r *remoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeap
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] PodSandboxStatus Response (podSandboxID=%v, status=%v)", podSandBoxID, resp.Status)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] PodSandboxStatus Response", "podSandboxID", podSandBoxID, "status", resp.Status)
|
||||
|
||||
if resp.Status != nil {
|
||||
if err := verifySandboxStatus(resp.Status); err != nil {
|
||||
@ -195,7 +196,7 @@ func (r *remoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeap
|
||||
|
||||
// ListPodSandbox returns a list of PodSandboxes.
|
||||
func (r *remoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ListPodSandbox (filter=%v, timeout=%v)", filter, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListPodSandbox", "filter", filter, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -203,18 +204,18 @@ func (r *remoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilte
|
||||
Filter: filter,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("ListPodSandbox with filter %+v from runtime service failed: %v", filter, err)
|
||||
klog.ErrorS(err, "ListPodSandbox with filter from runtime service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ListPodSandbox Response (filter=%v, items=%v)", filter, resp.Items)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListPodSandbox Response", "filter", filter, "items", resp.Items)
|
||||
|
||||
return resp.Items, nil
|
||||
}
|
||||
|
||||
// CreateContainer creates a new container in the specified PodSandbox.
|
||||
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)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] CreateContainer", "podSandboxID", podSandBoxID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -224,15 +225,16 @@ func (r *remoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
|
||||
SandboxConfig: sandboxConfig,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("CreateContainer in sandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
klog.ErrorS(err, "CreateContainer in sandbox from runtime service failed", "podSandboxID", podSandBoxID)
|
||||
return "", err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] CreateContainer (podSandBoxID=%v, ContainerId=%v)", podSandBoxID, resp.ContainerId)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] CreateContainer", "podSandboxID", podSandBoxID, "containerID", resp.ContainerId)
|
||||
if resp.ContainerId == "" {
|
||||
errorMessage := fmt.Sprintf("ContainerId is not set for container %q", config.GetMetadata())
|
||||
klog.Errorf("CreateContainer failed: %s", errorMessage)
|
||||
return "", errors.New(errorMessage)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "CreateContainer failed")
|
||||
return "", err
|
||||
}
|
||||
|
||||
return resp.ContainerId, nil
|
||||
@ -240,7 +242,7 @@ func (r *remoteRuntimeService) CreateContainer(podSandBoxID string, config *runt
|
||||
|
||||
// StartContainer starts the container.
|
||||
func (r *remoteRuntimeService) StartContainer(containerID string) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StartContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] StartContainer", "containerID", containerID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -248,17 +250,17 @@ func (r *remoteRuntimeService) StartContainer(containerID string) error {
|
||||
ContainerId: containerID,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("StartContainer %q from runtime service failed: %v", containerID, err)
|
||||
klog.ErrorS(err, "StartContainer from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StartContainer Response (containerID=%v)", containerID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] StartContainer Response", "containerID", containerID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// StopContainer stops a running container with a grace period (i.e., timeout).
|
||||
func (r *remoteRuntimeService) StopContainer(containerID string, timeout int64) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StopContainer (containerID=%v, timeout=%v)", containerID, timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] StopContainer", "containerID", containerID, "timeout", timeout)
|
||||
// Use timeout + default timeout (2 minutes) as timeout to leave extra time
|
||||
// for SIGKILL container and request latency.
|
||||
t := r.timeout + time.Duration(timeout)*time.Second
|
||||
@ -271,10 +273,10 @@ func (r *remoteRuntimeService) StopContainer(containerID string, timeout int64)
|
||||
Timeout: timeout,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("StopContainer %q from runtime service failed: %v", containerID, err)
|
||||
klog.ErrorS(err, "StopContainer from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] StopContainer Response (containerID=%v)", containerID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] StopContainer Response", "containerID", containerID)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -282,7 +284,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 {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] RemoveContainer (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] RemoveContainer", "containerID", containerID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -291,17 +293,17 @@ func (r *remoteRuntimeService) RemoveContainer(containerID string) error {
|
||||
ContainerId: containerID,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("RemoveContainer %q from runtime service failed: %v", containerID, err)
|
||||
klog.ErrorS(err, "RemoveContainer from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] RemoveContainer Response (containerID=%v)", containerID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] RemoveContainer Response", "containerID", containerID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListContainers lists containers by filters.
|
||||
func (r *remoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ListContainers (filter=%v, timeout=%v)", filter, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListContainers", "filter", filter, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -309,17 +311,17 @@ func (r *remoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter
|
||||
Filter: filter,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("ListContainers with filter %+v from runtime service failed: %v", filter, err)
|
||||
klog.ErrorS(err, "ListContainers with filter from runtime service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ListContainers Response (filter=%v, containers=%v)", filter, resp.Containers)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListContainers Response", "filter", filter, "containers", resp.Containers)
|
||||
|
||||
return resp.Containers, nil
|
||||
}
|
||||
|
||||
// ContainerStatus returns the container status.
|
||||
func (r *remoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ContainerStatus (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ContainerStatus", "containerID", containerID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -329,16 +331,16 @@ func (r *remoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
|
||||
if err != nil {
|
||||
// Don't spam the log with endless messages about the same failure.
|
||||
if r.logReduction.ShouldMessageBePrinted(err.Error(), containerID) {
|
||||
klog.Errorf("ContainerStatus %q from runtime service failed: %v", containerID, err)
|
||||
klog.ErrorS(err, "ContainerStatus from runtime service failed", "containerID", containerID)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
r.logReduction.ClearID(containerID)
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ContainerStatus Response (containerID=%v, status=%v)", containerID, resp.Status)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ContainerStatus Response", "containerID", containerID, "status", resp.Status)
|
||||
|
||||
if resp.Status != nil {
|
||||
if err := verifyContainerStatus(resp.Status); err != nil {
|
||||
klog.Errorf("ContainerStatus of %q failed: %v", containerID, err)
|
||||
klog.ErrorS(err, "verify ContainerStatus failed", "containerID", containerID)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -348,7 +350,7 @@ func (r *remoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
|
||||
|
||||
// UpdateContainerResources updates a containers resource config
|
||||
func (r *remoteRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] UpdateContainerResources (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] UpdateContainerResources", "containerID", containerID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -357,10 +359,10 @@ func (r *remoteRuntimeService) UpdateContainerResources(containerID string, reso
|
||||
Linux: resources,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("UpdateContainerResources %q from runtime service failed: %v", containerID, err)
|
||||
klog.ErrorS(err, "UpdateContainerResources from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] UpdateContainerResources Response (containerID=%v)", containerID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] UpdateContainerResources Response", "containerID", containerID)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -368,7 +370,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) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ExecSync (containerID=%v, timeout=%v)", containerID, timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ExecSync", "containerID", containerID, "timeout", timeout)
|
||||
// Do not set timeout when timeout is 0.
|
||||
var ctx context.Context
|
||||
var cancel context.CancelFunc
|
||||
@ -389,7 +391,7 @@ func (r *remoteRuntimeService) ExecSync(containerID string, cmd []string, timeou
|
||||
}
|
||||
resp, err := r.runtimeClient.ExecSync(ctx, req)
|
||||
if err != nil {
|
||||
klog.Errorf("ExecSync %s '%s' from runtime service failed: %v", containerID, strings.Join(cmd, " "), err)
|
||||
klog.ErrorS(err, "ExecSync cmd from runtime service failed", "containerID", containerID, "cmd", cmd)
|
||||
|
||||
// interpret DeadlineExceeded gRPC errors as timedout probes
|
||||
if status.Code(err) == codes.DeadlineExceeded {
|
||||
@ -399,7 +401,7 @@ func (r *remoteRuntimeService) ExecSync(containerID string, cmd []string, timeou
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ExecSync Response (containerID=%v, ExitCode=%v)", containerID, resp.ExitCode)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ExecSync Response", "containerID", containerID, "exitCode", resp.ExitCode)
|
||||
err = nil
|
||||
if resp.ExitCode != 0 {
|
||||
err = utilexec.CodeExitError{
|
||||
@ -413,21 +415,22 @@ 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) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Exec (timeout=%v)", r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Exec", "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Exec(ctx, req)
|
||||
if err != nil {
|
||||
klog.Errorf("Exec %s '%s' from runtime service failed: %v", req.ContainerId, strings.Join(req.Cmd, " "), err)
|
||||
klog.ErrorS(err, "Exec cmd from runtime service failed", "containerID", req.ContainerId, "cmd", req.Cmd)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).Info("[RemoteRuntimeService] Exec Response")
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Exec Response")
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
klog.Errorf("Exec failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "Exec failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
@ -435,42 +438,44 @@ 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) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Attach (containerId=%v, timeout=%v)", req.ContainerId, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Attach", "containerID", req.ContainerId, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Attach(ctx, req)
|
||||
if err != nil {
|
||||
klog.Errorf("Attach %s from runtime service failed: %v", req.ContainerId, err)
|
||||
klog.ErrorS(err, "Attach container from runtime service failed", "containerID", req.ContainerId)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Attach Response (containerId=%v)", req.ContainerId)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Attach Response", "containerID", req.ContainerId)
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
klog.Errorf("Attach failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "Attach failed")
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 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) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] PortForward (podSandboxID=%v, port=%v, timeout=%v)", req.PodSandboxId, req.Port, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] PortForward", "podSandboxID", req.PodSandboxId, "port", req.Port, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.PortForward(ctx, req)
|
||||
if err != nil {
|
||||
klog.Errorf("PortForward %s from runtime service failed: %v", req.PodSandboxId, err)
|
||||
klog.ErrorS(err, "PortForward from runtime service failed", "podSandboxID", req.PodSandboxId)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] PortForward Response (podSandboxID=%v)", req.PodSandboxId)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] PortForward Response", "podSandboxID", req.PodSandboxId)
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
klog.Errorf("PortForward failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "PortForward failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
@ -480,7 +485,7 @@ func (r *remoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (
|
||||
// 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 {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] UpdateRuntimeConfig (runtimeConfig=%v, timeout=%v)", runtimeConfig, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] UpdateRuntimeConfig", "runtimeConfig", runtimeConfig, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -494,29 +499,30 @@ func (r *remoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.Run
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] UpdateRuntimeConfig Response (runtimeConfig=%v)", runtimeConfig)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] UpdateRuntimeConfig Response", "runtimeConfig", runtimeConfig)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status returns the status of the runtime.
|
||||
func (r *remoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Status (timeout=%v)", r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Status", "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Status(ctx, &runtimeapi.StatusRequest{})
|
||||
if err != nil {
|
||||
klog.Errorf("Status from runtime service failed: %v", err)
|
||||
klog.ErrorS(err, "Status from runtime service failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] Status Response (status=%v)", resp.Status)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] Status Response", "status", resp.Status)
|
||||
|
||||
if resp.Status == nil || len(resp.Status.Conditions) < 2 {
|
||||
errorMessage := "RuntimeReady or NetworkReady condition are not set"
|
||||
klog.Errorf("Status failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
err := errors.New(errorMessage)
|
||||
klog.ErrorS(err, "Status failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.Status, nil
|
||||
@ -524,7 +530,7 @@ func (r *remoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
|
||||
// ContainerStats returns the stats of the container.
|
||||
func (r *remoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ContainerStats (containerID=%v, timeout=%v)", containerID, r.timeout)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ContainerStats", "containerID", containerID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
@ -533,19 +539,19 @@ func (r *remoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.C
|
||||
})
|
||||
if err != nil {
|
||||
if r.logReduction.ShouldMessageBePrinted(err.Error(), containerID) {
|
||||
klog.Errorf("ContainerStats %q from runtime service failed: %v", containerID, err)
|
||||
klog.ErrorS(err, "ContainerStats from runtime service failed", "containerID", containerID)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
r.logReduction.ClearID(containerID)
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ContainerStats Response (containerID=%v, stats=%v)", containerID, resp.GetStats())
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ContainerStats Response", "containerID", containerID, "stats", resp.GetStats())
|
||||
|
||||
return resp.GetStats(), nil
|
||||
}
|
||||
|
||||
// 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)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListContainerStats", "filter", 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?
|
||||
ctx, cancel := getContextWithCancel()
|
||||
@ -555,26 +561,26 @@ func (r *remoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerSt
|
||||
Filter: filter,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Errorf("ListContainerStats with filter %+v from runtime service failed: %v", filter, err)
|
||||
klog.ErrorS(err, "ListContainerStats with filter from runtime service failed", "filter", filter)
|
||||
return nil, err
|
||||
}
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ListContainerStats Response (filter=%v, stats=%v)", filter, resp.GetStats())
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ListContainerStats Response", "filter", filter, "stats", resp.GetStats())
|
||||
|
||||
return resp.GetStats(), nil
|
||||
}
|
||||
|
||||
// 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)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ReopenContainerLog", "containerID", containerID, "timeout", r.timeout)
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.ReopenContainerLog(ctx, &runtimeapi.ReopenContainerLogRequest{ContainerId: containerID})
|
||||
if err != nil {
|
||||
klog.Errorf("ReopenContainerLog %q from runtime service failed: %v", containerID, err)
|
||||
klog.ErrorS(err, "ReopenContainerLog from runtime service failed", "containerID", containerID)
|
||||
return err
|
||||
}
|
||||
|
||||
klog.V(10).Infof("[RemoteRuntimeService] ReopenContainerLog Response (containerID=%v)", containerID)
|
||||
klog.V(10).InfoS("[RemoteRuntimeService] ReopenContainerLog Response", "containerID", containerID)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user