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
e82b88fe
Commit
e82b88fe
authored
Nov 24, 2014
by
Brendan Burns
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2560 from ddysher/fix-git-volume
gitrepo validation
parents
518115c9
b5fce502
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 @
e82b88fe
...
@@ -72,7 +72,11 @@ func validateSource(source *api.VolumeSource) errs.ValidationErrorList {
...
@@ -72,7 +72,11 @@ func validateSource(source *api.VolumeSource) errs.ValidationErrorList {
}
}
if
source
.
EmptyDir
!=
nil
{
if
source
.
EmptyDir
!=
nil
{
numVolumes
++
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
{
if
source
.
GCEPersistentDisk
!=
nil
{
numVolumes
++
numVolumes
++
...
@@ -92,15 +96,21 @@ func validateHostDir(hostDir *api.HostDir) errs.ValidationErrorList {
...
@@ -92,15 +96,21 @@ func validateHostDir(hostDir *api.HostDir) errs.ValidationErrorList {
return
allErrs
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
{
func
validateGCEPersistentDisk
(
PD
*
api
.
GCEPersistentDisk
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
:=
errs
.
ValidationErrorList
{}
if
PD
.
PDName
==
""
{
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
==
""
{
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
{
if
PD
.
Partition
<
0
||
PD
.
Partition
>
255
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"PD.Partition"
,
PD
.
Partition
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"PD.Partition"
,
PD
.
Partition
))
...
@@ -108,6 +118,8 @@ func validateGCEPersistentDisk(PD *api.GCEPersistentDisk) errs.ValidationErrorLi
...
@@ -108,6 +118,8 @@ func validateGCEPersistentDisk(PD *api.GCEPersistentDisk) errs.ValidationErrorLi
return
allErrs
return
allErrs
}
}
var
supportedPortProtocols
=
util
.
NewStringSet
(
string
(
api
.
ProtocolTCP
),
string
(
api
.
ProtocolUDP
))
func
validatePorts
(
ports
[]
api
.
Port
)
errs
.
ValidationErrorList
{
func
validatePorts
(
ports
[]
api
.
Port
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
:=
errs
.
ValidationErrorList
{}
...
...
pkg/api/validation/validation_test.go
View file @
e82b88fe
...
@@ -42,12 +42,13 @@ func TestValidateVolumes(t *testing.T) {
...
@@ -42,12 +42,13 @@ func TestValidateVolumes(t *testing.T) {
{
Name
:
"abc-123"
,
Source
:
&
api
.
VolumeSource
{
HostDir
:
&
api
.
HostDir
{
"/mnt/path3"
}}},
{
Name
:
"abc-123"
,
Source
:
&
api
.
VolumeSource
{
HostDir
:
&
api
.
HostDir
{
"/mnt/path3"
}}},
{
Name
:
"empty"
,
Source
:
&
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDir
{}}},
{
Name
:
"empty"
,
Source
:
&
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDir
{}}},
{
Name
:
"gcepd"
,
Source
:
&
api
.
VolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDisk
{
"my-PD"
,
"ext4"
,
1
,
false
}}},
{
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
)
names
,
errs
:=
validateVolumes
(
successCase
)
if
len
(
errs
)
!=
0
{
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"expected success: %v"
,
errs
)
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
)
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