Skip to content

Commit

Permalink
Merge pull request kubernetes#12094 from brendandburns/kubectl
Browse files Browse the repository at this point in the history
Auto commit by PR queue bot
  • Loading branch information
alex-mohr committed Aug 4, 2015
2 parents 6d16c18 + c9bc145 commit 7ac6c50
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions contrib/completions/bash/kubectl
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ _kubectl_expose()
flags+=("--protocol=")
flags+=("--public-ip=")
flags+=("--selector=")
flags+=("--session-affinity=")
flags+=("--target-port=")
flags+=("--template=")
two_word_flags+=("-t")
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/kubectl-expose.1
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ re\-use the labels from the resource it exposes.
\fB\-\-selector\fP=""
A label selector to use for this service. If empty (the default) infer the selector from the replication controller.

.PP
\fB\-\-session\-affinity\fP=""
If non\-empty, set the session affinity for the service to this; legal values: 'None', 'ClientIP'

.PP
\fB\-\-target\-port\fP=""
Name or number for the port on the container that the service should direct traffic to. Optional.
Expand Down
3 changes: 2 additions & 1 deletion docs/user-guide/kubectl/kubectl_expose.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream
--protocol="TCP": The network protocol for the service to be created. Default is 'tcp'.
--public-ip="": Name of a public IP address to set for the service. The service will be assigned this IP in addition to its generated service IP.
--selector="": A label selector to use for this service. If empty (the default) infer the selector from the replication controller.
--session-affinity="": If non-empty, set the session affinity for the service to this; legal values: 'None', 'ClientIP'
--target-port="": Name or number for the port on the container that the service should direct traffic to. Optional.
-t, --template="": Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]
--type="": Type for this service: ClusterIP, NodePort, or LoadBalancer. Default is 'ClusterIP' unless --create-external-load-balancer is specified.
Expand Down Expand Up @@ -117,7 +118,7 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream

* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager

###### Auto generated by spf13/cobra at 2015-07-17 01:17:57.020108348 +0000 UTC
###### Auto generated by spf13/cobra at 2015-07-31 17:33:19.568673976 +0000 UTC


<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
Expand Down
1 change: 1 addition & 0 deletions pkg/kubectl/cmd/expose.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func NewCmdExposeService(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmd.Flags().String("public-ip", "", "Name of a public IP address to set for the service. The service will be assigned this IP in addition to its generated service IP.")
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().String("name", "", "The name for the newly created object.")
cmd.Flags().String("session-affinity", "", "If non-empty, set the session affinity for the service to this; legal values: 'None', 'ClientIP'")
return cmd
}

Expand Down
35 changes: 35 additions & 0 deletions pkg/kubectl/cmd/expose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,41 @@ func TestRunExposeService(t *testing.T) {
},
status: 200,
},
{
name: "expose-external-affinity-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"},
TypeMeta: api.TypeMeta{Kind: "Service", APIVersion: "v1"},
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", "create-external-load-balancer": "true", "session-affinity": "ClientIP"},
output: &api.Service{
ObjectMeta: api.ObjectMeta{Name: "foo", Namespace: "test", ResourceVersion: "12", Labels: map[string]string{"svc": "test"}},
TypeMeta: api.TypeMeta{Kind: "Service", APIVersion: "v1"},
Spec: api.ServiceSpec{
Ports: []api.ServicePort{
{
Name: "default",
Protocol: api.Protocol("UDP"),
Port: 14,
TargetPort: util.NewIntOrStringFromInt(14),
},
},
Selector: map[string]string{"func": "stream"},
Type: api.ServiceTypeLoadBalancer,
SessionAffinity: api.ServiceAffinityClientIP,
},
},
status: 200,
},
}

for _, test := range tests {
Expand Down
11 changes: 11 additions & 0 deletions pkg/kubectl/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func paramNames() []GeneratorParam {
{"container-port", false}, // alias of target-port
{"target-port", false},
{"port-name", false},
{"session-affinity", false},
}
}

Expand Down Expand Up @@ -141,5 +142,15 @@ func generate(params map[string]string) (runtime.Object, error) {
if len(params["type"]) != 0 {
service.Spec.Type = api.ServiceType(params["type"])
}
if len(params["session-affinity"]) != 0 {
switch api.ServiceAffinity(params["session-affinity"]) {
case api.ServiceAffinityNone:
service.Spec.SessionAffinity = api.ServiceAffinityNone
case api.ServiceAffinityClientIP:
service.Spec.SessionAffinity = api.ServiceAffinityClientIP
default:
return nil, fmt.Errorf("unknown session affinity: %s", params["session-affinity"])
}
}
return &service, nil
}
31 changes: 31 additions & 0 deletions pkg/kubectl/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,37 @@ func TestGenerateService(t *testing.T) {
},
},
},
{
generator: ServiceGeneratorV1{},
params: map[string]string{
"selector": "foo=bar,baz=blah",
"name": "test",
"port": "80",
"protocol": "TCP",
"container-port": "1234",
"session-affinity": "ClientIP",
},
expected: api.Service{
ObjectMeta: api.ObjectMeta{
Name: "test",
},
Spec: api.ServiceSpec{
Selector: map[string]string{
"foo": "bar",
"baz": "blah",
},
Ports: []api.ServicePort{
{
Name: "default",
Port: 80,
Protocol: "TCP",
TargetPort: util.NewIntOrStringFromInt(1234),
},
},
SessionAffinity: api.ServiceAffinityClientIP,
},
},
},
}
for _, test := range tests {
obj, err := test.generator.Generate(test.params)
Expand Down

0 comments on commit 7ac6c50

Please sign in to comment.