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
5ac7f310
Commit
5ac7f310
authored
Dec 17, 2015
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18508 from mqliang/bindingValidation
Auto commit by PR queue bot
parents
1357525d
04763abb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
11 deletions
+24
-11
validation.go
pkg/api/validation/validation.go
+16
-0
etcd.go
pkg/registry/pod/etcd/etcd.go
+6
-9
etcd_test.go
pkg/registry/pod/etcd/etcd_test.go
+2
-2
No files found.
pkg/api/validation/validation.go
View file @
5ac7f310
...
@@ -1225,6 +1225,22 @@ func ValidatePodStatusUpdate(newPod, oldPod *api.Pod) field.ErrorList {
...
@@ -1225,6 +1225,22 @@ func ValidatePodStatusUpdate(newPod, oldPod *api.Pod) field.ErrorList {
return
allErrs
return
allErrs
}
}
// ValidatePodBinding tests if required fields in the pod binding are legal.
func
ValidatePodBinding
(
binding
*
api
.
Binding
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
if
len
(
binding
.
Target
.
Kind
)
!=
0
&&
binding
.
Target
.
Kind
!=
"Node"
{
// TODO: When validation becomes versioned, this gets more complicated.
allErrs
=
append
(
allErrs
,
field
.
NotSupported
(
field
.
NewPath
(
"target"
,
"kind"
),
binding
.
Target
.
Kind
,
[]
string
{
"Node"
,
"<empty>"
}))
}
if
len
(
binding
.
Target
.
Name
)
==
0
{
// TODO: When validation becomes versioned, this gets more complicated.
allErrs
=
append
(
allErrs
,
field
.
Required
(
field
.
NewPath
(
"target"
,
"name"
)))
}
return
allErrs
}
// ValidatePodTemplate tests if required fields in the pod template are set.
// ValidatePodTemplate tests if required fields in the pod template are set.
func
ValidatePodTemplate
(
pod
*
api
.
PodTemplate
)
field
.
ErrorList
{
func
ValidatePodTemplate
(
pod
*
api
.
PodTemplate
)
field
.
ErrorList
{
allErrs
:=
ValidateObjectMeta
(
&
pod
.
ObjectMeta
,
true
,
ValidatePodName
,
field
.
NewPath
(
"metadata"
))
allErrs
:=
ValidateObjectMeta
(
&
pod
.
ObjectMeta
,
true
,
ValidatePodName
,
field
.
NewPath
(
"metadata"
))
...
...
pkg/registry/pod/etcd/etcd.go
View file @
5ac7f310
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
etcderr
"k8s.io/kubernetes/pkg/api/errors/etcd"
etcderr
"k8s.io/kubernetes/pkg/api/errors/etcd"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/kubelet/client"
"k8s.io/kubernetes/pkg/kubelet/client"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/labels"
...
@@ -35,7 +36,6 @@ import (
...
@@ -35,7 +36,6 @@ import (
podrest
"k8s.io/kubernetes/pkg/registry/pod/rest"
podrest
"k8s.io/kubernetes/pkg/registry/pod/rest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/util/validation/field"
)
)
// PodStorage includes storage for pods and all sub resources
// PodStorage includes storage for pods and all sub resources
...
@@ -93,8 +93,8 @@ func NewStorage(
...
@@ -93,8 +93,8 @@ func NewStorage(
Storage
:
storageInterface
,
Storage
:
storageInterface
,
}
}
statusStore
:=
*
store
statusStore
:=
*
store
statusStore
.
UpdateStrategy
=
pod
.
StatusStrategy
statusStore
.
UpdateStrategy
=
pod
.
StatusStrategy
return
PodStorage
{
return
PodStorage
{
...
@@ -132,15 +132,12 @@ var _ = rest.Creater(&BindingREST{})
...
@@ -132,15 +132,12 @@ var _ = rest.Creater(&BindingREST{})
// Create ensures a pod is bound to a specific host.
// Create ensures a pod is bound to a specific host.
func
(
r
*
BindingREST
)
Create
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
out
runtime
.
Object
,
err
error
)
{
func
(
r
*
BindingREST
)
Create
(
ctx
api
.
Context
,
obj
runtime
.
Object
)
(
out
runtime
.
Object
,
err
error
)
{
binding
:=
obj
.
(
*
api
.
Binding
)
binding
:=
obj
.
(
*
api
.
Binding
)
// TODO: move me to a binding strategy
// TODO: move me to a binding strategy
if
len
(
binding
.
Target
.
Kind
)
!=
0
&&
binding
.
Target
.
Kind
!=
"Node"
{
if
errs
:=
validation
.
ValidatePodBinding
(
binding
);
len
(
errs
)
!=
0
{
// TODO: When validation becomes versioned, this gets more complicated.
return
nil
,
errs
.
ToAggregate
()
return
nil
,
errors
.
NewInvalid
(
"binding"
,
binding
.
Name
,
field
.
ErrorList
{
field
.
NotSupported
(
field
.
NewPath
(
"target"
,
"kind"
),
binding
.
Target
.
Kind
,
[]
string
{
"Node"
,
"<empty>"
})})
}
if
len
(
binding
.
Target
.
Name
)
==
0
{
// TODO: When validation becomes versioned, this gets more complicated.
return
nil
,
errors
.
NewInvalid
(
"binding"
,
binding
.
Name
,
field
.
ErrorList
{
field
.
Required
(
field
.
NewPath
(
"target"
,
"name"
))})
}
}
err
=
r
.
assignPod
(
ctx
,
binding
.
Name
,
binding
.
Target
.
Name
,
binding
.
Annotations
)
err
=
r
.
assignPod
(
ctx
,
binding
.
Name
,
binding
.
Target
.
Name
,
binding
.
Annotations
)
out
=
&
unversioned
.
Status
{
Status
:
unversioned
.
StatusSuccess
}
out
=
&
unversioned
.
Status
{
Status
:
unversioned
.
StatusSuccess
}
return
return
...
...
pkg/registry/pod/etcd/etcd_test.go
View file @
5ac7f310
...
@@ -482,14 +482,14 @@ func TestEtcdCreateBinding(t *testing.T) {
...
@@ -482,14 +482,14 @@ func TestEtcdCreateBinding(t *testing.T) {
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
},
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
},
Target
:
api
.
ObjectReference
{},
Target
:
api
.
ObjectReference
{},
},
},
errOK
:
func
(
err
error
)
bool
{
return
err
ors
.
IsInvalid
(
err
)
},
errOK
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
},
},
"badKind"
:
{
"badKind"
:
{
binding
:
api
.
Binding
{
binding
:
api
.
Binding
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
},
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
},
Target
:
api
.
ObjectReference
{
Name
:
"machine1"
,
Kind
:
"unknown"
},
Target
:
api
.
ObjectReference
{
Name
:
"machine1"
,
Kind
:
"unknown"
},
},
},
errOK
:
func
(
err
error
)
bool
{
return
err
ors
.
IsInvalid
(
err
)
},
errOK
:
func
(
err
error
)
bool
{
return
err
!=
nil
},
},
},
"emptyKind"
:
{
"emptyKind"
:
{
binding
:
api
.
Binding
{
binding
:
api
.
Binding
{
...
...
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