Skip to content

Commit 0036f72

Browse files
juanvallejosmarterclayton
authored andcommitted
UPSTREAM: 31353: fix duplicate validation/field/errors
Related PR: openshift/origin#10317 Related BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1257800#c3 PR kubernetes#10317 fixed duplicate errors for invalid aggregate errors in https://github.com/openshift/origin/blob/master/vendor/k8s.io/kubernetes/pkg/kubectl/cmd/util/helpers.go. However, duplicate aggregate errors that went through https://github.com/openshift/origin/blob/master/vendor/k8s.io/kubernetes/pkg/util/validation/field/errors.go were not affected by that patch. This patch adds duplicate aggregate error checking to `pkg/util/validation/field/errors.go` \##### Before `$ oc set env rc/idling-echo-1 test-abc=1234` ``` error: ReplicationController "idling-echo-1" is invalid: [spec.template.spec.containers[0].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName", spec.template.spec.containers[1].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName", spec.template.spec.containers[0].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName", spec.template.spec.containers[1].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName"] ``` `$ oc set env rc/node-1 test-abc=1234` ``` error: ReplicationController "idling-echo-1" is invalid: [spec.template.spec.containers[0].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName", spec.template.spec.containers[1].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName"] ``` \##### After `$ oc set env rc/idling-echo-1 test-abc=1234` ``` error: ReplicationController "idling-echo-1" is invalid: [spec.template.spec.containers[0].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName", spec.template.spec.containers[1].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName"] ``` `$ oc set env rc/node-1 test-abc=1234` ``` error: ReplicationController "node-1" is invalid: spec.template.spec.containers[0].env[0].name: Invalid value: "test-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName" ``` :100644 100644 203f7cc... 089f21c... M pkg/util/validation/field/errors.go
1 parent 0c4ceb3 commit 0036f72

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pkg/util/validation/field/errors.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323

2424
utilerrors "k8s.io/kubernetes/pkg/util/errors"
25+
"k8s.io/kubernetes/pkg/util/sets"
2526
)
2627

2728
// Error is an implementation of the 'error' interface, which represents a
@@ -201,9 +202,15 @@ func NewErrorTypeMatcher(t ErrorType) utilerrors.Matcher {
201202

202203
// ToAggregate converts the ErrorList into an errors.Aggregate.
203204
func (list ErrorList) ToAggregate() utilerrors.Aggregate {
204-
errs := make([]error, len(list))
205-
for i := range list {
206-
errs[i] = list[i]
205+
errs := make([]error, 0, len(list))
206+
errorMsgs := sets.NewString()
207+
for _, err := range list {
208+
msg := fmt.Sprintf("%v", err)
209+
if errorMsgs.Has(msg) {
210+
continue
211+
}
212+
errorMsgs.Insert(msg)
213+
errs = append(errs, err)
207214
}
208215
return utilerrors.NewAggregate(errs)
209216
}

0 commit comments

Comments
 (0)