Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPSTREAM: 31353: fix duplicate validation/field/errors #10613

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Aug 24, 2016

UPSTREAM: kubernetes/kubernetes#31353

Related PR: #10317
Related BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1257800#c3

PR #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 # rc with two containers

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 # rc with one container

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"

cc @fabianofranz

Related PR: openshift#10317
Related BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1257800#c3

PR openshift#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"
```
@juanvallejo juanvallejo force-pushed the jvallejo_fix-duplicate-errors-oc-set-env branch from 8e2de1f to 7d0ef9e Compare August 24, 2016 16:43
@juanvallejo juanvallejo changed the title UPSTREAM: 0000: fix duplicate validation/field/errors UPSTREAM: 31353: fix duplicate validation/field/errors Aug 24, 2016
@juanvallejo
Copy link
Contributor Author

[test]

errs := make([]error, len(list))
for i := range list {
errs[i] = list[i]
errs := make([]error, 0, len(list))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for creating this with the same length of list? Because if there are any duplicates the length will be different anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 length, len(list) capacity. normally, the length ends up being the same

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right :)

@fabianofranz
Copy link
Member

Might be worth adding something to errors_test.go.

@juanvallejo
Copy link
Contributor Author

juanvallejo commented Aug 24, 2016

@fabianofranz

Might be worth adding something to errors_test.go.

Will do!

I went ahead and included a second related commit (4bc77e4) to this PR I was not sure whether it made more sense to leave it here or move it to a PR of its own, what do you think? cc @liggitt

EDIT: Decided it might be easier to make a second PR for that commit: #10619

@juanvallejo juanvallejo force-pushed the jvallejo_fix-duplicate-errors-oc-set-env branch from 207feed to c9e424b Compare August 24, 2016 21:41
@juanvallejo juanvallejo force-pushed the jvallejo_fix-duplicate-errors-oc-set-env branch from c9e424b to f6f8446 Compare August 24, 2016 21:42
@openshift-bot
Copy link
Contributor

Evaluated for origin test up to f6f8446

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/8414/)

@fabianofranz
Copy link
Member

LGTM [merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Aug 25, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/8414/) (Image: devenv-rhel7_4929)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to f6f8446

@openshift-bot openshift-bot merged commit 504c4e2 into openshift:master Aug 26, 2016
@juanvallejo juanvallejo deleted the jvallejo_fix-duplicate-errors-oc-set-env branch August 26, 2016 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants