Skip to content

Commit 0a80c5e

Browse files
committed
better variable names
1 parent 79f45bc commit 0a80c5e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pkg/apis/core/validation/validation.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5508,10 +5508,10 @@ func ValidatePodResize(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
55085508
}
55095509

55105510
// Ensure that only CPU and memory resources are mutable.
5511-
mungedPodSpec := *newPod.Spec.DeepCopy()
5511+
originalCPUMemPodSpec := *newPod.Spec.DeepCopy()
55125512
var newContainers []core.Container
5513-
for ix, container := range mungedPodSpec.Containers {
5514-
mungeCPUMemResources := func(resourceList, oldResourceList core.ResourceList) core.ResourceList {
5513+
for ix, container := range originalCPUMemPodSpec.Containers {
5514+
dropCPUMemoryUpdates := func(resourceList, oldResourceList core.ResourceList) core.ResourceList {
55155515
if oldResourceList == nil {
55165516
return nil
55175517
}
@@ -5531,17 +5531,17 @@ func ValidatePodResize(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
55315531
}
55325532
return mungedResourceList
55335533
}
5534-
lim := mungeCPUMemResources(container.Resources.Limits, oldPod.Spec.Containers[ix].Resources.Limits)
5535-
req := mungeCPUMemResources(container.Resources.Requests, oldPod.Spec.Containers[ix].Resources.Requests)
5534+
lim := dropCPUMemoryUpdates(container.Resources.Limits, oldPod.Spec.Containers[ix].Resources.Limits)
5535+
req := dropCPUMemoryUpdates(container.Resources.Requests, oldPod.Spec.Containers[ix].Resources.Requests)
55365536
container.Resources = core.ResourceRequirements{Limits: lim, Requests: req}
55375537
container.ResizePolicy = oldPod.Spec.Containers[ix].ResizePolicy // +k8s:verify-mutation:reason=clone
55385538
newContainers = append(newContainers, container)
55395539
}
5540-
mungedPodSpec.Containers = newContainers
5541-
if !apiequality.Semantic.DeepEqual(mungedPodSpec, oldPod.Spec) {
5540+
originalCPUMemPodSpec.Containers = newContainers
5541+
if !apiequality.Semantic.DeepEqual(originalCPUMemPodSpec, oldPod.Spec) {
55425542
// This likely means that the user has made changes to resources other than CPU and Memory.
5543-
specDiff := cmp.Diff(oldPod.Spec, mungedPodSpec)
5544-
errs := field.Forbidden(specPath, fmt.Sprintf("pod resize may not change fields other than cpu and memory\n%v", specDiff))
5543+
specDiff := cmp.Diff(oldPod.Spec, originalCPUMemPodSpec)
5544+
errs := field.Forbidden(specPath, fmt.Sprintf("only cpu and memory resources are mutable\n%v", specDiff))
55455545
allErrs = append(allErrs, errs)
55465546
}
55475547
return allErrs

pkg/apis/core/validation/validation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25113,7 +25113,7 @@ func TestValidatePodResize(t *testing.T) {
2511325113
test: "storage limit change",
2511425114
old: mkPod(core.ResourceList{}, getResources("100m", "100Mi", "2Gi", "")),
2511525115
new: mkPod(core.ResourceList{}, getResources("100m", "100Mi", "1Gi", "")),
25116-
err: "spec: Forbidden: pod resize may not change fields other than cpu and memory",
25116+
err: "spec: Forbidden: only cpu and memory resources are mutable",
2511725117
}, {
2511825118
test: "cpu request change",
2511925119
old: mkPod(getResources("200m", "0", "", ""), core.ResourceList{}),
@@ -25128,7 +25128,7 @@ func TestValidatePodResize(t *testing.T) {
2512825128
test: "storage request change",
2512925129
old: mkPod(getResources("100m", "0", "1Gi", ""), core.ResourceList{}),
2513025130
new: mkPod(getResources("100m", "0", "2Gi", ""), core.ResourceList{}),
25131-
err: "spec: Forbidden: pod resize may not change fields other than cpu and memory",
25131+
err: "spec: Forbidden: only cpu and memory resources are mutable",
2513225132
}, {
2513325133
test: "Pod QoS unchanged, guaranteed -> guaranteed",
2513425134
old: mkPod(getResources("100m", "100Mi", "1Gi", ""), getResources("100m", "100Mi", "1Gi", "")),

0 commit comments

Comments
 (0)