mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-19 08:54:44 +00:00
In-place Pod Vertical Scaling - API changes
1. Define ContainerResizePolicy and add it to Container struct. 2. Add ResourcesAllocated and Resources fields to ContainerStatus struct. 3. Define ResourcesResizeStatus and add it to PodStatus struct. 4. Add InPlacePodVerticalScaling feature gate and drop disabled fields. 5. ResizePolicy validation & defaulting and Resources mutability for CPU/Memory. 6. Various fixes from code review feedback (originally committed on Apr 12, 2022) KEP: /enhancements/keps/sig-node/1287-in-place-update-pod-resources
This commit is contained in:
committed by
vinay kulkarni
parent
cfb32121c1
commit
76962b0fa7
@@ -257,7 +257,7 @@ func visitContainerConfigmapNames(container *v1.Container, visitor Visitor) bool
|
||||
}
|
||||
|
||||
// GetContainerStatus extracts the status of container "name" from "statuses".
|
||||
// It also returns if "name" exists.
|
||||
// It returns true if "name" exists, else returns false.
|
||||
func GetContainerStatus(statuses []v1.ContainerStatus, name string) (v1.ContainerStatus, bool) {
|
||||
for i := range statuses {
|
||||
if statuses[i].Name == name {
|
||||
@@ -274,6 +274,17 @@ func GetExistingContainerStatus(statuses []v1.ContainerStatus, name string) v1.C
|
||||
return status
|
||||
}
|
||||
|
||||
// GetIndexOfContainerStatus gets the index of status of container "name" from "statuses",
|
||||
// It returns (index, true) if "name" exists, else returns (0, false).
|
||||
func GetIndexOfContainerStatus(statuses []v1.ContainerStatus, name string) (int, bool) {
|
||||
for i := range statuses {
|
||||
if statuses[i].Name == name {
|
||||
return i, true
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// IsPodAvailable returns true if a pod is available; false otherwise.
|
||||
// Precondition for an available pod is that it must be ready. On top
|
||||
// of that, there are two cases when a pod can be considered available:
|
||||
|
@@ -809,6 +809,53 @@ func TestGetContainerStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIndexOfContainerStatus(t *testing.T) {
|
||||
testStatus := []v1.ContainerStatus{
|
||||
{
|
||||
Name: "c1",
|
||||
Ready: false,
|
||||
Image: "image1",
|
||||
},
|
||||
{
|
||||
Name: "c2",
|
||||
Ready: true,
|
||||
Image: "image1",
|
||||
},
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
desc string
|
||||
containerName string
|
||||
expectedExists bool
|
||||
expectedIndex int
|
||||
}{
|
||||
{
|
||||
desc: "first container",
|
||||
containerName: "c1",
|
||||
expectedExists: true,
|
||||
expectedIndex: 0,
|
||||
},
|
||||
{
|
||||
desc: "second container",
|
||||
containerName: "c2",
|
||||
expectedExists: true,
|
||||
expectedIndex: 1,
|
||||
},
|
||||
{
|
||||
desc: "non-existent container",
|
||||
containerName: "c3",
|
||||
expectedExists: false,
|
||||
expectedIndex: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
idx, exists := GetIndexOfContainerStatus(testStatus, test.containerName)
|
||||
assert.Equal(t, test.expectedExists, exists, "GetIndexOfContainerStatus: "+test.desc)
|
||||
assert.Equal(t, test.expectedIndex, idx, "GetIndexOfContainerStatus: "+test.desc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdatePodCondition(t *testing.T) {
|
||||
time := metav1.Now()
|
||||
|
||||
|
Reference in New Issue
Block a user