mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
In-place Pod Vertical Scaling - core implementation
1. Core Kubelet changes to implement In-place Pod Vertical Scaling. 2. E2E tests for In-place Pod Vertical Scaling. 3. Refactor kubelet code and add missing tests (Derek's kubelet review) 4. Add a new hash over container fields without Resources field to allow feature gate toggling without restarting containers not using the feature. 5. Fix corner-case where resize A->B->A gets ignored 6. Add cgroup v2 support to pod resize E2E test. KEP: /enhancements/keps/sig-node/1287-in-place-update-pod-resources Co-authored-by: Chen Wang <Chen.Wang1@ibm.com>
This commit is contained in:
committed by
vinay kulkarni
parent
231849a908
commit
f2bd94a0de
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
@@ -230,6 +231,111 @@ func TestToKubeContainerStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestToKubeContainerStatusWithResources tests the converting the CRI container status to
|
||||
// the internal type (i.e., toKubeContainerStatus()) for containers that returns Resources.
|
||||
func TestToKubeContainerStatusWithResources(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.InPlacePodVerticalScaling, true)()
|
||||
cid := &kubecontainer.ContainerID{Type: "testRuntime", ID: "dummyid"}
|
||||
meta := &runtimeapi.ContainerMetadata{Name: "cname", Attempt: 3}
|
||||
imageSpec := &runtimeapi.ImageSpec{Image: "fimage"}
|
||||
var (
|
||||
createdAt int64 = 327
|
||||
startedAt int64 = 999
|
||||
)
|
||||
|
||||
for desc, test := range map[string]struct {
|
||||
input *runtimeapi.ContainerStatus
|
||||
expected *kubecontainer.Status
|
||||
}{
|
||||
"container reporting cpu and memory": {
|
||||
input: &runtimeapi.ContainerStatus{
|
||||
Id: cid.ID,
|
||||
Metadata: meta,
|
||||
Image: imageSpec,
|
||||
State: runtimeapi.ContainerState_CONTAINER_RUNNING,
|
||||
CreatedAt: createdAt,
|
||||
StartedAt: startedAt,
|
||||
Resources: &runtimeapi.ContainerResources{
|
||||
Linux: &runtimeapi.LinuxContainerResources{
|
||||
CpuQuota: 25000,
|
||||
CpuPeriod: 100000,
|
||||
MemoryLimitInBytes: 524288000,
|
||||
OomScoreAdj: -998,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &kubecontainer.Status{
|
||||
ID: *cid,
|
||||
Image: imageSpec.Image,
|
||||
State: kubecontainer.ContainerStateRunning,
|
||||
CreatedAt: time.Unix(0, createdAt),
|
||||
StartedAt: time.Unix(0, startedAt),
|
||||
Resources: &kubecontainer.ContainerResources{
|
||||
CPULimit: resource.NewMilliQuantity(250, resource.DecimalSI),
|
||||
MemoryLimit: resource.NewQuantity(524288000, resource.BinarySI),
|
||||
},
|
||||
},
|
||||
},
|
||||
"container reporting cpu only": {
|
||||
input: &runtimeapi.ContainerStatus{
|
||||
Id: cid.ID,
|
||||
Metadata: meta,
|
||||
Image: imageSpec,
|
||||
State: runtimeapi.ContainerState_CONTAINER_RUNNING,
|
||||
CreatedAt: createdAt,
|
||||
StartedAt: startedAt,
|
||||
Resources: &runtimeapi.ContainerResources{
|
||||
Linux: &runtimeapi.LinuxContainerResources{
|
||||
CpuQuota: 50000,
|
||||
CpuPeriod: 100000,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &kubecontainer.Status{
|
||||
ID: *cid,
|
||||
Image: imageSpec.Image,
|
||||
State: kubecontainer.ContainerStateRunning,
|
||||
CreatedAt: time.Unix(0, createdAt),
|
||||
StartedAt: time.Unix(0, startedAt),
|
||||
Resources: &kubecontainer.ContainerResources{
|
||||
CPULimit: resource.NewMilliQuantity(500, resource.DecimalSI),
|
||||
},
|
||||
},
|
||||
},
|
||||
"container reporting memory only": {
|
||||
input: &runtimeapi.ContainerStatus{
|
||||
Id: cid.ID,
|
||||
Metadata: meta,
|
||||
Image: imageSpec,
|
||||
State: runtimeapi.ContainerState_CONTAINER_RUNNING,
|
||||
CreatedAt: createdAt,
|
||||
StartedAt: startedAt,
|
||||
Resources: &runtimeapi.ContainerResources{
|
||||
Linux: &runtimeapi.LinuxContainerResources{
|
||||
MemoryLimitInBytes: 524288000,
|
||||
OomScoreAdj: -998,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &kubecontainer.Status{
|
||||
ID: *cid,
|
||||
Image: imageSpec.Image,
|
||||
State: kubecontainer.ContainerStateRunning,
|
||||
CreatedAt: time.Unix(0, createdAt),
|
||||
StartedAt: time.Unix(0, startedAt),
|
||||
Resources: &kubecontainer.ContainerResources{
|
||||
MemoryLimit: resource.NewQuantity(524288000, resource.BinarySI),
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(desc, func(t *testing.T) {
|
||||
actual := toKubeContainerStatus(test.input, cid.Type)
|
||||
assert.Equal(t, test.expected, actual, desc)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLifeCycleHook(t *testing.T) {
|
||||
|
||||
// Setup
|
||||
@@ -696,3 +802,39 @@ func TestKillContainerGracePeriod(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestUpdateContainerResources tests updating a container in a Pod.
|
||||
func TestUpdateContainerResources(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
|
||||
_, fakeContainers := makeAndSetFakePod(t, m, fakeRuntime, pod)
|
||||
assert.Equal(t, len(fakeContainers), 1)
|
||||
|
||||
cStatus, err := m.getPodContainerStatuses(pod.UID, pod.Name, pod.Namespace)
|
||||
assert.NoError(t, err)
|
||||
containerID := cStatus[0].ID
|
||||
|
||||
err = m.updateContainerResources(pod, &pod.Spec.Containers[0], containerID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Verify container is updated
|
||||
assert.Contains(t, fakeRuntime.Called, "UpdateContainerResources")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user