kubernetes/pkg/kubectl/cmd/util
Kubernetes Submit Queue 05192d9d57 Merge pull request #33319 from juanvallejo/jvallejo/add-option-to-set-nodeport
Automatic merge from submit-queue

Add option to set a service nodeport

**Release note**:
```release-note
Add kubectl --node-port option for specifying the service nodeport
```

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**
```
# create a nodeport service with an invalid port
$ kubectl 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

# create a nodeport service with a valid port
$ kubectl create service nodeport mynodeport --tcp=8080:7777 --node-port=30000
service "mynodeport" created

# create a nodeport service with a port already in use
$ kubectl create service nodeport mynodeport --tcp=8080:7777 --node-port=30000
The Service "mynodeport" is invalid: spec.ports[0].nodePort: Invalid value: 3000: provided port is already allocated

$ kubectl 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.
```

@fabianofranz
2016-10-05 15:00:32 -07:00
..
editor Remove "All rights reserved" from all the headers. 2016-06-29 17:47:36 -07:00
jsonmerge change all jsonmerge to strategicpatch 2016-09-09 08:28:10 +08:00
clientcache.go convert rest of kubectl to generated clients 2016-09-12 08:22:34 -04:00
factory_test.go Extend all to more resources 2016-09-19 13:01:59 -04:00
factory.go Replace references to http://releases.k8s.io/HEAD/docs/user-guide/ 2016-10-02 11:44:40 +01:00
helpers_test.go if test succ remove the tmp file 2016-09-28 16:52:55 +08:00
helpers.go Merge pull request #33319 from juanvallejo/jvallejo/add-option-to-set-nodeport 2016-10-05 15:00:32 -07:00
printing.go update PrintSuccess message when using --dry-run 2016-09-15 10:11:21 -04:00
shortcut_restmapper_test.go Extend all to more resources 2016-09-19 13:01:59 -04:00
shortcut_restmapper.go Extend all to more resources 2016-09-19 13:01:59 -04:00