Skip to content

Commit 544d8c0

Browse files
committed
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 <[email protected]>
1 parent 07e7368 commit 544d8c0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/apis/core/validation/validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3990,7 +3990,7 @@ func ValidateTolerations(tolerations []core.Toleration, fldPath *field.Path) fie
39903990
}
39913991
case core.TolerationOpExists:
39923992
if len(toleration.Value) > 0 {
3993-
allErrors = append(allErrors, field.Invalid(idxPath.Child("operator"), toleration, "value must be empty when `operator` is 'Exists'"))
3993+
allErrors = append(allErrors, field.Invalid(idxPath.Child("operator"), toleration.Value, "value must be empty when `operator` is 'Exists'"))
39943994
}
39953995
default:
39963996
validValues := []core.TolerationOperator{core.TolerationOpEqual, core.TolerationOpExists}

0 commit comments

Comments
 (0)