Merge pull request #15461 from kargakis/relax-exposing-multiport-objects

expose: Enable exposing multiport objects
This commit is contained in:
Jerzy Szczepkowski
2015-10-27 10:25:54 +01:00
8 changed files with 237 additions and 37 deletions

View File

@@ -235,6 +235,8 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
}
rf := cmdutil.NewFactory(nil)
f.PodSelectorForObject = rf.PodSelectorForObject
f.PortsForObject = rf.PortsForObject
f.LabelsForObject = rf.LabelsForObject
f.CanBeExposed = rf.CanBeExposed
return f, t, testapi.Default.Codec()
}

View File

@@ -19,6 +19,7 @@ package cmd
import (
"fmt"
"io"
"strings"
"github.com/spf13/cobra"
@@ -35,11 +36,12 @@ type ExposeOptions struct {
}
const (
expose_long = `Take a replication controller, service or pod and expose it as a new Kubernetes Service.
expose_long = `Take a replication controller, service, or pod and expose it as a new Kubernetes service.
Looks up a replication controller, service or pod by name and uses the selector for that resource as the
selector for a new Service on the specified port. If no labels are specified, the new service will
re-use the labels from the resource it exposes.`
Looks up a replication controller, service, or pod by name and uses the selector for that resource as the
selector for a new service on the specified port. Note that if no port is specified via --port and the
exposed resource has multiple ports, all will be re-used by the new service. Also if no labels are specified,
the new service will re-use the labels from the resource it exposes.`
expose_example = `# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000.
$ kubectl expose rc nginx --port=80 --target-port=8000
@@ -163,7 +165,7 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
case 1:
params["port"] = ports[0]
default:
return cmdutil.UsageError(cmd, fmt.Sprintf("multiple ports to choose from: %v, please explicitly specify a port using the --port flag.", ports))
params["ports"] = strings.Join(ports, ",")
}
}
if kubectl.IsZero(params["labels"]) {

View File

@@ -286,6 +286,54 @@ func TestRunExposeService(t *testing.T) {
expected: "service \"a-name-that-is-toooo-big\" exposed",
status: 200,
},
{
name: "expose-multiport-object",
args: []string{"service", "foo"},
ns: "test",
calls: map[string]string{
"GET": "/namespaces/test/services/foo",
"POST": "/namespaces/test/services",
},
input: &api.Service{
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Protocol: api.ProtocolTCP,
Port: 80,
TargetPort: util.NewIntOrStringFromInt(80),
},
{
Protocol: api.ProtocolTCP,
Port: 443,
TargetPort: util.NewIntOrStringFromInt(443),
},
},
},
},
flags: map[string]string{"selector": "svc=fromfoo", "generator": "service/v2", "name": "fromfoo", "dry-run": "true"},
output: &api.Service{
ObjectMeta: api.ObjectMeta{Name: "fromfoo", Namespace: "", Labels: map[string]string{"svc": "multiport"}},
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Name: "port-1",
Protocol: api.ProtocolTCP,
Port: 80,
TargetPort: util.NewIntOrStringFromInt(80),
},
{
Name: "port-2",
Protocol: api.ProtocolTCP,
Port: 443,
TargetPort: util.NewIntOrStringFromInt(443),
},
},
Selector: map[string]string{"svc": "fromfoo"},
},
},
status: 200,
},
}
for _, test := range tests {