Skip to content

Commit cfa0349

Browse files
committed
Update validation code
1 parent c31b1b3 commit cfa0349

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/api/pod/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package pod
1919
import (
2020
"strings"
2121

22-
"github.com/google/go-cmp/cmp" //nolint:depguard
22+
apiequality "k8s.io/apimachinery/pkg/api/equality"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
2525
"k8s.io/apimachinery/pkg/util/sets"

pkg/apis/core/validation/validation.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5644,6 +5644,11 @@ func ValidatePodResize(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
56445644
var newContainers []core.Container
56455645
for ix, container := range originalCPUMemPodSpec.Containers {
56465646
dropCPUMemoryResourcesFromContainer(&container, &oldPod.Spec.Containers[ix])
5647+
if !apiequality.Semantic.DeepEqual(container, oldPod.Spec.Containers[ix]) {
5648+
// This likely means that the user has made changes to resources other than CPU and memory for regular container.
5649+
errs := field.Forbidden(specPath, "only cpu and memory resources are mutable")
5650+
allErrs = append(allErrs, errs)
5651+
}
56475652
newContainers = append(newContainers, container)
56485653
}
56495654
originalCPUMemPodSpec.Containers = newContainers
@@ -5676,8 +5681,7 @@ func ValidatePodResize(newPod, oldPod *core.Pod, opts PodValidationOptions) fiel
56765681

56775682
if !apiequality.Semantic.DeepEqual(originalCPUMemPodSpec, oldPod.Spec) {
56785683
// This likely means that the user has made changes to resources other than CPU and Memory.
5679-
specDiff := cmp.Diff(oldPod.Spec, originalCPUMemPodSpec)
5680-
errs := field.Forbidden(specPath, fmt.Sprintf("only cpu and memory resources are mutable\n%v", specDiff))
5684+
errs := field.Forbidden(specPath, "only cpu and memory resources are mutable")
56815685
allErrs = append(allErrs, errs)
56825686
}
56835687
return allErrs

0 commit comments

Comments
 (0)