Merge pull request #111645 from vinaykul/restart-free-pod-vertical-scaling-cri

CRI changes to support in-place pod resize
This commit is contained in:
Kubernetes Prow Robot 2022-08-02 21:27:51 -07:00 committed by GitHub
commit aea9f9887d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 1552 additions and 877 deletions

View File

@ -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(),
},
})
}

View File

@ -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
}

View File

@ -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{}

View File

@ -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
}

View File

@ -113,6 +113,10 @@ func v1alpha2LinuxContainerResources(from *runtimeapi.LinuxContainerResources) *
return (*v1alpha2.LinuxContainerResources)(unsafe.Pointer(from))
}
func v1alpha2WindowsContainerResources(from *runtimeapi.WindowsContainerResources) *v1alpha2.WindowsContainerResources {
return (*v1alpha2.WindowsContainerResources)(unsafe.Pointer(from))
}
func v1alpha2ExecRequest(from *runtimeapi.ExecRequest) *v1alpha2.ExecRequest {
// If this function changes, also adapt the corresponding Exec code in
// pkg/kubelet/cri/remote/remote_runtime.go

View File

@ -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
}

View File

@ -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,14 @@ 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()),
Windows: v1alpha2WindowsContainerResources(resources.GetWindows()),
})
}
if err != nil {

View File

@ -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())

File diff suppressed because it is too large Load Diff

View File

@ -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<string, string> 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;

File diff suppressed because it is too large Load Diff

View File

@ -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<string, string> 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;

View File

@ -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)

View File

@ -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()