-
Notifications
You must be signed in to change notification settings - Fork 40.9k
Validate if service has duplicate port #47336
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
Conversation
@xiangpengzhao: Reiterating the mentions to trigger a notification: In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Hi @xiangpengzhao. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
7b009e5
to
519ac02
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall. Just wondering if additional coverage should be added.
}, | ||
numErrs: 0, | ||
}, | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you have a test case with port==0 to cover that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove the port==0 case as per @mengqiy comment.
pkg/api/validation/validation.go
Outdated
key := api.ServicePort{Protocol: port.Protocol, Port: port.Port} | ||
_, found := ports[key] | ||
if found { | ||
allErrs = append(allErrs, field.Duplicate(portPath.Child("port"), port.Port)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message may be misleading, since it only talks about port
. We should include protocol as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure two errors make sense either... a single error that included both the protocol and the port number is what I would expect - field.Duplicate(portPath, key)
pkg/api/validation/validation.go
Outdated
portsPath = specPath.Child("ports") | ||
ports := make(map[api.ServicePort]bool) | ||
for i, port := range service.Spec.Ports { | ||
if port.Port == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we treat port 0 differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought port can be unspecified. That's incorrect. Thanks for pointing this out!
519ac02
to
36bd862
Compare
36bd862
to
feb68d3
Compare
inline comments addressed. PTAL. |
/ok-to-test |
feb68d3
to
f56bf5a
Compare
@ping @liggitt and @derekwaynecarr for reviewing thanks! |
f56bf5a
to
354394c
Compare
Thanks @liggitt ! Inline comment addressed. PTAL. |
354394c
to
3f28074
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: thockin, xiangpengzhao Associated issue: 47221 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/retest |
Automatic merge from submit-queue |
What this PR does / why we need it:
Validate if a service has duplicate Spec.Ports.Port (same number with same protocol)
xref #47221
fixes this part:
Special notes for your reviewer:
/cc @thockin @liggitt @mengqiy
@kubernetes/sig-network-pr-reviews
Release note: