diff --git a/pkg/kubelet/cm/cpumanager/cpu_manager.go b/pkg/kubelet/cm/cpumanager/cpu_manager.go index dde49b6ec8c..0928c688e08 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_manager.go +++ b/pkg/kubelet/cm/cpumanager/cpu_manager.go @@ -42,7 +42,7 @@ import ( type ActivePodsFunc func() []*v1.Pod type runtimeService interface { - UpdateContainerResources(id string, resources *runtimeapi.LinuxContainerResources) error + UpdateContainerResources(id string, resources *runtimeapi.ContainerResources) error } type policyName string @@ -515,8 +515,10 @@ func (m *manager) updateContainerCPUSet(containerID string, cpus cpuset.CPUSet) // this patch-like partial resources. return m.containerRuntime.UpdateContainerResources( containerID, - &runtimeapi.LinuxContainerResources{ - CpusetCpus: cpus.String(), + &runtimeapi.ContainerResources{ + Linux: &runtimeapi.LinuxContainerResources{ + CpusetCpus: cpus.String(), + }, }) } diff --git a/pkg/kubelet/cm/cpumanager/cpu_manager_test.go b/pkg/kubelet/cm/cpumanager/cpu_manager_test.go index 9b3e24fc3b2..834d099ac3e 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_manager_test.go +++ b/pkg/kubelet/cm/cpumanager/cpu_manager_test.go @@ -128,7 +128,7 @@ type mockRuntimeService struct { err error } -func (rt mockRuntimeService) UpdateContainerResources(id string, resources *runtimeapi.LinuxContainerResources) error { +func (rt mockRuntimeService) UpdateContainerResources(id string, resources *runtimeapi.ContainerResources) error { return rt.err } diff --git a/pkg/kubelet/cm/memorymanager/memory_manager.go b/pkg/kubelet/cm/memorymanager/memory_manager.go index dad537e9a47..c567871f1b0 100644 --- a/pkg/kubelet/cm/memorymanager/memory_manager.go +++ b/pkg/kubelet/cm/memorymanager/memory_manager.go @@ -43,7 +43,7 @@ const memoryManagerStateFileName = "memory_manager_state" type ActivePodsFunc func() []*v1.Pod type runtimeService interface { - UpdateContainerResources(id string, resources *runtimeapi.LinuxContainerResources) error + UpdateContainerResources(id string, resources *runtimeapi.ContainerResources) error } type sourcesReadyStub struct{} diff --git a/pkg/kubelet/cm/memorymanager/memory_manager_test.go b/pkg/kubelet/cm/memorymanager/memory_manager_test.go index 68cf93f60c0..648c985b2e9 100644 --- a/pkg/kubelet/cm/memorymanager/memory_manager_test.go +++ b/pkg/kubelet/cm/memorymanager/memory_manager_test.go @@ -122,7 +122,7 @@ type mockRuntimeService struct { err error } -func (rt mockRuntimeService) UpdateContainerResources(id string, resources *runtimeapi.LinuxContainerResources) error { +func (rt mockRuntimeService) UpdateContainerResources(id string, resources *runtimeapi.ContainerResources) error { return rt.err } diff --git a/pkg/kubelet/cri/remote/fake/fake_runtime.go b/pkg/kubelet/cri/remote/fake/fake_runtime.go index 0ef21475e6f..be52c91a3ac 100644 --- a/pkg/kubelet/cri/remote/fake/fake_runtime.go +++ b/pkg/kubelet/cri/remote/fake/fake_runtime.go @@ -305,7 +305,7 @@ func (f *RemoteRuntime) Status(ctx context.Context, req *kubeapi.StatusRequest) // UpdateContainerResources updates ContainerConfig of the container. func (f *RemoteRuntime) UpdateContainerResources(ctx context.Context, req *kubeapi.UpdateContainerResourcesRequest) (*kubeapi.UpdateContainerResourcesResponse, error) { - err := f.RuntimeService.UpdateContainerResources(req.ContainerId, req.Linux) + err := f.RuntimeService.UpdateContainerResources(req.ContainerId, &kubeapi.ContainerResources{Linux: req.Linux}) if err != nil { return nil, err } diff --git a/pkg/kubelet/cri/remote/remote_runtime.go b/pkg/kubelet/cri/remote/remote_runtime.go index 0faf86b6bb6..c1f5f4cf32d 100644 --- a/pkg/kubelet/cri/remote/remote_runtime.go +++ b/pkg/kubelet/cri/remote/remote_runtime.go @@ -641,7 +641,7 @@ func (r *remoteRuntimeService) containerStatusV1(ctx context.Context, containerI } // UpdateContainerResources updates a containers resource config -func (r *remoteRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) (err error) { +func (r *remoteRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.ContainerResources) (err error) { klog.V(10).InfoS("[RemoteRuntimeService] UpdateContainerResources", "containerID", containerID, "timeout", r.timeout) ctx, cancel := getContextWithTimeout(r.timeout) defer cancel() @@ -649,12 +649,13 @@ func (r *remoteRuntimeService) UpdateContainerResources(containerID string, reso if r.useV1API() { _, err = r.runtimeClient.UpdateContainerResources(ctx, &runtimeapi.UpdateContainerResourcesRequest{ ContainerId: containerID, - Linux: resources, + Linux: resources.GetLinux(), + Windows: resources.GetWindows(), }) } else { _, err = r.runtimeClientV1alpha2.UpdateContainerResources(ctx, &runtimeapiV1alpha2.UpdateContainerResourcesRequest{ ContainerId: containerID, - Linux: v1alpha2LinuxContainerResources(resources), + Linux: v1alpha2LinuxContainerResources(resources.GetLinux()), }) } if err != nil { diff --git a/pkg/kubelet/kuberuntime/instrumented_services.go b/pkg/kubelet/kuberuntime/instrumented_services.go index 2412aaa0199..18ce6aa0425 100644 --- a/pkg/kubelet/kuberuntime/instrumented_services.go +++ b/pkg/kubelet/kuberuntime/instrumented_services.go @@ -131,7 +131,7 @@ func (in instrumentedRuntimeService) ContainerStatus(containerID string, verbose return out, err } -func (in instrumentedRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error { +func (in instrumentedRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.ContainerResources) error { const operation = "update_container" defer recordOperation(operation, time.Now()) diff --git a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto index bf14b2d82c3..9feb4b245f4 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto +++ b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto @@ -79,7 +79,8 @@ service RuntimeService { // ContainerStatus returns status of the container. If the container is not // present, returns an error. rpc ContainerStatus(ContainerStatusRequest) returns (ContainerStatusResponse) {} - // UpdateContainerResources updates ContainerConfig of the container. + // UpdateContainerResources updates ContainerConfig of the container synchronously. + // If runtime fails to transactionally update the requested resources, an error is returned. 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 @@ -1158,6 +1159,8 @@ message ContainerStatus { repeated Mount mounts = 14; // Log path of container. string log_path = 15; + // Resource limits configuration of the container. + ContainerResources resources = 16; } message ContainerStatusResponse { @@ -1170,6 +1173,14 @@ message ContainerStatusResponse { map info = 2; } +// ContainerResources holds resource limits configuration for a container. +message ContainerResources { + // Resource limits configuration specific to Linux container. + LinuxContainerResources linux = 1; + // Resource limits configuration specific to Windows container. + WindowsContainerResources windows = 2; +} + message UpdateContainerResourcesRequest { // ID of the container to update. string container_id = 1; diff --git a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.proto b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.proto index 41671963229..6f6734e6067 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.proto +++ b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2/api.proto @@ -79,7 +79,8 @@ service RuntimeService { // ContainerStatus returns status of the container. If the container is not // present, returns an error. rpc ContainerStatus(ContainerStatusRequest) returns (ContainerStatusResponse) {} - // UpdateContainerResources updates ContainerConfig of the container. + // UpdateContainerResources updates ContainerConfig of the container synchronously. + // If runtime fails to transactionally update the requested resources, an error is returned. 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 @@ -1151,6 +1152,8 @@ message ContainerStatus { repeated Mount mounts = 14; // Log path of container. string log_path = 15; + // Resource limits configuration of the container. + ContainerResources resources = 16; } message ContainerStatusResponse { @@ -1163,6 +1166,14 @@ message ContainerStatusResponse { map info = 2; } +// ContainerResources holds resource limits configuration for a container. +message ContainerResources { + // Resource limits configuration specific to Linux container. + LinuxContainerResources linux = 1; + // Resource limits configuration specific to Windows container. + WindowsContainerResources windows = 2; +} + message UpdateContainerResourcesRequest { // ID of the container to update. string container_id = 1; diff --git a/staging/src/k8s.io/cri-api/pkg/apis/services.go b/staging/src/k8s.io/cri-api/pkg/apis/services.go index d80a0544ffb..55f631738b7 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/services.go +++ b/staging/src/k8s.io/cri-api/pkg/apis/services.go @@ -43,8 +43,9 @@ type ContainerManager interface { ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) // ContainerStatus returns the status of the container. ContainerStatus(containerID string, verbose bool) (*runtimeapi.ContainerStatusResponse, error) - // UpdateContainerResources updates the cgroup resources for the container. - UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error + // UpdateContainerResources updates ContainerConfig of the container synchronously. + // If runtime fails to transactionally update the requested resources, an error is returned. + UpdateContainerResources(containerID string, resources *runtimeapi.ContainerResources) 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) diff --git a/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go b/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go index cffe63878ec..635295e3d71 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go +++ b/staging/src/k8s.io/cri-api/pkg/apis/testing/fake_runtime_service.go @@ -509,7 +509,7 @@ func (r *FakeRuntimeService) ContainerStatus(containerID string, verbose bool) ( } // UpdateContainerResources returns the container resource in the FakeRuntimeService. -func (r *FakeRuntimeService) UpdateContainerResources(string, *runtimeapi.LinuxContainerResources) error { +func (r *FakeRuntimeService) UpdateContainerResources(string, *runtimeapi.ContainerResources) error { r.Lock() defer r.Unlock()