mirror of https://github.com/k3s-io/k3s
add port validate when --port is set or --expose=true
parent
956501b1f0
commit
ef87972835
|
@ -112,7 +112,7 @@ func addRunFlags(cmd *cobra.Command) {
|
|||
cmd.Flags().Bool("rm", false, "If true, delete resources created in this command for attached containers.")
|
||||
cmd.Flags().String("overrides", "", "An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field.")
|
||||
cmd.Flags().StringSlice("env", []string{}, "Environment variables to set in the container")
|
||||
cmd.Flags().Int("port", -1, "The port that this container exposes. If --expose is true, this is also the port used by the service that is created.")
|
||||
cmd.Flags().String("port", "", "The port that this container exposes. If --expose is true, this is also the port used by the service that is created.")
|
||||
cmd.Flags().Int("hostport", -1, "The host port mapping for the container port. To demonstrate a single-machine container.")
|
||||
cmd.Flags().StringP("labels", "l", "", "Labels to apply to the pod(s).")
|
||||
cmd.Flags().BoolP("stdin", "i", false, "Keep stdin open on the container(s) in the pod, even if nothing is attached.")
|
||||
|
@ -536,9 +536,9 @@ func generateService(f *cmdutil.Factory, cmd *cobra.Command, args []string, serv
|
|||
}
|
||||
names := generator.ParamNames()
|
||||
|
||||
port := cmdutil.GetFlagInt(cmd, "port")
|
||||
if port < 1 {
|
||||
return fmt.Errorf("--port must be a positive integer when exposing a service")
|
||||
port := cmdutil.GetFlagString(cmd, "port")
|
||||
if len(port) == 0 {
|
||||
return fmt.Errorf("--port must be set when exposing a service")
|
||||
}
|
||||
|
||||
params := map[string]interface{}{}
|
||||
|
|
|
@ -796,7 +796,7 @@ func updatePodPorts(params map[string]string, podSpec *api.PodSpec) (err error)
|
|||
}
|
||||
|
||||
// Don't include the port if it was not specified.
|
||||
if port > 0 {
|
||||
if len(params["port"]) > 0 {
|
||||
podSpec.Containers[0].Ports = []api.ContainerPort{
|
||||
{
|
||||
ContainerPort: int32(port),
|
||||
|
|
|
@ -39,7 +39,7 @@ func TestGenerate(t *testing.T) {
|
|||
"image": "someimage",
|
||||
"image-pull-policy": "Always",
|
||||
"replicas": "1",
|
||||
"port": "-1",
|
||||
"port": "",
|
||||
},
|
||||
expected: &api.ReplicationController{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
|
@ -72,7 +72,7 @@ func TestGenerate(t *testing.T) {
|
|||
"name": "foo",
|
||||
"image": "someimage",
|
||||
"replicas": "1",
|
||||
"port": "-1",
|
||||
"port": "",
|
||||
"env": []string{"a=b", "c=d"},
|
||||
},
|
||||
expected: &api.ReplicationController{
|
||||
|
@ -116,7 +116,7 @@ func TestGenerate(t *testing.T) {
|
|||
"image": "someimage",
|
||||
"image-pull-policy": "Never",
|
||||
"replicas": "1",
|
||||
"port": "-1",
|
||||
"port": "",
|
||||
"args": []string{"bar", "baz", "blah"},
|
||||
},
|
||||
expected: &api.ReplicationController{
|
||||
|
@ -150,7 +150,7 @@ func TestGenerate(t *testing.T) {
|
|||
"name": "foo",
|
||||
"image": "someimage",
|
||||
"replicas": "1",
|
||||
"port": "-1",
|
||||
"port": "",
|
||||
"args": []string{"bar", "baz", "blah"},
|
||||
"command": "true",
|
||||
},
|
||||
|
@ -410,7 +410,7 @@ func TestGeneratePod(t *testing.T) {
|
|||
params: map[string]interface{}{
|
||||
"name": "foo",
|
||||
"image": "someimage",
|
||||
"port": "-1",
|
||||
"port": "",
|
||||
},
|
||||
expected: &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
|
|
Loading…
Reference in New Issue