Merge pull request #50834 from zjj2wry/fix_validation_expose_port

Automatic merge from submit-queue (batch tested with PRs 50281, 50747, 50347, 50834, 50852)

fix kubectl issue(#52)kubectl run --expose continues after error (mis…

…sing port)



**What this PR does / why we need it**:
https://github.com/kubernetes/kubectl/issues/52
**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-08-17 16:56:25 -07:00 committed by GitHub
commit d958a35ab9

View File

@ -176,6 +176,9 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
if interactive && replicas != 1 {
return cmdutil.UsageErrorf(cmd, "-i/--stdin requires that replicas is 1, found %d", replicas)
}
if cmdutil.GetFlagBool(cmd, "expose") && len(cmdutil.GetFlagString(cmd, "port")) == 0 {
return cmdutil.UsageErrorf(cmd, "--port must be set when exposing a service")
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
@ -537,11 +540,6 @@ func generateService(f cmdutil.Factory, cmd *cobra.Command, args []string, servi
}
names := generator.ParamNames()
port := cmdutil.GetFlagString(cmd, "port")
if len(port) == 0 {
return nil, fmt.Errorf("--port must be set when exposing a service")
}
params := map[string]interface{}{}
for key, value := range paramsIn {
_, isString := value.(string)