Unverified Commit 7446f49b authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #58899 from yujuhong/reopen-logs

Automatic merge from submit-queue (batch tested with PRs 58899, 58980). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. CRI: Add a call to reopen log file for a container This allows a daemon external to the container runtime to rotate the log file, and then ask the runtime to reopen the files. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #58823 **Release note**: ```release-note CRI: Add a call to reopen log file for a container. ```
parents 29ca36f0 57d8b64d
...@@ -52,6 +52,9 @@ type ContainerManager interface { ...@@ -52,6 +52,9 @@ type ContainerManager interface {
Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error)
// Attach prepares a streaming endpoint to attach to a running container, and returns the address. // Attach prepares a streaming endpoint to attach to a running container, and returns the address.
Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error)
// ReopenContainerLog asks runtime to reopen the stdout/stderr log file
// for the container.
ReopenContainerLog(ContainerID string) error
} }
// PodSandboxManager contains methods for operating on PodSandboxes. The methods // PodSandboxManager contains methods for operating on PodSandboxes. The methods
......
...@@ -459,3 +459,11 @@ func (r *FakeRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStat ...@@ -459,3 +459,11 @@ func (r *FakeRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStat
return result, nil return result, nil
} }
func (r *FakeRuntimeService) ReopenContainerLog(containerID string) error {
r.Lock()
defer r.Unlock()
r.Called = append(r.Called, "ReopenContainerLog")
return nil
}
...@@ -63,6 +63,10 @@ service RuntimeService { ...@@ -63,6 +63,10 @@ service RuntimeService {
rpc ContainerStatus(ContainerStatusRequest) returns (ContainerStatusResponse) {} rpc ContainerStatus(ContainerStatusRequest) returns (ContainerStatusResponse) {}
// UpdateContainerResources updates ContainerConfig of the container. // UpdateContainerResources updates ContainerConfig of the container.
rpc UpdateContainerResources(UpdateContainerResourcesRequest) returns (UpdateContainerResourcesResponse) {} rpc UpdateContainerResources(UpdateContainerResourcesRequest) returns (UpdateContainerResourcesResponse) {}
// ReopenContainerLog asks runtime to reopen the stdout/stderr log file
// for the container. This is often called after the log file has been
// rotated.
rpc ReopenContainerLog(ReopenContainerLogRequest) returns (ReopenContainerLogResponse) {}
// ExecSync runs a command in a container synchronously. // ExecSync runs a command in a container synchronously.
rpc ExecSync(ExecSyncRequest) returns (ExecSyncResponse) {} rpc ExecSync(ExecSyncRequest) returns (ExecSyncResponse) {}
...@@ -1153,3 +1157,11 @@ message MemoryUsage { ...@@ -1153,3 +1157,11 @@ message MemoryUsage {
// The amount of working set memory in bytes. // The amount of working set memory in bytes.
UInt64Value working_set_bytes = 2; UInt64Value working_set_bytes = 2;
} }
message ReopenContainerLogRequest {
// ID of the container for which to reopen the log.
string container_id = 1;
}
message ReopenContainerLogResponse{
}
...@@ -15,6 +15,7 @@ go_library( ...@@ -15,6 +15,7 @@ go_library(
"docker_container.go", "docker_container.go",
"docker_image.go", "docker_image.go",
"docker_legacy_service.go", "docker_legacy_service.go",
"docker_logs.go",
"docker_sandbox.go", "docker_sandbox.go",
"docker_service.go", "docker_service.go",
"docker_streaming.go", "docker_streaming.go",
......
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package dockershim
import (
"fmt"
"golang.org/x/net/context"
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)
// ReopenContainerLog reopens the container log file.
func (ds *dockerService) ReopenContainerLog(_ context.Context, _ *runtimeapi.ReopenContainerLogRequest) (*runtimeapi.ReopenContainerLogResponse, error) {
return nil, fmt.Errorf("docker does not support reopening container log files")
}
...@@ -140,6 +140,15 @@ func (in instrumentedRuntimeService) UpdateContainerResources(containerID string ...@@ -140,6 +140,15 @@ func (in instrumentedRuntimeService) UpdateContainerResources(containerID string
return err return err
} }
func (in instrumentedRuntimeService) ReopenContainerLog(containerID string) error {
const operation = "reopen_container_log"
defer recordOperation(operation, time.Now())
err := in.service.ReopenContainerLog(containerID)
recordError(operation, err)
return err
}
func (in instrumentedRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) ([]byte, []byte, error) { func (in instrumentedRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) ([]byte, []byte, error) {
const operation = "exec_sync" const operation = "exec_sync"
defer recordOperation(operation, time.Now()) defer recordOperation(operation, time.Now())
......
...@@ -283,3 +283,13 @@ func (f *RemoteRuntime) UpdateContainerResources(ctx context.Context, req *kubea ...@@ -283,3 +283,13 @@ func (f *RemoteRuntime) UpdateContainerResources(ctx context.Context, req *kubea
return &kubeapi.UpdateContainerResourcesResponse{}, nil return &kubeapi.UpdateContainerResourcesResponse{}, nil
} }
// ReopenContainerLog reopens the container log file.
func (f *RemoteRuntime) ReopenContainerLog(ctx context.Context, req *kubeapi.ReopenContainerLogRequest) (*kubeapi.ReopenContainerLogResponse, error) {
err := f.RuntimeService.ReopenContainerLog(req.ContainerId)
if err != nil {
return nil, err
}
return &kubeapi.ReopenContainerLogResponse{}, nil
}
...@@ -476,3 +476,15 @@ func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerSt ...@@ -476,3 +476,15 @@ func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerSt
return resp.GetStats(), nil return resp.GetStats(), nil
} }
func (r *RemoteRuntimeService) ReopenContainerLog(containerID string) error {
ctx, cancel := getContextWithTimeout(r.timeout)
defer cancel()
_, err := r.runtimeClient.ReopenContainerLog(ctx, &runtimeapi.ReopenContainerLogRequest{ContainerId: containerID})
if err != nil {
glog.Errorf("ReopenContainerLog %q from runtime service failed: %v", containerID, err)
return err
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment