mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
make kubelet call updatePodSandboxResources on PodResizeAction
This commit is contained in:
parent
b27c303ac2
commit
ce4de97c2e
@ -272,6 +272,15 @@ func (in instrumentedRuntimeService) PortForward(ctx context.Context, req *runti
|
|||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (in instrumentedRuntimeService) UpdatePodSandboxResources(ctx context.Context, req *runtimeapi.UpdatePodSandboxResourcesRequest) (*runtimeapi.UpdatePodSandboxResourcesResponse, error) {
|
||||||
|
const operation = "update_podsandbox"
|
||||||
|
defer recordOperation(operation, time.Now())
|
||||||
|
|
||||||
|
resp, err := in.service.UpdatePodSandboxResources(ctx, req)
|
||||||
|
recordError(operation, err)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
func (in instrumentedRuntimeService) UpdateRuntimeConfig(ctx context.Context, runtimeConfig *runtimeapi.RuntimeConfig) error {
|
func (in instrumentedRuntimeService) UpdateRuntimeConfig(ctx context.Context, runtimeConfig *runtimeapi.RuntimeConfig) error {
|
||||||
const operation = "update_runtime_config"
|
const operation = "update_runtime_config"
|
||||||
defer recordOperation(operation, time.Now())
|
defer recordOperation(operation, time.Now())
|
||||||
|
@ -33,6 +33,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
crierror "k8s.io/cri-api/pkg/errors"
|
crierror "k8s.io/cri-api/pkg/errors"
|
||||||
|
|
||||||
"github.com/opencontainers/selinux/go-selinux"
|
"github.com/opencontainers/selinux/go-selinux"
|
||||||
@ -411,6 +412,25 @@ func (m *kubeGenericRuntimeManager) updateContainerResources(pod *v1.Pod, contai
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *kubeGenericRuntimeManager) updatePodSandboxResources(sandboxID string, pod *v1.Pod) error {
|
||||||
|
podResourcesRequest := &runtimeapi.UpdatePodSandboxResourcesRequest{
|
||||||
|
PodSandboxId: sandboxID,
|
||||||
|
Overhead: m.convertOverheadToLinuxResources(pod),
|
||||||
|
Resources: m.calculateSandboxResources(pod),
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
_, err := m.runtimeService.UpdatePodSandboxResources(ctx, podResourcesRequest)
|
||||||
|
if err != nil {
|
||||||
|
stat, _ := grpcstatus.FromError(err)
|
||||||
|
if stat.Code() == codes.Unimplemented {
|
||||||
|
klog.ErrorS(err, "updatePodSandboxResources failed: method unimplemented on runtime service", "sandboxID", sandboxID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// makeDevices generates container devices for kubelet runtime v1.
|
// makeDevices generates container devices for kubelet runtime v1.
|
||||||
func makeDevices(opts *kubecontainer.RunContainerOptions) []*runtimeapi.Device {
|
func makeDevices(opts *kubecontainer.RunContainerOptions) []*runtimeapi.Device {
|
||||||
devices := make([]*runtimeapi.Device, len(opts.Devices))
|
devices := make([]*runtimeapi.Device, len(opts.Devices))
|
||||||
|
@ -969,3 +969,39 @@ func TestUpdateContainerResources(t *testing.T) {
|
|||||||
// Verify container is updated
|
// Verify container is updated
|
||||||
assert.Contains(t, fakeRuntime.Called, "UpdateContainerResources")
|
assert.Contains(t, fakeRuntime.Called, "UpdateContainerResources")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestUpdatePodSandboxResources tests updating a podSandBox resources.
|
||||||
|
func TestUpdatePodSandboxResources(t *testing.T) {
|
||||||
|
fakeRuntime, _, m, errCreate := createTestRuntimeManager()
|
||||||
|
require.NoError(t, errCreate)
|
||||||
|
pod := &v1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
UID: "12345678",
|
||||||
|
Name: "bar",
|
||||||
|
Namespace: "new",
|
||||||
|
},
|
||||||
|
Spec: v1.PodSpec{
|
||||||
|
Containers: []v1.Container{
|
||||||
|
{
|
||||||
|
Name: "foo",
|
||||||
|
Image: "busybox",
|
||||||
|
ImagePullPolicy: v1.PullIfNotPresent,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create fake sandbox and container
|
||||||
|
fakeSandbox, fakeContainers := makeAndSetFakePod(t, m, fakeRuntime, pod)
|
||||||
|
assert.Len(t, fakeContainers, 1)
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
_, err := m.getPodContainerStatuses(ctx, pod.UID, pod.Name, pod.Namespace)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = m.updatePodSandboxResources(fakeSandbox.Id, pod)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Verify sandbox is updated
|
||||||
|
assert.Contains(t, fakeRuntime.Called, "UpdatePodSandboxResources")
|
||||||
|
}
|
||||||
|
@ -775,6 +775,9 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podContainerC
|
|||||||
result.Fail(errResize)
|
result.Fail(errResize)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if errUpdate := m.updatePodSandboxResources(podContainerChanges.SandboxID, pod); errUpdate != nil {
|
||||||
|
klog.ErrorS(err, "updatePodSandboxResources failed", "pod", pod.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(podContainerChanges.ContainersToUpdate[v1.ResourceCPU]) > 0 || podContainerChanges.UpdatePodResources {
|
if len(podContainerChanges.ContainersToUpdate[v1.ResourceCPU]) > 0 || podContainerChanges.UpdatePodResources {
|
||||||
if podResources.CPUShares == nil {
|
if podResources.CPUShares == nil {
|
||||||
@ -801,6 +804,9 @@ func (m *kubeGenericRuntimeManager) doPodResizeAction(pod *v1.Pod, podContainerC
|
|||||||
result.Fail(errResize)
|
result.Fail(errResize)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if errUpdate := m.updatePodSandboxResources(podContainerChanges.SandboxID, pod); errUpdate != nil {
|
||||||
|
klog.ErrorS(err, "updatePodSandboxResources failed", "pod", pod.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1077,6 +1077,19 @@ message WindowsContainerResources {
|
|||||||
int64 memory_limit_in_bytes = 4;
|
int64 memory_limit_in_bytes = 4;
|
||||||
// Specifies the size of the rootfs / scratch space in bytes to be configured for this container. Default: 0 (not specified).
|
// Specifies the size of the rootfs / scratch space in bytes to be configured for this container. Default: 0 (not specified).
|
||||||
int64 rootfs_size_in_bytes = 5;
|
int64 rootfs_size_in_bytes = 5;
|
||||||
|
// Optionally specifies the set of CPUs to affinitize for this container.
|
||||||
|
repeated WindowsCpuGroupAffinity affinity_cpus = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// WindowsCpuGroupAffinity specifies the CPU mask and group to affinitize.
|
||||||
|
// This is similar to the following _GROUP_AFFINITY structure:
|
||||||
|
// https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/miniport/ns-miniport-_group_affinity
|
||||||
|
message WindowsCpuGroupAffinity {
|
||||||
|
// CPU mask relative to this CPU group.
|
||||||
|
uint64 cpu_mask = 1;
|
||||||
|
// Processor group the mask refers to, as returned by
|
||||||
|
// GetLogicalProcessorInformationEx.
|
||||||
|
uint32 cpu_group = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerMetadata holds all necessary information for building the container
|
// ContainerMetadata holds all necessary information for building the container
|
||||||
|
Loading…
Reference in New Issue
Block a user