Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a5bc6bda
Commit
a5bc6bda
authored
May 15, 2015
by
Jeff Lowdermilk
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8166 from kargakis/labels-for-object
expose: Re-use labels in case none was specified
parents
0f98a1dd
ac652d16
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
77 additions
and
6 deletions
+77
-6
kubectl_expose.md
docs/kubectl_expose.md
+3
-2
kubectl-expose.1
docs/man/man1/kubectl-expose.1
+2
-1
expose.go
pkg/kubectl/cmd/expose.go
+9
-1
expose_test.go
pkg/kubectl/cmd/expose_test.go
+4
-2
factory.go
pkg/kubectl/cmd/util/factory.go
+5
-0
factory_test.go
pkg/kubectl/cmd/util/factory_test.go
+53
-0
service.go
pkg/kubectl/service.go
+1
-0
No files found.
docs/kubectl_expose.md
View file @
a5bc6bda
...
@@ -8,7 +8,8 @@ Take a replicated application and expose it as Kubernetes Service
...
@@ -8,7 +8,8 @@ Take a replicated application and expose it as Kubernetes Service
Take a replicated application and expose it as Kubernetes Service.
Take a replicated application and expose it as Kubernetes Service.
Looks up a replication controller or service by name and uses the selector for that resource as the
Looks up a replication controller or service by name and uses the selector for that resource as the
selector for a new Service on the specified port.
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.
```
```
kubectl expose RESOURCE NAME --port=port [--protocol=TCP|UDP] [--target-port=number-or-name] [--service-name=name] [--public-ip=ip] [--create-external-load-balancer=bool]
kubectl expose RESOURCE NAME --port=port [--protocol=TCP|UDP] [--target-port=number-or-name] [--service-name=name] [--public-ip=ip] [--create-external-load-balancer=bool]
...
@@ -81,4 +82,4 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --service-name=video-str
...
@@ -81,4 +82,4 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --service-name=video-str
### SEE ALSO
### SEE ALSO
*
[
kubectl
](
kubectl.md
)
- kubectl controls the Kubernetes cluster manager
*
[
kubectl
](
kubectl.md
)
- kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra at 2015-05-
08 20:26:40.49295951
+0000 UTC
###### Auto generated by spf13/cobra at 2015-05-
14 09:05:28.99900833
+0000 UTC
docs/man/man1/kubectl-expose.1
View file @
a5bc6bda
...
@@ -17,7 +17,8 @@ Take a replicated application and expose it as Kubernetes Service.
...
@@ -17,7 +17,8 @@ Take a replicated application and expose it as Kubernetes Service.
.PP
.PP
Looks up a replication controller or service by name and uses the selector for that resource as the
Looks up a replication controller or service by name and uses the selector for that resource as the
selector for a new Service on the specified port.
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.
.SH OPTIONS
.SH OPTIONS
...
...
pkg/kubectl/cmd/expose.go
View file @
a5bc6bda
...
@@ -32,7 +32,8 @@ const (
...
@@ -32,7 +32,8 @@ const (
expose_long
=
`Take a replicated application and expose it as Kubernetes Service.
expose_long
=
`Take a replicated application and expose it as Kubernetes Service.
Looks up a replication controller or service by name and uses the selector for that resource as the
Looks up a replication controller or service by name and uses the selector for that resource as the
selector for a new Service on the specified port.`
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.`
expose_example
=
`// Creates a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000.
expose_example
=
`// Creates 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
$ kubectl expose rc nginx --port=80 --target-port=8000
...
@@ -151,6 +152,13 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
...
@@ -151,6 +152,13 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
if
cmdutil
.
GetFlagBool
(
cmd
,
"create-external-load-balancer"
)
{
if
cmdutil
.
GetFlagBool
(
cmd
,
"create-external-load-balancer"
)
{
params
[
"create-external-load-balancer"
]
=
"true"
params
[
"create-external-load-balancer"
]
=
"true"
}
}
if
len
(
params
[
"labels"
])
==
0
{
labels
,
err
:=
f
.
LabelsForObject
(
inputObject
)
if
err
!=
nil
{
return
err
}
params
[
"labels"
]
=
kubectl
.
MakeLabels
(
labels
)
}
err
=
kubectl
.
ValidateParams
(
names
,
params
)
err
=
kubectl
.
ValidateParams
(
names
,
params
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
pkg/kubectl/cmd/expose_test.go
View file @
a5bc6bda
...
@@ -41,13 +41,15 @@ func TestRunExposeService(t *testing.T) {
...
@@ -41,13 +41,15 @@ func TestRunExposeService(t *testing.T) {
args
:
[]
string
{
"service"
,
"baz"
},
args
:
[]
string
{
"service"
,
"baz"
},
input
:
&
api
.
Service
{
input
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1beta3"
},
Spec
:
api
.
ServiceSpec
{
Spec
:
api
.
ServiceSpec
{
Selector
:
map
[
string
]
string
{
"app"
:
"go"
},
Selector
:
map
[
string
]
string
{
"app"
:
"go"
},
},
},
},
},
flags
:
map
[
string
]
string
{
"selector"
:
"func=stream"
,
"protocol"
:
"UDP"
,
"port"
:
"14"
,
"service-name"
:
"foo"
},
flags
:
map
[
string
]
string
{
"selector"
:
"func=stream"
,
"protocol"
:
"UDP"
,
"port"
:
"14"
,
"service-name"
:
"foo"
,
"labels"
:
"svc=test"
},
output
:
&
api
.
Service
{
output
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
,
Labels
:
map
[
string
]
string
{
"svc"
:
"test"
}},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1beta3"
},
Spec
:
api
.
ServiceSpec
{
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{
Ports
:
[]
api
.
ServicePort
{
{
{
...
...
pkg/kubectl/cmd/util/factory.go
View file @
a5bc6bda
...
@@ -73,6 +73,8 @@ type Factory struct {
...
@@ -73,6 +73,8 @@ type Factory struct {
PodSelectorForObject
func
(
object
runtime
.
Object
)
(
string
,
error
)
PodSelectorForObject
func
(
object
runtime
.
Object
)
(
string
,
error
)
// PortsForObject returns the ports associated with the provided object
// PortsForObject returns the ports associated with the provided object
PortsForObject
func
(
object
runtime
.
Object
)
([]
string
,
error
)
PortsForObject
func
(
object
runtime
.
Object
)
([]
string
,
error
)
// LabelsForObject returns the labels associated with the provided object
LabelsForObject
func
(
object
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
// Returns a schema that can validate objects stored on disk.
// Returns a schema that can validate objects stored on disk.
Validator
func
()
(
validation
.
Schema
,
error
)
Validator
func
()
(
validation
.
Schema
,
error
)
// Returns the default namespace to use in cases where no other namespace is specified
// Returns the default namespace to use in cases where no other namespace is specified
...
@@ -182,6 +184,9 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -182,6 +184,9 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
nil
,
fmt
.
Errorf
(
"it is not possible to get ports from %s"
,
kind
)
return
nil
,
fmt
.
Errorf
(
"it is not possible to get ports from %s"
,
kind
)
}
}
},
},
LabelsForObject
:
func
(
object
runtime
.
Object
)
(
map
[
string
]
string
,
error
)
{
return
meta
.
NewAccessor
()
.
Labels
(
object
)
},
Resizer
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Resizer
,
error
)
{
Resizer
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Resizer
,
error
)
{
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
APIVersion
)
client
,
err
:=
clients
.
ClientForVersion
(
mapping
.
APIVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/kubectl/cmd/util/factory_test.go
View file @
a5bc6bda
...
@@ -23,6 +23,8 @@ import (
...
@@ -23,6 +23,8 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
clientcmdapi
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
clientcmdapi
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
)
)
func
TestNewFactoryDefaultFlagBindings
(
t
*
testing
.
T
)
{
func
TestNewFactoryDefaultFlagBindings
(
t
*
testing
.
T
)
{
...
@@ -100,3 +102,54 @@ func TestPortsForObject(t *testing.T) {
...
@@ -100,3 +102,54 @@ func TestPortsForObject(t *testing.T) {
}
}
}
}
}
}
func
TestLabelsForObject
(
t
*
testing
.
T
)
{
f
:=
NewFactory
(
nil
)
tests
:=
[]
struct
{
name
string
object
runtime
.
Object
expected
string
err
error
}{
{
name
:
"successful re-use of labels"
,
object
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
Labels
:
map
[
string
]
string
{
"svc"
:
"test"
}},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1beta3"
},
},
expected
:
"svc=test"
,
err
:
nil
,
},
{
name
:
"empty labels"
,
object
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"test"
,
Labels
:
map
[
string
]
string
{}},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1beta3"
},
},
expected
:
""
,
err
:
nil
,
},
{
name
:
"nil labels"
,
object
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"zen"
,
Namespace
:
"test"
,
Labels
:
nil
},
TypeMeta
:
api
.
TypeMeta
{
Kind
:
"Service"
,
APIVersion
:
"v1beta3"
},
},
expected
:
""
,
err
:
nil
,
},
}
for
_
,
test
:=
range
tests
{
gotLabels
,
err
:=
f
.
LabelsForObject
(
test
.
object
)
if
err
!=
test
.
err
{
t
.
Fatalf
(
"%s: Error mismatch: Expected %v, got %v"
,
test
.
name
,
test
.
err
,
err
)
}
got
:=
kubectl
.
MakeLabels
(
gotLabels
)
if
test
.
expected
!=
got
{
t
.
Fatalf
(
"%s: Labels mismatch! Expected %s, got %s"
,
test
.
name
,
test
.
expected
,
got
)
}
}
}
pkg/kubectl/service.go
View file @
a5bc6bda
...
@@ -32,6 +32,7 @@ func (ServiceGenerator) ParamNames() []GeneratorParam {
...
@@ -32,6 +32,7 @@ func (ServiceGenerator) ParamNames() []GeneratorParam {
{
"name"
,
true
},
{
"name"
,
true
},
{
"selector"
,
true
},
{
"selector"
,
true
},
{
"port"
,
true
},
{
"port"
,
true
},
{
"labels"
,
false
},
{
"public-ip"
,
false
},
{
"public-ip"
,
false
},
{
"create-external-load-balancer"
,
false
},
{
"create-external-load-balancer"
,
false
},
{
"protocol"
,
false
},
{
"protocol"
,
false
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment