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
9bb8dd9c
Unverified
Commit
9bb8dd9c
authored
Aug 01, 2018
by
Tim Allclair
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix coordination.Lease validation
parent
d9493156
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
validation.go
pkg/apis/coordination/validation/validation.go
+4
-2
validation_test.go
pkg/apis/coordination/validation/validation_test.go
+21
-1
No files found.
pkg/apis/coordination/validation/validation.go
View file @
9bb8dd9c
...
@@ -24,14 +24,16 @@ import (
...
@@ -24,14 +24,16 @@ import (
// ValidateLease validates a Lease.
// ValidateLease validates a Lease.
func
ValidateLease
(
lease
*
coordination
.
Lease
)
field
.
ErrorList
{
func
ValidateLease
(
lease
*
coordination
.
Lease
)
field
.
ErrorList
{
allErrs
:=
validation
.
ValidateObjectMeta
(
&
lease
.
ObjectMeta
,
true
,
validation
.
NameIsDNSSubdomain
,
field
.
NewPath
(
"
objectMe
ta"
))
allErrs
:=
validation
.
ValidateObjectMeta
(
&
lease
.
ObjectMeta
,
true
,
validation
.
NameIsDNSSubdomain
,
field
.
NewPath
(
"
metada
ta"
))
allErrs
=
append
(
allErrs
,
ValidateLeaseSpec
(
&
lease
.
Spec
,
field
.
NewPath
(
"spec"
))
...
)
allErrs
=
append
(
allErrs
,
ValidateLeaseSpec
(
&
lease
.
Spec
,
field
.
NewPath
(
"spec"
))
...
)
return
allErrs
return
allErrs
}
}
// ValidateLeaseUpdate validates an update of Lease object.
// ValidateLeaseUpdate validates an update of Lease object.
func
ValidateLeaseUpdate
(
lease
,
oldLease
*
coordination
.
Lease
)
field
.
ErrorList
{
func
ValidateLeaseUpdate
(
lease
,
oldLease
*
coordination
.
Lease
)
field
.
ErrorList
{
return
ValidateLease
(
lease
)
allErrs
:=
validation
.
ValidateObjectMetaUpdate
(
&
lease
.
ObjectMeta
,
&
oldLease
.
ObjectMeta
,
field
.
NewPath
(
"metadata"
))
allErrs
=
append
(
allErrs
,
ValidateLeaseSpec
(
&
lease
.
Spec
,
field
.
NewPath
(
"spec"
))
...
)
return
allErrs
}
}
// ValidateLeaseSpec validates spec of Lease.
// ValidateLeaseSpec validates spec of Lease.
...
...
pkg/apis/coordination/validation/validation_test.go
View file @
9bb8dd9c
...
@@ -71,6 +71,10 @@ func TestValidateLeaseSpecUpdate(t *testing.T) {
...
@@ -71,6 +71,10 @@ func TestValidateLeaseSpecUpdate(t *testing.T) {
oldLeaseDuration
:=
int32
(
3
)
oldLeaseDuration
:=
int32
(
3
)
oldLeaseTransitions
:=
int32
(
3
)
oldLeaseTransitions
:=
int32
(
3
)
oldLease
:=
&
coordination
.
Lease
{
oldLease
:=
&
coordination
.
Lease
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"holder"
,
Namespace
:
"holder-namespace"
,
},
Spec
:
coordination
.
LeaseSpec
{
Spec
:
coordination
.
LeaseSpec
{
HolderIdentity
:
&
oldHolder
,
HolderIdentity
:
&
oldHolder
,
LeaseDurationSeconds
:
&
oldLeaseDuration
,
LeaseDurationSeconds
:
&
oldLeaseDuration
,
...
@@ -78,7 +82,23 @@ func TestValidateLeaseSpecUpdate(t *testing.T) {
...
@@ -78,7 +82,23 @@ func TestValidateLeaseSpecUpdate(t *testing.T) {
},
},
}
}
errs
:=
ValidateLeaseUpdate
(
lease
,
oldLease
)
errs
:=
ValidateLeaseUpdate
(
lease
,
oldLease
)
if
len
(
errs
)
!=
2
{
if
len
(
errs
)
!=
3
{
t
.
Errorf
(
"unexpected list of errors: %#v"
,
errs
.
ToAggregate
()
.
Error
())
t
.
Errorf
(
"unexpected list of errors: %#v"
,
errs
.
ToAggregate
()
.
Error
())
}
}
validLeaseDuration
:=
int32
(
10
)
validLeaseTransitions
:=
int32
(
20
)
validLease
:=
&
coordination
.
Lease
{
ObjectMeta
:
oldLease
.
ObjectMeta
,
Spec
:
coordination
.
LeaseSpec
{
HolderIdentity
:
&
holder
,
LeaseDurationSeconds
:
&
validLeaseDuration
,
LeaseTransitions
:
&
validLeaseTransitions
,
},
}
validLease
.
ObjectMeta
.
ResourceVersion
=
"2"
errs
=
ValidateLeaseUpdate
(
validLease
,
oldLease
)
if
len
(
errs
)
!=
0
{
t
.
Errorf
(
"unexpected list of errors for valid update: %#v"
,
errs
.
ToAggregate
()
.
Error
())
}
}
}
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