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: 33319: add nodeport option when creating NodePort service #11059

Merged

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Sep 22, 2016

UPSTREAM: kubernetes/kubernetes#33319
Related bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1378012

This patch adds the option to set a nodeport when creating a NodePort
service. In case of a port allocation error due to a specified port
being out of the valid range, the error now includes the valid
range. If a --nodeport value is not specified, it defaults to zero, in
which case the allocator will default to its current behavior of
assigning an available port.

This patch also adds a new helper function in cmd/util/helpers.go to
retrieve Int32 cobra flags.

Example

$ oc create service nodeport mynodeport --tcp=8080:7777 --nodeport=1
The Service "mynodeport" is invalid: spec.ports[0].nodePort: Invalid
value: 1: provided port is not in the valid range. Valid ports range
from 30000-32767

$ oc create service nodeport mynodeport --tcp=8080:7777 --nodeport=30000
service "mynodeport" created

$ oc describe service mynodeport
Name:                   mynodeport
Namespace:              default
Labels:                 app=mynodeport
Selector:               app=mynodeport
Type:                   NodePort
IP:                     172.30.81.254
Port:                   8080-7777       8080/TCP
NodePort:               8080-7777       30000/TCP
Endpoints:              <none>
Session Affinity:       None
No events.

cc @openshift/cli-review @csrwng

@juanvallejo
Copy link
Contributor Author

[test]

Copy link
Contributor

@csrwng csrwng left a comment

Choose a reason for hiding this comment

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

Overall looks good, just minor comments.

func GetFlagInt32(cmd *cobra.Command, flag string) int32 {
i, err := cmd.Flags().GetInt32(flag)
if err != nil {
glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/err/error/

@@ -133,6 +133,7 @@ func NewCmdCreateServiceNodePort(f *cmdutil.Factory, cmdOut io.Writer) *cobra.Co
cmdutil.AddValidateFlags(cmd)
cmdutil.AddPrinterFlags(cmd)
cmdutil.AddGeneratorFlags(cmd, cmdutil.ServiceNodePortGeneratorV1Name)
cmd.Flags().Int32("nodeport", 0, "Port used to expose the service on each node in a cluster.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like it should be named "node-port" based on the capitalization used in the API (NodePort)

return ErrNotInRange
// include valid port range in error
validPorts := r.portRange.String()
msg := fmt.Sprintf("Valid ports range from %s", validPorts)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit ... I think "Valid ports range is %s" would be better

@juanvallejo juanvallejo force-pushed the jvallejo/add-nodeport-option branch from 1588b81 to fc8e559 Compare September 22, 2016 20:06
@juanvallejo
Copy link
Contributor Author

@csrwng Review comments addressed, thanks for the feedback!

@juanvallejo juanvallejo changed the title add nodeport option when creating NodePort service UPSTREAM: 33319: add nodeport option when creating NodePort service Sep 22, 2016
@juanvallejo juanvallejo force-pushed the jvallejo/add-nodeport-option branch 2 times, most recently from 55fb03e to 2e5ece4 Compare September 22, 2016 20:43
@juanvallejo juanvallejo force-pushed the jvallejo/add-nodeport-option branch from f80e7cf to f7c9a97 Compare September 23, 2016 18:12
@juanvallejo
Copy link
Contributor Author

conformance test flaked on #11079 re[test]

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 26, 2016
@juanvallejo juanvallejo force-pushed the jvallejo/add-nodeport-option branch from f7c9a97 to 5ed2b4c Compare October 6, 2016 17:35
@openshift-bot openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 6, 2016
@juanvallejo
Copy link
Contributor Author

@fabianofranz or @csrwng upstream PR merged, PTAL

@fabianofranz
Copy link
Member

@juanvallejo is this up-to-date with upstream (4 versus 2 commits)?

@juanvallejo
Copy link
Contributor Author

@fabianofranz it's up to date, I had forgotten to squash upstream :/

UPSTREAM: kubernetes/kubernetes#33319

This patch adds the option to set a nodeport when creating a NodePort
service. In case of a port allocation error due to a specified port
being out of the valid range, the error now includes the valid
range. If a `--node-port` value is not specified, it defaults to zero, in
which case the allocator will default to its current behavior of
assigning an available port.

This patch also adds a new helper function in `cmd/util/helpers.go` to
retrieve `Int32` cobra flags.

**Example**
```
$ oc create service nodeport mynodeport --tcp=8080:7777 --node-port=1
The Service "mynodeport" is invalid: spec.ports[0].nodePort: Invalid
value: 1: provided port is not in the valid range. Valid ports range
from 30000-32767

$ oc create service nodeport mynodeport --tcp=8080:7777 --node-port=30000
service "mynodeport" created

$ oc describe service mynodeport
Name:                   mynodeport
Namespace:              default
Labels:                 app=mynodeport
Selector:               app=mynodeport
Type:                   NodePort
IP:                     172.30.81.254
Port:                   8080-7777       8080/TCP
NodePort:               8080-7777       30000/TCP
Endpoints:              <none>
Session Affinity:       None
No events.
```
@juanvallejo juanvallejo force-pushed the jvallejo/add-nodeport-option branch from 5ed2b4c to 26655c5 Compare October 6, 2016 20:40
@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 26655c5

@fabianofranz
Copy link
Member

[merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Oct 6, 2016

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

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 26655c5

@openshift-bot
Copy link
Contributor

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

@openshift-bot openshift-bot merged commit 128758d into openshift:master Oct 9, 2016
@juanvallejo juanvallejo deleted the jvallejo/add-nodeport-option branch October 10, 2016 14:00
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.

4 participants