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
48c6b7ea
Commit
48c6b7ea
authored
Oct 05, 2015
by
Alex Robinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14728 from kargakis/truncate-inherited-service-names
expose: Truncate service names
parents
32b9d8aa
989806d9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
3 deletions
+60
-3
test-cmd.sh
hack/test-cmd.sh
+12
-0
pod-with-large-name.yaml
hack/testdata/pod-with-large-name.yaml
+11
-0
expose.go
pkg/kubectl/cmd/expose.go
+6
-1
expose_test.go
pkg/kubectl/cmd/expose_test.go
+31
-2
No files found.
hack/test-cmd.sh
View file @
48c6b7ea
...
@@ -702,6 +702,18 @@ __EOF__
...
@@ -702,6 +702,18 @@ __EOF__
# Post-condition: the error message has "invalid resource" string
# Post-condition: the error message has "invalid resource" string
kube::test::if_has_string
"
${
output_message
}
"
'invalid resource'
kube::test::if_has_string
"
${
output_message
}
"
'invalid resource'
### Try to generate a service with invalid name (exceeding maximum valid size)
# Pre-condition: use --name flag
output_message
=
$(
!
kubectl expose
-f
hack/testdata/pod-with-large-name.yaml
--name
=
invalid-large-service-name
--port
=
8081 2>&1
"
${
kube_flags
[@]
}
"
)
# Post-condition: should fail due to invalid name
kube::test::if_has_string
"
${
output_message
}
"
'metadata.name: invalid value'
# Pre-condition: default run without --name flag; should succeed by truncating the inherited name
output_message
=
$(
kubectl expose
-f
hack/testdata/pod-with-large-name.yaml
--port
=
8081 2>&1
"
${
kube_flags
[@]
}
"
)
# Post-condition: inherited name from pod has been truncated
kube::test::if_has_string
"
${
output_message
}
"
'\"kubernetes-serve-hostnam\" exposed'
# Clean-up
kubectl delete svc kubernetes-serve-hostnam
"
${
kube_flags
[@]
}
"
### Delete replication controller with id
### Delete replication controller with id
# Pre-condition: frontend replication controller is running
# Pre-condition: frontend replication controller is running
kube::test::get_object_assert rc
"{{range.items}}{{
$id_field
}}:{{end}}"
'frontend:'
kube::test::get_object_assert rc
"{{range.items}}{{
$id_field
}}:{{end}}"
'frontend:'
...
...
hack/testdata/pod-with-large-name.yaml
0 → 100644
View file @
48c6b7ea
# Used for testing name truncation in kubectl expose
apiVersion
:
v1
kind
:
Pod
metadata
:
name
:
kubernetes-serve-hostname
labels
:
name
:
kubernetes-serve-hostname
spec
:
containers
:
-
name
:
kubernetes-serve-hostname
image
:
gcr.io/google_containers/serve_hostname
pkg/kubectl/cmd/expose.go
View file @
48c6b7ea
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/util/validation"
)
)
// ExposeOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
// ExposeOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
...
@@ -133,7 +134,11 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
...
@@ -133,7 +134,11 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
}
}
names
:=
generator
.
ParamNames
()
names
:=
generator
.
ParamNames
()
params
:=
kubectl
.
MakeParams
(
cmd
,
names
)
params
:=
kubectl
.
MakeParams
(
cmd
,
names
)
params
[
"default-name"
]
=
info
.
Name
name
:=
info
.
Name
if
len
(
name
)
>
validation
.
DNS952LabelMaxLength
{
name
=
name
[
:
validation
.
DNS952LabelMaxLength
]
}
params
[
"default-name"
]
=
name
// For objects that need a pod selector, derive it from the exposed object in case a user
// For objects that need a pod selector, derive it from the exposed object in case a user
// didn't explicitly specify one via --selector
// didn't explicitly specify one via --selector
...
...
pkg/kubectl/cmd/expose_test.go
View file @
48c6b7ea
...
@@ -136,7 +136,7 @@ func TestRunExposeService(t *testing.T) {
...
@@ -136,7 +136,7 @@ func TestRunExposeService(t *testing.T) {
status
:
200
,
status
:
200
,
},
},
{
{
name
:
"expose-
external-
service"
,
name
:
"expose-service"
,
args
:
[]
string
{
"service"
,
"baz"
},
args
:
[]
string
{
"service"
,
"baz"
},
ns
:
"test"
,
ns
:
"test"
,
calls
:
map
[
string
]
string
{
calls
:
map
[
string
]
string
{
...
@@ -168,7 +168,7 @@ func TestRunExposeService(t *testing.T) {
...
@@ -168,7 +168,7 @@ func TestRunExposeService(t *testing.T) {
status
:
200
,
status
:
200
,
},
},
{
{
name
:
"expose-
external-
affinity-service"
,
name
:
"expose-affinity-service"
,
args
:
[]
string
{
"service"
,
"baz"
},
args
:
[]
string
{
"service"
,
"baz"
},
ns
:
"test"
,
ns
:
"test"
,
calls
:
map
[
string
]
string
{
calls
:
map
[
string
]
string
{
...
@@ -226,11 +226,40 @@ func TestRunExposeService(t *testing.T) {
...
@@ -226,11 +226,40 @@ func TestRunExposeService(t *testing.T) {
TargetPort
:
util
.
NewIntOrStringFromInt
(
90
),
TargetPort
:
util
.
NewIntOrStringFromInt
(
90
),
},
},
},
},
Selector
:
map
[
string
]
string
{
"svc"
:
"fromexternal"
},
},
},
},
},
expected
:
"service
\"
frombaz
\"
exposed"
,
expected
:
"service
\"
frombaz
\"
exposed"
,
status
:
200
,
status
:
200
,
},
},
{
name
:
"truncate-name"
,
args
:
[]
string
{
"pod"
,
"a-name-that-is-toooo-big-for-a-service"
},
ns
:
"test"
,
calls
:
map
[
string
]
string
{
"GET"
:
"/namespaces/test/pods/a-name-that-is-toooo-big-for-a-service"
,
"POST"
:
"/namespaces/test/services"
,
},
input
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"baz"
,
Namespace
:
"test"
,
ResourceVersion
:
"12"
},
},
flags
:
map
[
string
]
string
{
"selector"
:
"svc=frompod"
,
"port"
:
"90"
,
"labels"
:
"svc=frompod"
,
"generator"
:
"service/v2"
},
output
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"a-name-that-is-toooo-big"
,
Namespace
:
""
,
Labels
:
map
[
string
]
string
{
"svc"
:
"frompod"
}},
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{
{
Protocol
:
api
.
ProtocolTCP
,
Port
:
90
,
TargetPort
:
util
.
NewIntOrStringFromInt
(
90
),
},
},
Selector
:
map
[
string
]
string
{
"svc"
:
"frompod"
},
},
},
expected
:
"service
\"
a-name-that-is-toooo-big
\"
exposed"
,
status
:
200
,
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
...
...
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