mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 04:52:08 +00:00
Update validation code
This commit is contained in:
parent
c31b1b3332
commit
cfa0349159
@ -19,7 +19,7 @@ package pod
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-cmp/cmp" //nolint:depguard
|
||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
|
@ -5644,6 +5644,11 @@ func ValidatePodResize(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
|
||||
var newContainers []core.Container
|
||||
for ix, container := range originalCPUMemPodSpec.Containers {
|
||||
dropCPUMemoryResourcesFromContainer(&container, &oldPod.Spec.Containers[ix])
|
||||
if !apiequality.Semantic.DeepEqual(container, oldPod.Spec.Containers[ix]) {
|
||||
// This likely means that the user has made changes to resources other than CPU and memory for regular container.
|
||||
errs := field.Forbidden(specPath, "only cpu and memory resources are mutable")
|
||||
allErrs = append(allErrs, errs)
|
||||
}
|
||||
newContainers = append(newContainers, container)
|
||||
}
|
||||
originalCPUMemPodSpec.Containers = newContainers
|
||||
@ -5676,8 +5681,7 @@ func ValidatePodResize(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
|
||||
|
||||
if !apiequality.Semantic.DeepEqual(originalCPUMemPodSpec, oldPod.Spec) {
|
||||
// This likely means that the user has made changes to resources other than CPU and Memory.
|
||||
specDiff := cmp.Diff(oldPod.Spec, originalCPUMemPodSpec)
|
||||
errs := field.Forbidden(specPath, fmt.Sprintf("only cpu and memory resources are mutable\n%v", specDiff))
|
||||
errs := field.Forbidden(specPath, "only cpu and memory resources are mutable")
|
||||
allErrs = append(allErrs, errs)
|
||||
}
|
||||
return allErrs
|
||||
|
Loading…
Reference in New Issue
Block a user