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
3168f165
Commit
3168f165
authored
Mar 02, 2015
by
Brendan Burns
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4927 from thockin/plural_22_endpoints
Add defaults for HTTGetAction.Path & test actions
parents
9f7b78b0
532c39c3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
0 deletions
+71
-0
fuzzer.go
pkg/api/testing/fuzzer.go
+5
-0
defaults.go
pkg/api/v1beta1/defaults.go
+5
-0
defaults.go
pkg/api/v1beta2/defaults.go
+5
-0
defaults.go
pkg/api/v1beta3/defaults.go
+5
-0
validation.go
pkg/api/validation/validation.go
+24
-0
validation_test.go
pkg/api/validation/validation_test.go
+27
-0
No files found.
pkg/api/testing/fuzzer.go
View file @
3168f165
...
...
@@ -240,6 +240,11 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
ep
.
IP
=
fmt
.
Sprintf
(
"%d.%d.%d.%d"
,
c
.
Rand
.
Intn
(
256
),
c
.
Rand
.
Intn
(
256
),
c
.
Rand
.
Intn
(
256
),
c
.
Rand
.
Intn
(
256
))
ep
.
Port
=
c
.
Rand
.
Intn
(
65536
)
},
func
(
http
*
api
.
HTTPGetAction
,
c
fuzz
.
Continue
)
{
http
.
Path
=
"/"
+
c
.
RandString
()
// can't be blank
c
.
Fuzz
(
&
http
.
Port
)
c
.
Fuzz
(
&
http
.
Host
)
},
)
return
f
}
pkg/api/v1beta1/defaults.go
View file @
3168f165
...
...
@@ -90,5 +90,10 @@ func init() {
obj
.
Protocol
=
"TCP"
}
},
func
(
obj
*
HTTPGetAction
)
{
if
obj
.
Path
==
""
{
obj
.
Path
=
"/"
}
},
)
}
pkg/api/v1beta2/defaults.go
View file @
3168f165
...
...
@@ -92,5 +92,10 @@ func init() {
obj
.
Protocol
=
"TCP"
}
},
func
(
obj
*
HTTPGetAction
)
{
if
obj
.
Path
==
""
{
obj
.
Path
=
"/"
}
},
)
}
pkg/api/v1beta3/defaults.go
View file @
3168f165
...
...
@@ -85,5 +85,10 @@ func init() {
obj
.
Protocol
=
"TCP"
}
},
func
(
obj
*
HTTPGetAction
)
{
if
obj
.
Path
==
""
{
obj
.
Path
=
"/"
}
},
)
}
pkg/api/validation/validation.go
View file @
3168f165
...
...
@@ -451,6 +451,21 @@ func validateHTTPGetAction(http *api.HTTPGetAction) errs.ValidationErrorList {
if
len
(
http
.
Path
)
==
0
{
allErrors
=
append
(
allErrors
,
errs
.
NewFieldRequired
(
"path"
,
http
.
Path
))
}
if
http
.
Port
.
Kind
==
util
.
IntstrInt
&&
!
util
.
IsValidPortNum
(
http
.
Port
.
IntVal
)
{
allErrors
=
append
(
allErrors
,
errs
.
NewFieldInvalid
(
"port"
,
http
.
Port
,
portRangeErrorMsg
))
}
else
if
http
.
Port
.
Kind
==
util
.
IntstrString
&&
len
(
http
.
Port
.
StrVal
)
==
0
{
allErrors
=
append
(
allErrors
,
errs
.
NewFieldRequired
(
"port"
,
http
.
Port
.
StrVal
))
}
return
allErrors
}
func
validateTCPSocketAction
(
tcp
*
api
.
TCPSocketAction
)
errs
.
ValidationErrorList
{
allErrors
:=
errs
.
ValidationErrorList
{}
if
tcp
.
Port
.
Kind
==
util
.
IntstrInt
&&
!
util
.
IsValidPortNum
(
tcp
.
Port
.
IntVal
)
{
allErrors
=
append
(
allErrors
,
errs
.
NewFieldInvalid
(
"port"
,
tcp
.
Port
,
portRangeErrorMsg
))
}
else
if
tcp
.
Port
.
Kind
==
util
.
IntstrString
&&
len
(
tcp
.
Port
.
StrVal
)
==
0
{
allErrors
=
append
(
allErrors
,
errs
.
NewFieldRequired
(
"port"
,
tcp
.
Port
.
StrVal
))
}
return
allErrors
}
...
...
@@ -465,6 +480,10 @@ func validateHandler(handler *api.Handler) errs.ValidationErrorList {
numHandlers
++
allErrors
=
append
(
allErrors
,
validateHTTPGetAction
(
handler
.
HTTPGet
)
.
Prefix
(
"httpGet"
)
...
)
}
if
handler
.
TCPSocket
!=
nil
{
numHandlers
++
allErrors
=
append
(
allErrors
,
validateTCPSocketAction
(
handler
.
TCPSocket
)
.
Prefix
(
"tcpSocket"
)
...
)
}
if
numHandlers
!=
1
{
allErrors
=
append
(
allErrors
,
errs
.
NewFieldInvalid
(
""
,
handler
,
"exactly 1 handler type is required"
))
}
...
...
@@ -662,6 +681,11 @@ func ValidateService(service *api.Service) errs.ValidationErrorList {
}
else
if
!
supportedPortProtocols
.
Has
(
strings
.
ToUpper
(
string
(
service
.
Spec
.
Protocol
)))
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldNotSupported
(
"spec.protocol"
,
service
.
Spec
.
Protocol
))
}
if
service
.
Spec
.
ContainerPort
.
Kind
==
util
.
IntstrInt
&&
service
.
Spec
.
ContainerPort
.
IntVal
!=
0
&&
!
util
.
IsValidPortNum
(
service
.
Spec
.
ContainerPort
.
IntVal
)
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"spec.containerPort"
,
service
.
Spec
.
Port
,
portRangeErrorMsg
))
}
else
if
service
.
Spec
.
ContainerPort
.
Kind
==
util
.
IntstrString
&&
len
(
service
.
Spec
.
ContainerPort
.
StrVal
)
==
0
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"spec.containerPort"
,
service
.
Spec
.
ContainerPort
.
StrVal
))
}
if
service
.
Spec
.
Selector
!=
nil
{
allErrs
=
append
(
allErrs
,
ValidateLabels
(
service
.
Spec
.
Selector
,
"spec.selector"
)
...
)
...
...
pkg/api/validation/validation_test.go
View file @
3168f165
...
...
@@ -331,6 +331,33 @@ func TestValidateProbe(t *testing.T) {
}
}
func
TestValidateHandler
(
t
*
testing
.
T
)
{
successCases
:=
[]
api
.
Handler
{
{
Exec
:
&
api
.
ExecAction
{
Command
:
[]
string
{
"echo"
}}},
{
HTTPGet
:
&
api
.
HTTPGetAction
{
Path
:
"/"
,
Port
:
util
.
NewIntOrStringFromInt
(
1
),
Host
:
""
}},
{
HTTPGet
:
&
api
.
HTTPGetAction
{
Path
:
"/foo"
,
Port
:
util
.
NewIntOrStringFromInt
(
65535
),
Host
:
"host"
}},
{
HTTPGet
:
&
api
.
HTTPGetAction
{
Path
:
"/"
,
Port
:
util
.
NewIntOrStringFromString
(
"port"
),
Host
:
""
}},
}
for
_
,
h
:=
range
successCases
{
if
errs
:=
validateHandler
(
&
h
);
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
}
}
errorCases
:=
[]
api
.
Handler
{
{},
{
Exec
:
&
api
.
ExecAction
{
Command
:
[]
string
{}}},
{
HTTPGet
:
&
api
.
HTTPGetAction
{
Path
:
""
,
Port
:
util
.
NewIntOrStringFromInt
(
0
),
Host
:
""
}},
{
HTTPGet
:
&
api
.
HTTPGetAction
{
Path
:
"/foo"
,
Port
:
util
.
NewIntOrStringFromInt
(
65536
),
Host
:
"host"
}},
{
HTTPGet
:
&
api
.
HTTPGetAction
{
Path
:
""
,
Port
:
util
.
NewIntOrStringFromString
(
""
),
Host
:
""
}},
}
for
_
,
h
:=
range
errorCases
{
if
errs
:=
validateHandler
(
&
h
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure for %#v"
,
h
)
}
}
}
func
TestValidatePullPolicy
(
t
*
testing
.
T
)
{
type
T
struct
{
Container
api
.
Container
...
...
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