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
b5fce502
Commit
b5fce502
authored
Nov 23, 2014
by
Deyuan Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gitrepo validation
parent
162e4983
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
validation.go
pkg/api/validation/validation.go
+16
-4
validation_test.go
pkg/api/validation/validation_test.go
+2
-1
No files found.
pkg/api/validation/validation.go
View file @
b5fce502
...
...
@@ -72,7 +72,11 @@ func validateSource(source *api.VolumeSource) errs.ValidationErrorList {
}
if
source
.
EmptyDir
!=
nil
{
numVolumes
++
//EmptyDirs have nothing to validate
// EmptyDirs have nothing to validate
}
if
source
.
GitRepo
!=
nil
{
numVolumes
++
allErrs
=
append
(
allErrs
,
validateGitRepo
(
source
.
GitRepo
)
...
)
}
if
source
.
GCEPersistentDisk
!=
nil
{
numVolumes
++
...
...
@@ -92,15 +96,21 @@ func validateHostDir(hostDir *api.HostDir) errs.ValidationErrorList {
return
allErrs
}
var
supportedPortProtocols
=
util
.
NewStringSet
(
string
(
api
.
ProtocolTCP
),
string
(
api
.
ProtocolUDP
))
func
validateGitRepo
(
gitRepo
*
api
.
GitRepo
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
if
gitRepo
.
Repository
==
""
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"gitRepo.Repository"
,
gitRepo
.
Repository
))
}
return
allErrs
}
func
validateGCEPersistentDisk
(
PD
*
api
.
GCEPersistentDisk
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
if
PD
.
PDName
==
""
{
allErrs
=
append
(
allErrs
,
errs
.
NewField
Invali
d
(
"PD.PDName"
,
PD
.
PDName
))
allErrs
=
append
(
allErrs
,
errs
.
NewField
Require
d
(
"PD.PDName"
,
PD
.
PDName
))
}
if
PD
.
FSType
==
""
{
allErrs
=
append
(
allErrs
,
errs
.
NewField
Invali
d
(
"PD.FSType"
,
PD
.
FSType
))
allErrs
=
append
(
allErrs
,
errs
.
NewField
Require
d
(
"PD.FSType"
,
PD
.
FSType
))
}
if
PD
.
Partition
<
0
||
PD
.
Partition
>
255
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"PD.Partition"
,
PD
.
Partition
))
...
...
@@ -108,6 +118,8 @@ func validateGCEPersistentDisk(PD *api.GCEPersistentDisk) errs.ValidationErrorLi
return
allErrs
}
var
supportedPortProtocols
=
util
.
NewStringSet
(
string
(
api
.
ProtocolTCP
),
string
(
api
.
ProtocolUDP
))
func
validatePorts
(
ports
[]
api
.
Port
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
...
...
pkg/api/validation/validation_test.go
View file @
b5fce502
...
...
@@ -42,12 +42,13 @@ func TestValidateVolumes(t *testing.T) {
{
Name
:
"abc-123"
,
Source
:
&
api
.
VolumeSource
{
HostDir
:
&
api
.
HostDir
{
"/mnt/path3"
}}},
{
Name
:
"empty"
,
Source
:
&
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDir
{}}},
{
Name
:
"gcepd"
,
Source
:
&
api
.
VolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDisk
{
"my-PD"
,
"ext4"
,
1
,
false
}}},
{
Name
:
"gitrepo"
,
Source
:
&
api
.
VolumeSource
{
GitRepo
:
&
api
.
GitRepo
{
"my-repo"
,
"hashstring"
}}},
}
names
,
errs
:=
validateVolumes
(
successCase
)
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
}
if
len
(
names
)
!=
5
||
!
names
.
HasAll
(
"abc"
,
"123"
,
"abc-123"
,
"empty"
,
"gcepd
"
)
{
if
len
(
names
)
!=
6
||
!
names
.
HasAll
(
"abc"
,
"123"
,
"abc-123"
,
"empty"
,
"gcepd"
,
"gitrepo
"
)
{
t
.
Errorf
(
"wrong names result: %v"
,
names
)
}
...
...
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