mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
better variable names
This commit is contained in:
parent
79f45bce19
commit
0a80c5ecb7
@ -5508,10 +5508,10 @@ func ValidatePodResize(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that only CPU and memory resources are mutable.
|
// Ensure that only CPU and memory resources are mutable.
|
||||||
mungedPodSpec := *newPod.Spec.DeepCopy()
|
originalCPUMemPodSpec := *newPod.Spec.DeepCopy()
|
||||||
var newContainers []core.Container
|
var newContainers []core.Container
|
||||||
for ix, container := range mungedPodSpec.Containers {
|
for ix, container := range originalCPUMemPodSpec.Containers {
|
||||||
mungeCPUMemResources := func(resourceList, oldResourceList core.ResourceList) core.ResourceList {
|
dropCPUMemoryUpdates := func(resourceList, oldResourceList core.ResourceList) core.ResourceList {
|
||||||
if oldResourceList == nil {
|
if oldResourceList == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -5531,17 +5531,17 @@ func ValidatePodResize(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
|
|||||||
}
|
}
|
||||||
return mungedResourceList
|
return mungedResourceList
|
||||||
}
|
}
|
||||||
lim := mungeCPUMemResources(container.Resources.Limits, oldPod.Spec.Containers[ix].Resources.Limits)
|
lim := dropCPUMemoryUpdates(container.Resources.Limits, oldPod.Spec.Containers[ix].Resources.Limits)
|
||||||
req := mungeCPUMemResources(container.Resources.Requests, oldPod.Spec.Containers[ix].Resources.Requests)
|
req := dropCPUMemoryUpdates(container.Resources.Requests, oldPod.Spec.Containers[ix].Resources.Requests)
|
||||||
container.Resources = core.ResourceRequirements{Limits: lim, Requests: req}
|
container.Resources = core.ResourceRequirements{Limits: lim, Requests: req}
|
||||||
container.ResizePolicy = oldPod.Spec.Containers[ix].ResizePolicy // +k8s:verify-mutation:reason=clone
|
container.ResizePolicy = oldPod.Spec.Containers[ix].ResizePolicy // +k8s:verify-mutation:reason=clone
|
||||||
newContainers = append(newContainers, container)
|
newContainers = append(newContainers, container)
|
||||||
}
|
}
|
||||||
mungedPodSpec.Containers = newContainers
|
originalCPUMemPodSpec.Containers = newContainers
|
||||||
if !apiequality.Semantic.DeepEqual(mungedPodSpec, oldPod.Spec) {
|
if !apiequality.Semantic.DeepEqual(originalCPUMemPodSpec, oldPod.Spec) {
|
||||||
// This likely means that the user has made changes to resources other than CPU and Memory.
|
// This likely means that the user has made changes to resources other than CPU and Memory.
|
||||||
specDiff := cmp.Diff(oldPod.Spec, mungedPodSpec)
|
specDiff := cmp.Diff(oldPod.Spec, originalCPUMemPodSpec)
|
||||||
errs := field.Forbidden(specPath, fmt.Sprintf("pod resize may not change fields other than cpu and memory\n%v", specDiff))
|
errs := field.Forbidden(specPath, fmt.Sprintf("only cpu and memory resources are mutable\n%v", specDiff))
|
||||||
allErrs = append(allErrs, errs)
|
allErrs = append(allErrs, errs)
|
||||||
}
|
}
|
||||||
return allErrs
|
return allErrs
|
||||||
|
@ -25113,7 +25113,7 @@ func TestValidatePodResize(t *testing.T) {
|
|||||||
test: "storage limit change",
|
test: "storage limit change",
|
||||||
old: mkPod(core.ResourceList{}, getResources("100m", "100Mi", "2Gi", "")),
|
old: mkPod(core.ResourceList{}, getResources("100m", "100Mi", "2Gi", "")),
|
||||||
new: mkPod(core.ResourceList{}, getResources("100m", "100Mi", "1Gi", "")),
|
new: mkPod(core.ResourceList{}, getResources("100m", "100Mi", "1Gi", "")),
|
||||||
err: "spec: Forbidden: pod resize may not change fields other than cpu and memory",
|
err: "spec: Forbidden: only cpu and memory resources are mutable",
|
||||||
}, {
|
}, {
|
||||||
test: "cpu request change",
|
test: "cpu request change",
|
||||||
old: mkPod(getResources("200m", "0", "", ""), core.ResourceList{}),
|
old: mkPod(getResources("200m", "0", "", ""), core.ResourceList{}),
|
||||||
@ -25128,7 +25128,7 @@ func TestValidatePodResize(t *testing.T) {
|
|||||||
test: "storage request change",
|
test: "storage request change",
|
||||||
old: mkPod(getResources("100m", "0", "1Gi", ""), core.ResourceList{}),
|
old: mkPod(getResources("100m", "0", "1Gi", ""), core.ResourceList{}),
|
||||||
new: mkPod(getResources("100m", "0", "2Gi", ""), core.ResourceList{}),
|
new: mkPod(getResources("100m", "0", "2Gi", ""), core.ResourceList{}),
|
||||||
err: "spec: Forbidden: pod resize may not change fields other than cpu and memory",
|
err: "spec: Forbidden: only cpu and memory resources are mutable",
|
||||||
}, {
|
}, {
|
||||||
test: "Pod QoS unchanged, guaranteed -> guaranteed",
|
test: "Pod QoS unchanged, guaranteed -> guaranteed",
|
||||||
old: mkPod(getResources("100m", "100Mi", "1Gi", ""), getResources("100m", "100Mi", "1Gi", "")),
|
old: mkPod(getResources("100m", "100Mi", "1Gi", ""), getResources("100m", "100Mi", "1Gi", "")),
|
||||||
|
Loading…
Reference in New Issue
Block a user