@@ -25601,24 +25601,6 @@ func TestValidatePodResize(t *testing.T) {
25601
25601
),
25602
25602
)...)
25603
25603
}
25604
- mkPodWithInitCtrs := func(req, lim core.ResourceList, tweaks ...podtest.TweakContainer) *core.Pod {
25605
- tweaks = append(tweaks, podtest.SetContainerRestartPolicy(containerRestartPolicyAlways))
25606
- return podtest.MakePod("pod",
25607
- podtest.SetInitContainers(
25608
- podtest.MakeContainer(
25609
- "restartable-init",
25610
- append(tweaks,
25611
- podtest.SetContainerResources(
25612
- core.ResourceRequirements{
25613
- Requests: req,
25614
- Limits: lim,
25615
- },
25616
- ),
25617
- )...,
25618
- ),
25619
- ),
25620
- )
25621
- }
25622
25604
25623
25605
mkPodWithInitContainers := func(req, lim core.ResourceList, restartPolicy core.ContainerRestartPolicy, tweaks ...podtest.Tweak) *core.Pod {
25624
25606
return podtest.MakePod("pod", append(tweaks,
@@ -25638,11 +25620,10 @@ func TestValidatePodResize(t *testing.T) {
25638
25620
}
25639
25621
25640
25622
tests := []struct {
25641
- test string
25642
- old *core.Pod
25643
- new *core.Pod
25644
- isSideCarCtr bool
25645
- err string
25623
+ test string
25624
+ old *core.Pod
25625
+ new *core.Pod
25626
+ err string
25646
25627
}{
25647
25628
{
25648
25629
test: "pod-level resources with container cpu limit change",
@@ -25930,9 +25911,8 @@ func TestValidatePodResize(t *testing.T) {
25930
25911
test: "Pod QoS unchanged, burstable -> burstable, remove cpu and memory requests",
25931
25912
old: mkPodWithInitContainers(getResources("100m", "100Mi", "", ""), getResources("100m", "", "", ""), ""),
25932
25913
new: mkPodWithInitContainers(core.ResourceList{}, getResources("100m", "", "", ""), ""),
25933
- err: "spec: Forbidden: only cpu and memory resources are mutable",
25934
- },
25935
- {
25914
+ err: "spec: Forbidden: cpu and memory resources for only sidecar containers are mutable",
25915
+ }, {
25936
25916
test: "Pod with nil Resource field in Status",
25937
25917
old: mkPod(core.ResourceList{}, getResources("100m", "0", "1Gi", ""), podtest.SetStatus(core.PodStatus{
25938
25918
ContainerStatuses: []core.ContainerStatus{{
@@ -25999,48 +25979,40 @@ func TestValidatePodResize(t *testing.T) {
25999
25979
})),
26000
25980
new: mkPod(core.ResourceList{}, getResources("200m", "0", "1Gi", "")),
26001
25981
err: "",
26002
- },
26003
- {
26004
- test: "cpu limit change for sidecar containers",
26005
- old: mkPodWithInitCtrs(core.ResourceList{}, getResources("100m", "0", "1Gi", "")),
26006
- new: mkPodWithInitCtrs(core.ResourceList{}, getResources("200m", "0", "1Gi", "")),
26007
- isSideCarCtr: true,
26008
- err: "",
26009
- }, {
26010
- test: "memory limit change for sidecar containers",
26011
- old: mkPodWithInitCtrs(core.ResourceList{}, getResources("100m", "200Mi", "", "")),
26012
- new: mkPodWithInitCtrs(core.ResourceList{}, getResources("100m", "100Mi", "", "")),
26013
- isSideCarCtr: true,
26014
- err: "",
26015
- }, {
26016
- test: "storage limit change for sidecar containers",
26017
- old: mkPodWithInitCtrs(core.ResourceList{}, getResources("100m", "100Mi", "2Gi", "")),
26018
- new: mkPodWithInitCtrs(core.ResourceList{}, getResources("100m", "100Mi", "1Gi", "")),
26019
- isSideCarCtr: true,
26020
- err: "spec: Forbidden: cpu and memory resources for only sidecar containers are mutable",
26021
- }, {
26022
- test: "cpu request change for sidecar containers",
26023
- old: mkPodWithInitCtrs(getResources("200m", "0", "", ""), core.ResourceList{}),
26024
- new: mkPodWithInitCtrs(getResources("100m", "0", "", ""), core.ResourceList{}),
26025
- isSideCarCtr: true,
26026
- err: "",
26027
- }, {
26028
- test: "memory request change for sidecar containers",
26029
- old: mkPodWithInitCtrs(getResources("0", "100Mi", "", ""), core.ResourceList{}),
26030
- new: mkPodWithInitCtrs(getResources("0", "200Mi", "", ""), core.ResourceList{}),
26031
- isSideCarCtr: true,
26032
- err: "",
26033
- }, {
26034
- test: "storage request change for sidecar containers",
26035
- old: mkPodWithInitCtrs(getResources("100m", "0", "1Gi", ""), core.ResourceList{}),
26036
- new: mkPodWithInitCtrs(getResources("100m", "0", "2Gi", ""), core.ResourceList{}),
26037
- isSideCarCtr: true,
26038
- err: "spec: Forbidden: cpu and memory resources for only sidecar containers are mutable",
25982
+ }, {
25983
+ test: "cpu limit change for sidecar containers",
25984
+ old: mkPodWithInitContainers(core.ResourceList{}, getResources("100m", "0", "1Gi", ""), core.ContainerRestartPolicyAlways),
25985
+ new: mkPodWithInitContainers(core.ResourceList{}, getResources("200m", "0", "1Gi", ""), core.ContainerRestartPolicyAlways),
25986
+ err: "",
25987
+ }, {
25988
+ test: "memory limit change for sidecar containers",
25989
+ old: mkPodWithInitContainers(core.ResourceList{}, getResources("100m", "200Mi", "", ""), core.ContainerRestartPolicyAlways),
25990
+ new: mkPodWithInitContainers(core.ResourceList{}, getResources("100m", "100Mi", "", ""), core.ContainerRestartPolicyAlways),
25991
+ err: "",
25992
+ }, {
25993
+ test: "storage limit change for sidecar containers",
25994
+ old: mkPodWithInitContainers(core.ResourceList{}, getResources("100m", "100Mi", "2Gi", ""), core.ContainerRestartPolicyAlways),
25995
+ new: mkPodWithInitContainers(core.ResourceList{}, getResources("100m", "100Mi", "1Gi", ""), core.ContainerRestartPolicyAlways),
25996
+ err: "spec: Forbidden: cpu and memory resources for only sidecar containers are mutable",
25997
+ }, {
25998
+ test: "cpu request change for sidecar containers",
25999
+ old: mkPodWithInitContainers(getResources("200m", "0", "", ""), core.ResourceList{}, core.ContainerRestartPolicyAlways),
26000
+ new: mkPodWithInitContainers(getResources("100m", "0", "", ""), core.ResourceList{}, core.ContainerRestartPolicyAlways),
26001
+ err: "",
26002
+ }, {
26003
+ test: "memory request change for sidecar containers",
26004
+ old: mkPodWithInitContainers(getResources("0", "100Mi", "", ""), core.ResourceList{}, core.ContainerRestartPolicyAlways),
26005
+ new: mkPodWithInitContainers(getResources("0", "200Mi", "", ""), core.ResourceList{}, core.ContainerRestartPolicyAlways),
26006
+ err: "",
26007
+ }, {
26008
+ test: "storage request change for sidecar containers",
26009
+ old: mkPodWithInitContainers(getResources("100m", "0", "1Gi", ""), core.ResourceList{}, core.ContainerRestartPolicyAlways),
26010
+ new: mkPodWithInitContainers(getResources("100m", "0", "2Gi", ""), core.ResourceList{}, core.ContainerRestartPolicyAlways),
26011
+ err: "spec: Forbidden: cpu and memory resources for only sidecar containers are mutable",
26039
26012
},
26040
26013
}
26041
26014
26042
26015
for _, test := range tests {
26043
- featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SidecarContainers, test.isSideCarCtr)
26044
26016
test.new.ObjectMeta.ResourceVersion = "1"
26045
26017
test.old.ObjectMeta.ResourceVersion = "1"
26046
26018
0 commit comments