Skip to content

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

Merged
merged 1 commit into from
Aug 1, 2017

Conversation

xiangpengzhao
Copy link
Contributor

@xiangpengzhao xiangpengzhao commented Jun 12, 2017

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:

It is possible to express a Service with multiple ports blocks with the same number. This is not very useful and may cause trouble for implementations of Services.

Special notes for your reviewer:
/cc @thockin @liggitt @mengqiy
@kubernetes/sig-network-pr-reviews

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. sig/network Categorizes an issue or PR as relevant to SIG Network. labels Jun 12, 2017
@k8s-ci-robot
Copy link
Contributor

@xiangpengzhao: Reiterating the mentions to trigger a notification:
@kubernetes/sig-network-pr-reviews.

In response to this:

What this PR does / why we need it:
Validate if a service has duplicate Spec.Ports.Port (same number with same protocol)

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): partially fixes #47221
fixes this part:

It is possible to express a Service with multiple ports blocks with the same number. This is not very useful and may cause trouble for implementations of Services.

Special notes for your reviewer:
/cc @thockin @liggitt @mengqiy
@kubernetes/sig-network-pr-reviews

Release note:

NONE

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.

@k8s-ci-robot
Copy link
Contributor

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 @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 12, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Jun 12, 2017
@xiangpengzhao xiangpengzhao force-pushed the fix-dup-port branch 2 times, most recently from 7b009e5 to 519ac02 Compare June 13, 2017 01:06
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 30, 2017
Copy link
Contributor

@pmichali pmichali left a 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,
},
{
Copy link
Contributor

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?

Copy link
Contributor Author

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.

key := api.ServicePort{Protocol: port.Protocol, Port: port.Port}
_, found := ports[key]
if found {
allErrs = append(allErrs, field.Duplicate(portPath.Child("port"), port.Port))
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Will fix.

Copy link
Member

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)

portsPath = specPath.Child("ports")
ports := make(map[api.ServicePort]bool)
for i, port := range service.Spec.Ports {
if port.Port == 0 {
Copy link
Member

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?

Copy link
Contributor Author

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!

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 3, 2017
@xiangpengzhao
Copy link
Contributor Author

inline comments addressed. PTAL.

@mengqiy
Copy link
Member

mengqiy commented Jul 5, 2017

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 5, 2017
@xiangpengzhao
Copy link
Contributor Author

@ping @liggitt and @derekwaynecarr for reviewing
and
/assign @thockin
for approval

thanks!

@xiangpengzhao
Copy link
Contributor Author

Thanks @liggitt ! Inline comment addressed. PTAL.

@thockin
Copy link
Member

thockin commented Aug 1, 2017

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 1, 2017
@k8s-github-robot
Copy link

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 1, 2017
@xiangpengzhao
Copy link
Contributor Author

/retest

@k8s-github-robot
Copy link

Automatic merge from submit-queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/network Categorizes an issue or PR as relevant to SIG Network. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants