Merge pull request #28239 from ApsOps/kubectl-expose-headless-svc

Automatic merge from submit-queue

Add a flag for `kubectl expose`to set ClusterIP and allow headless services

- Use `--cluster-ip=None` to create a headless service
- Fixes #10294
This commit is contained in:
k8s-merge-robot
2016-08-02 01:18:19 -07:00
committed by GitHub
5 changed files with 134 additions and 0 deletions

View File

@@ -198,6 +198,70 @@ func TestRunExposeService(t *testing.T) {
},
status: 200,
},
{
name: "expose-service-cluster-ip",
args: []string{"service", "baz"},
ns: "test",
calls: map[string]string{
"GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services",
},
input: &api.Service{
ObjectMeta: api.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{
Selector: map[string]string{"app": "go"},
},
},
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "cluster-ip": "10.10.10.10", "dry-run": "true"},
output: &api.Service{
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Protocol: api.ProtocolUDP,
Port: 14,
TargetPort: intstr.FromInt(14),
},
},
Selector: map[string]string{"func": "stream"},
ClusterIP: "10.10.10.10",
},
},
expected: "service \"foo\" exposed",
status: 200,
},
{
name: "expose-headless-service",
args: []string{"service", "baz"},
ns: "test",
calls: map[string]string{
"GET": "/namespaces/test/services/baz",
"POST": "/namespaces/test/services",
},
input: &api.Service{
ObjectMeta: api.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
Spec: api.ServiceSpec{
Selector: map[string]string{"app": "go"},
},
},
flags: map[string]string{"selector": "func=stream", "protocol": "UDP", "port": "14", "name": "foo", "labels": "svc=test", "cluster-ip": "None", "dry-run": "true"},
output: &api.Service{
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "", Labels: map[string]string{"svc": "test"}},
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Protocol: api.ProtocolUDP,
Port: 14,
TargetPort: intstr.FromInt(14),
},
},
Selector: map[string]string{"func": "stream"},
ClusterIP: api.ClusterIPNone,
},
},
expected: "service \"foo\" exposed",
status: 200,
},
{
name: "expose-from-file",
args: []string{},