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
b1e7e6cf
Commit
b1e7e6cf
authored
Jul 24, 2016
by
Michael Fraenkel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Service names conform to RFC 1035
parent
31da82df
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
34 additions
and
34 deletions
+34
-34
test-cmd.sh
hack/make-rules/test-cmd.sh
+3
-3
pod-with-large-name.yaml
hack/testdata/pod-with-large-name.yaml
+1
-1
validation.go
pkg/api/validation/validation.go
+4
-4
validation_test.go
pkg/api/validation/validation_test.go
+2
-2
dns.go
pkg/dns/dns.go
+3
-3
expose.go
pkg/kubectl/cmd/expose.go
+2
-2
expose_test.go
pkg/kubectl/cmd/expose_test.go
+4
-4
validation.go
pkg/util/validation/validation.go
+10
-10
validation_test.go
pkg/util/validation/validation_test.go
+5
-5
No files found.
hack/make-rules/test-cmd.sh
View file @
b1e7e6cf
...
@@ -1765,15 +1765,15 @@ __EOF__
...
@@ -1765,15 +1765,15 @@ __EOF__
### Try to generate a service with invalid name (exceeding maximum valid size)
### Try to generate a service with invalid name (exceeding maximum valid size)
# Pre-condition: use --name flag
# 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
[@]
}
"
)
output_message
=
$(
!
kubectl expose
-f
hack/testdata/pod-with-large-name.yaml
--name
=
invalid-large-service-name
-that-has-more-than-sixty-three-characters
--port
=
8081 2>&1
"
${
kube_flags
[@]
}
"
)
# Post-condition: should fail due to invalid name
# Post-condition: should fail due to invalid name
kube::test::if_has_string
"
${
output_message
}
"
'metadata.name: Invalid value'
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
# 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
[@]
}
"
)
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
# Post-condition: inherited name from pod has been truncated
kube::test::if_has_string
"
${
output_message
}
"
'\"kubernetes-serve-hostnam\" exposed'
kube::test::if_has_string
"
${
output_message
}
"
'\"kubernetes-serve-hostnam
e-testing-sixty-three-characters-in-len
\" exposed'
# Clean-up
# Clean-up
kubectl delete svc kubernetes-serve-hostnam
"
${
kube_flags
[@]
}
"
kubectl delete svc kubernetes-serve-hostnam
e-testing-sixty-three-characters-in-len
"
${
kube_flags
[@]
}
"
### Expose multiport object as a new service
### Expose multiport object as a new service
# Pre-condition: don't use --port flag
# Pre-condition: don't use --port flag
...
...
hack/testdata/pod-with-large-name.yaml
View file @
b1e7e6cf
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
apiVersion
:
v1
apiVersion
:
v1
kind
:
Pod
kind
:
Pod
metadata
:
metadata
:
name
:
kubernetes-serve-hostname
name
:
kubernetes-serve-hostname
-testing-sixty-three-characters-in-length
labels
:
labels
:
name
:
kubernetes-serve-hostname
name
:
kubernetes-serve-hostname
spec
:
spec
:
...
...
pkg/api/validation/validation.go
View file @
b1e7e6cf
...
@@ -204,7 +204,7 @@ var ValidateReplicationControllerName = NameIsDNSSubdomain
...
@@ -204,7 +204,7 @@ var ValidateReplicationControllerName = NameIsDNSSubdomain
// ValidateServiceName can be used to check whether the given service name is valid.
// ValidateServiceName can be used to check whether the given service name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// Prefix indicates this name will be used as part of generation, in which case
// trailing dashes are allowed.
// trailing dashes are allowed.
var
ValidateServiceName
=
NameIsDNS
952
Label
var
ValidateServiceName
=
NameIsDNS
1035
Label
// ValidateNodeName can be used to check whether the given node name is valid.
// ValidateNodeName can be used to check whether the given node name is valid.
// Prefix indicates this name will be used as part of generation, in which case
// Prefix indicates this name will be used as part of generation, in which case
...
@@ -258,12 +258,12 @@ func NameIsDNSLabel(name string, prefix bool) []string {
...
@@ -258,12 +258,12 @@ func NameIsDNSLabel(name string, prefix bool) []string {
return
validation
.
IsDNS1123Label
(
name
)
return
validation
.
IsDNS1123Label
(
name
)
}
}
// NameIsDNS
952
Label is a ValidateNameFunc for names that must be a DNS 952 label.
// NameIsDNS
1035
Label is a ValidateNameFunc for names that must be a DNS 952 label.
func
NameIsDNS
952
Label
(
name
string
,
prefix
bool
)
[]
string
{
func
NameIsDNS
1035
Label
(
name
string
,
prefix
bool
)
[]
string
{
if
prefix
{
if
prefix
{
name
=
maskTrailingDash
(
name
)
name
=
maskTrailingDash
(
name
)
}
}
return
validation
.
IsDNS
952
Label
(
name
)
return
validation
.
IsDNS
1035
Label
(
name
)
}
}
// Validates that given value is not negative.
// Validates that given value is not negative.
...
...
pkg/api/validation/validation_test.go
View file @
b1e7e6cf
...
@@ -3449,7 +3449,7 @@ func TestValidateService(t *testing.T) {
...
@@ -3449,7 +3449,7 @@ func TestValidateService(t *testing.T) {
{
{
name
:
"too long name"
,
name
:
"too long name"
,
tweakSvc
:
func
(
s
*
api
.
Service
)
{
tweakSvc
:
func
(
s
*
api
.
Service
)
{
s
.
Name
=
strings
.
Repeat
(
"a"
,
25
)
s
.
Name
=
strings
.
Repeat
(
"a"
,
64
)
},
},
numErrs
:
1
,
numErrs
:
1
,
},
},
...
@@ -3463,7 +3463,7 @@ func TestValidateService(t *testing.T) {
...
@@ -3463,7 +3463,7 @@ func TestValidateService(t *testing.T) {
{
{
name
:
"too long generateName"
,
name
:
"too long generateName"
,
tweakSvc
:
func
(
s
*
api
.
Service
)
{
tweakSvc
:
func
(
s
*
api
.
Service
)
{
s
.
GenerateName
=
strings
.
Repeat
(
"a"
,
25
)
s
.
GenerateName
=
strings
.
Repeat
(
"a"
,
64
)
},
},
numErrs
:
1
,
numErrs
:
1
,
},
},
...
...
pkg/dns/dns.go
View file @
b1e7e6cf
...
@@ -665,7 +665,7 @@ func getSkyMsg(ip string, port int) (*skymsg.Service, string) {
...
@@ -665,7 +665,7 @@ func getSkyMsg(ip string, port int) (*skymsg.Service, string) {
// The conjunction of the following conditions forms the test for the federated service query
// The conjunction of the following conditions forms the test for the federated service query
// pattern:
// pattern:
// 1. `path` has exactly 4+len(domainPath) segments: mysvc.myns.myfederation.svc.domain.path.
// 1. `path` has exactly 4+len(domainPath) segments: mysvc.myns.myfederation.svc.domain.path.
// 2. Service name component must be a valid RFC
952
name.
// 2. Service name component must be a valid RFC
1035
name.
// 3. Namespace component must be a valid RFC 1123 name.
// 3. Namespace component must be a valid RFC 1123 name.
// 4. Federation component must also be a valid RFC 1123 name.
// 4. Federation component must also be a valid RFC 1123 name.
// 5. Fourth segment is exactly "svc"
// 5. Fourth segment is exactly "svc"
...
@@ -679,8 +679,8 @@ func (kd *KubeDNS) isFederationQuery(path []string) bool {
...
@@ -679,8 +679,8 @@ func (kd *KubeDNS) isFederationQuery(path []string) bool {
glog
.
V
(
2
)
.
Infof
(
"not a federation query: len(%q) != 4+len(%q)"
,
path
,
kd
.
domainPath
)
glog
.
V
(
2
)
.
Infof
(
"not a federation query: len(%q) != 4+len(%q)"
,
path
,
kd
.
domainPath
)
return
false
return
false
}
}
if
errs
:=
validation
.
IsDNS
952
Label
(
path
[
0
]);
len
(
errs
)
!=
0
{
if
errs
:=
validation
.
IsDNS
1035
Label
(
path
[
0
]);
len
(
errs
)
!=
0
{
glog
.
V
(
2
)
.
Infof
(
"not a federation query: %q is not an RFC
952
label: %q"
,
path
[
0
],
errs
)
glog
.
V
(
2
)
.
Infof
(
"not a federation query: %q is not an RFC
1035
label: %q"
,
path
[
0
],
errs
)
return
false
return
false
}
}
if
errs
:=
validation
.
IsDNS1123Label
(
path
[
1
]);
len
(
errs
)
!=
0
{
if
errs
:=
validation
.
IsDNS1123Label
(
path
[
1
]);
len
(
errs
)
!=
0
{
...
...
pkg/kubectl/cmd/expose.go
View file @
b1e7e6cf
...
@@ -170,8 +170,8 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
...
@@ -170,8 +170,8 @@ func RunExpose(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
params
:=
kubectl
.
MakeParams
(
cmd
,
names
)
params
:=
kubectl
.
MakeParams
(
cmd
,
names
)
name
:=
info
.
Name
name
:=
info
.
Name
if
len
(
name
)
>
validation
.
DNS
952
LabelMaxLength
{
if
len
(
name
)
>
validation
.
DNS
1035
LabelMaxLength
{
name
=
name
[
:
validation
.
DNS
952
LabelMaxLength
]
name
=
name
[
:
validation
.
DNS
1035
LabelMaxLength
]
}
}
params
[
"default-name"
]
=
name
params
[
"default-name"
]
=
name
...
...
pkg/kubectl/cmd/expose_test.go
View file @
b1e7e6cf
...
@@ -230,10 +230,10 @@ func TestRunExposeService(t *testing.T) {
...
@@ -230,10 +230,10 @@ func TestRunExposeService(t *testing.T) {
},
},
{
{
name
:
"truncate-name"
,
name
:
"truncate-name"
,
args
:
[]
string
{
"pod"
,
"a-name-that-is-toooo-big-for-a-service"
},
args
:
[]
string
{
"pod"
,
"a-name-that-is-toooo-big-for-a-service
-because-it-can-only-handle-63-characters
"
},
ns
:
"test"
,
ns
:
"test"
,
calls
:
map
[
string
]
string
{
calls
:
map
[
string
]
string
{
"GET"
:
"/namespaces/test/pods/a-name-that-is-toooo-big-for-a-service"
,
"GET"
:
"/namespaces/test/pods/a-name-that-is-toooo-big-for-a-service
-because-it-can-only-handle-63-characters
"
,
"POST"
:
"/namespaces/test/services"
,
"POST"
:
"/namespaces/test/services"
,
},
},
input
:
&
api
.
Pod
{
input
:
&
api
.
Pod
{
...
@@ -241,7 +241,7 @@ func TestRunExposeService(t *testing.T) {
...
@@ -241,7 +241,7 @@ func TestRunExposeService(t *testing.T) {
},
},
flags
:
map
[
string
]
string
{
"selector"
:
"svc=frompod"
,
"port"
:
"90"
,
"labels"
:
"svc=frompod"
,
"generator"
:
"service/v2"
},
flags
:
map
[
string
]
string
{
"selector"
:
"svc=frompod"
,
"port"
:
"90"
,
"labels"
:
"svc=frompod"
,
"generator"
:
"service/v2"
},
output
:
&
api
.
Service
{
output
:
&
api
.
Service
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"a-name-that-is-toooo-big"
,
Namespace
:
""
,
Labels
:
map
[
string
]
string
{
"svc"
:
"frompod"
}},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"a-name-that-is-toooo-big
-for-a-service-because-it-can-only-handle-63-characters
"
,
Namespace
:
""
,
Labels
:
map
[
string
]
string
{
"svc"
:
"frompod"
}},
Spec
:
api
.
ServiceSpec
{
Spec
:
api
.
ServiceSpec
{
Ports
:
[]
api
.
ServicePort
{
Ports
:
[]
api
.
ServicePort
{
{
{
...
@@ -253,7 +253,7 @@ func TestRunExposeService(t *testing.T) {
...
@@ -253,7 +253,7 @@ func TestRunExposeService(t *testing.T) {
Selector
:
map
[
string
]
string
{
"svc"
:
"frompod"
},
Selector
:
map
[
string
]
string
{
"svc"
:
"frompod"
},
},
},
},
},
expected
:
"service
\"
a-name-that-is-toooo-big
\"
exposed"
,
expected
:
"service
\"
a-name-that-is-toooo-big
-for-a-service-because-it-can-only-hand
\"
exposed"
,
status
:
200
,
status
:
200
,
},
},
{
{
...
...
pkg/util/validation/validation.go
View file @
b1e7e6cf
...
@@ -121,20 +121,20 @@ func IsDNS1123Subdomain(value string) []string {
...
@@ -121,20 +121,20 @@ func IsDNS1123Subdomain(value string) []string {
return
errs
return
errs
}
}
const
dns
952
LabelFmt
string
=
"[a-z]([-a-z0-9]*[a-z0-9])?"
const
dns
1035
LabelFmt
string
=
"[a-z]([-a-z0-9]*[a-z0-9])?"
const
DNS
952LabelMaxLength
int
=
24
const
DNS
1035LabelMaxLength
int
=
63
var
dns
952LabelRegexp
=
regexp
.
MustCompile
(
"^"
+
dns952
LabelFmt
+
"$"
)
var
dns
1035LabelRegexp
=
regexp
.
MustCompile
(
"^"
+
dns1035
LabelFmt
+
"$"
)
// IsDNS
952
Label tests for a string that conforms to the definition of a label in
// IsDNS
1035
Label tests for a string that conforms to the definition of a label in
// DNS (RFC
952
).
// DNS (RFC
1035
).
func
IsDNS
952
Label
(
value
string
)
[]
string
{
func
IsDNS
1035
Label
(
value
string
)
[]
string
{
var
errs
[]
string
var
errs
[]
string
if
len
(
value
)
>
DNS
952
LabelMaxLength
{
if
len
(
value
)
>
DNS
1035
LabelMaxLength
{
errs
=
append
(
errs
,
MaxLenError
(
DNS
952
LabelMaxLength
))
errs
=
append
(
errs
,
MaxLenError
(
DNS
1035
LabelMaxLength
))
}
}
if
!
dns
952
LabelRegexp
.
MatchString
(
value
)
{
if
!
dns
1035
LabelRegexp
.
MatchString
(
value
)
{
errs
=
append
(
errs
,
RegexError
(
dns
952
LabelFmt
,
"my-name"
,
"abc-123"
))
errs
=
append
(
errs
,
RegexError
(
dns
1035
LabelFmt
,
"my-name"
,
"abc-123"
))
}
}
return
errs
return
errs
}
}
...
...
pkg/util/validation/validation_test.go
View file @
b1e7e6cf
...
@@ -86,13 +86,13 @@ func TestIsDNS1123Subdomain(t *testing.T) {
...
@@ -86,13 +86,13 @@ func TestIsDNS1123Subdomain(t *testing.T) {
}
}
}
}
func
TestIsDNS
952
Label
(
t
*
testing
.
T
)
{
func
TestIsDNS
1035
Label
(
t
*
testing
.
T
)
{
goodValues
:=
[]
string
{
goodValues
:=
[]
string
{
"a"
,
"ab"
,
"abc"
,
"a1"
,
"a-1"
,
"a--1--2--b"
,
"a"
,
"ab"
,
"abc"
,
"a1"
,
"a-1"
,
"a--1--2--b"
,
strings
.
Repeat
(
"a"
,
24
),
strings
.
Repeat
(
"a"
,
63
),
}
}
for
_
,
val
:=
range
goodValues
{
for
_
,
val
:=
range
goodValues
{
if
msgs
:=
IsDNS
952
Label
(
val
);
len
(
msgs
)
!=
0
{
if
msgs
:=
IsDNS
1035
Label
(
val
);
len
(
msgs
)
!=
0
{
t
.
Errorf
(
"expected true for '%s': %v"
,
val
,
msgs
)
t
.
Errorf
(
"expected true for '%s': %v"
,
val
,
msgs
)
}
}
}
}
...
@@ -104,10 +104,10 @@ func TestIsDNS952Label(t *testing.T) {
...
@@ -104,10 +104,10 @@ func TestIsDNS952Label(t *testing.T) {
"_"
,
"a_"
,
"_a"
,
"a_b"
,
"1_"
,
"_1"
,
"1_2"
,
"_"
,
"a_"
,
"_a"
,
"a_b"
,
"1_"
,
"_1"
,
"1_2"
,
"."
,
"a."
,
".a"
,
"a.b"
,
"1."
,
".1"
,
"1.2"
,
"."
,
"a."
,
".a"
,
"a.b"
,
"1."
,
".1"
,
"1.2"
,
" "
,
"a "
,
" a"
,
"a b"
,
"1 "
,
" 1"
,
"1 2"
,
" "
,
"a "
,
" a"
,
"a b"
,
"1 "
,
" 1"
,
"1 2"
,
strings
.
Repeat
(
"a"
,
25
),
strings
.
Repeat
(
"a"
,
64
),
}
}
for
_
,
val
:=
range
badValues
{
for
_
,
val
:=
range
badValues
{
if
msgs
:=
IsDNS
952
Label
(
val
);
len
(
msgs
)
==
0
{
if
msgs
:=
IsDNS
1035
Label
(
val
);
len
(
msgs
)
==
0
{
t
.
Errorf
(
"expected false for '%s'"
,
val
)
t
.
Errorf
(
"expected false for '%s'"
,
val
)
}
}
}
}
...
...
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