Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/apis/core/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6222,11 +6222,11 @@ func validatePodResizeContainerOrdering(newPod, oldPod *core.Pod, specPath *fiel
// dropCPUMemoryResourcesFromContainer deletes the cpu and memory resources from the container, and copies them from the old pod container resources if present.
func dropCPUMemoryResourcesFromContainer(container *core.Container, oldPodSpecContainer *core.Container) {
dropCPUMemoryUpdates := func(resourceList, oldResourceList core.ResourceList) core.ResourceList {
if oldResourceList == nil {
return nil
}
var mungedResourceList core.ResourceList
if resourceList == nil {
if oldResourceList == nil {
return nil
}
mungedResourceList = make(core.ResourceList)
} else {
mungedResourceList = resourceList.DeepCopy()
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/core/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28309,6 +28309,21 @@ func TestValidatePodResize(t *testing.T) {
old: mkPodWithInitContainers(getResources("100m", "0", "1Gi", ""), core.ResourceList{}, core.ContainerRestartPolicyAlways, resizePolicy(core.ResourceMemory, core.RestartContainer)),
new: mkPodWithInitContainers(getResources("100m", "0", "2Gi", ""), core.ResourceList{}, core.ContainerRestartPolicyAlways, resizePolicy(core.ResourceMemory, core.NotRequired)),
err: "spec: Forbidden: only cpu and memory resources are mutable",
}, {
test: "invalid: adding non-resizable resources to a container without resources",
old: podtest.MakePod("pod", podtest.SetContainers(
podtest.MakeContainer("c1"),
)),
new: podtest.MakePod("pod", podtest.SetContainers(
podtest.MakeContainer("c1",
podtest.SetContainerResources(core.ResourceRequirements{
Requests: core.ResourceList{
core.ResourceEphemeralStorage: resource.MustParse("10Gi"),
},
}),
),
)),
err: "spec: Forbidden: only cpu and memory resources are mutable",
},
}

Expand Down
7 changes: 6 additions & 1 deletion test/integration/pods/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,11 @@ func TestPodResizeRBAC(t *testing.T) {
{
Name: "fake-name",
Image: "fakeimage",
Resources: v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("100m"),
},
},
},
},
},
Expand Down Expand Up @@ -929,7 +934,7 @@ func TestPodResizeRBAC(t *testing.T) {
}
resp.Spec.Containers[0].Resources = v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceEphemeralStorage: resource.MustParse("2Gi"),
Copy link
Member Author

@tallclair tallclair Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny that we had a test verifying the incorrect behavior... 🤔

v1.ResourceCPU: resource.MustParse("200m"),
},
}
_, err = saClient.CoreV1().Pods(ns.Name).UpdateResize(context.TODO(), resp.Name, resp, metav1.UpdateOptions{})
Expand Down