From 544d8c06c39e7f1c50cb11101ec6b222950e96ac Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Wed, 16 Oct 2024 11:40:02 +0200 Subject: [PATCH] Clarify API validation error if `operator` is `Exists` Without this patch the error message for this example: ``` --- apiVersion: v1 kind: Pod metadata: name: test spec: containers: - name: agent image: debian:latest tolerations: - key: pool operator: Exists value: build effect: NoSchedule ``` Looks like: ``` The Pod "test" is invalid: spec.tolerations[0].operator: Invalid value: core.Toleration{Key:"pool", Operator:"Exists", Value:"build", Effect:"NoSchedule", TolerationSeconds:(*int64)(nil)}: value must be empty when `operator` is 'Exists' ``` To clarify that the `Value` field is wrong, we now directly point the `field.Invalid` to it. Now the error message becomes a more clear and concise one: ``` The Pod "test" is invalid: spec.tolerations[0].operator: Invalid value: "build": value must be empty when `operator` is 'Exists' ``` Signed-off-by: Sascha Grunert --- pkg/apis/core/validation/validation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go index 9f6f8da5b42..01d12a036d3 100644 --- a/pkg/apis/core/validation/validation.go +++ b/pkg/apis/core/validation/validation.go @@ -3990,7 +3990,7 @@ func ValidateTolerations(tolerations []core.Toleration, fldPath *field.Path) fie } case core.TolerationOpExists: if len(toleration.Value) > 0 { - allErrors = append(allErrors, field.Invalid(idxPath.Child("operator"), toleration, "value must be empty when `operator` is 'Exists'")) + allErrors = append(allErrors, field.Invalid(idxPath.Child("operator"), toleration.Value, "value must be empty when `operator` is 'Exists'")) } default: validValues := []core.TolerationOperator{core.TolerationOpEqual, core.TolerationOpExists}