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
20eb3c49
Commit
20eb3c49
authored
Mar 03, 2015
by
James DeFelice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
resolves #4103
clarify resource conflict status, rebase to master remove ResourceConflict, replace usage with Conflict
parent
a8f01391
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
11 deletions
+64
-11
etcd.go
pkg/registry/pod/etcd/etcd.go
+18
-9
etcd_test.go
pkg/registry/pod/etcd/etcd_test.go
+46
-2
No files found.
pkg/registry/pod/etcd/etcd.go
View file @
20eb3c49
...
...
@@ -148,15 +148,15 @@ func (r *BindingREST) Create(ctx api.Context, obj runtime.Object) (out runtime.O
if
len
(
binding
.
Target
.
Name
)
==
0
{
return
nil
,
errors
.
NewInvalid
(
"binding"
,
binding
.
Name
,
errors
.
ValidationErrorList
{
errors
.
NewFieldRequired
(
"to.name"
,
binding
.
Target
.
Name
)})
}
err
=
r
.
assignPod
(
ctx
,
binding
.
Name
,
binding
.
Target
.
Name
)
err
=
etcderr
.
InterpretCreateError
(
err
,
"binding"
,
""
)
err
=
r
.
assignPod
(
ctx
,
binding
.
Name
,
binding
.
Target
.
Name
,
binding
.
Annotations
)
out
=
&
api
.
Status
{
Status
:
api
.
StatusSuccess
}
return
}
// setPodHostTo sets the given pod's host to 'machine' iff it was previously 'oldMachine'.
// setPodHostAndAnnotations sets the given pod's host to 'machine' iff it was previously 'oldMachine' and merges
// the provided annotations with those of the pod.
// Returns the current state of the pod, or an error.
func
(
r
*
BindingREST
)
setPodHost
To
(
ctx
api
.
Context
,
podID
,
oldMachine
,
machine
string
)
(
finalPod
*
api
.
Pod
,
err
error
)
{
func
(
r
*
BindingREST
)
setPodHost
AndAnnotations
(
ctx
api
.
Context
,
podID
,
oldMachine
,
machine
string
,
annotations
map
[
string
]
string
)
(
finalPod
*
api
.
Pod
,
err
error
)
{
podKey
,
err
:=
r
.
store
.
KeyFunc
(
ctx
,
podID
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -171,6 +171,12 @@ func (r *BindingREST) setPodHostTo(ctx api.Context, podID, oldMachine, machine s
}
pod
.
Spec
.
Host
=
machine
pod
.
Status
.
Host
=
machine
if
pod
.
Annotations
==
nil
{
pod
.
Annotations
=
make
(
map
[
string
]
string
)
}
for
k
,
v
:=
range
annotations
{
pod
.
Annotations
[
k
]
=
v
}
finalPod
=
pod
return
pod
,
nil
})
...
...
@@ -178,12 +184,15 @@ func (r *BindingREST) setPodHostTo(ctx api.Context, podID, oldMachine, machine s
}
// assignPod assigns the given pod to the given machine.
func
(
r
*
BindingREST
)
assignPod
(
ctx
api
.
Context
,
podID
string
,
machine
string
)
error
{
_
,
err
:=
r
.
setPodHostTo
(
ctx
,
podID
,
""
,
machine
)
if
err
!=
nil
{
return
err
func
(
r
*
BindingREST
)
assignPod
(
ctx
api
.
Context
,
podID
string
,
machine
string
,
annotations
map
[
string
]
string
)
(
err
error
)
{
if
_
,
err
=
r
.
setPodHostAndAnnotations
(
ctx
,
podID
,
""
,
machine
,
annotations
);
err
!=
nil
{
err
=
etcderr
.
InterpretGetError
(
err
,
"pod"
,
podID
)
err
=
etcderr
.
InterpretUpdateError
(
err
,
"pod"
,
podID
)
if
_
,
ok
:=
err
.
(
*
errors
.
StatusError
);
!
ok
{
err
=
errors
.
NewConflict
(
"binding"
,
podID
,
err
)
}
}
return
err
return
}
type
podLifecycle
struct
{}
...
...
pkg/registry/pod/etcd/etcd_test.go
View file @
20eb3c49
...
...
@@ -894,8 +894,12 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) {
// Suddenly, a wild scheduler appears:
_
,
err
=
bindingRegistry
.
Create
(
ctx
,
&
api
.
Binding
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
},
Target
:
api
.
ObjectReference
{
Name
:
"machine"
},
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
Annotations
:
map
[
string
]
string
{
"label1"
:
"value1"
},
},
Target
:
api
.
ObjectReference
{
Name
:
"machine"
},
})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
...
...
@@ -914,6 +918,46 @@ func TestEtcdCreateWithContainersNotFound(t *testing.T) {
if
pod
.
Name
!=
"foo"
{
t
.
Errorf
(
"Unexpected pod: %#v %s"
,
pod
,
resp
.
Node
.
Value
)
}
if
!
(
pod
.
Annotations
!=
nil
&&
pod
.
Annotations
[
"label1"
]
==
"value1"
)
{
t
.
Fatalf
(
"Pod annotations don't match the expected: %v"
,
pod
.
Annotations
)
}
}
func
TestEtcdCreateWithConflict
(
t
*
testing
.
T
)
{
registry
,
bindingRegistry
,
_
,
fakeClient
,
_
:=
newStorage
(
t
)
ctx
:=
api
.
NewDefaultContext
()
fakeClient
.
TestIndex
=
true
key
,
_
:=
registry
.
store
.
KeyFunc
(
ctx
,
"foo"
)
fakeClient
.
Data
[
key
]
=
tools
.
EtcdResponseWithError
{
R
:
&
etcd
.
Response
{
Node
:
nil
,
},
E
:
tools
.
EtcdErrorNotFound
,
}
_
,
err
:=
registry
.
Create
(
ctx
,
validNewPod
())
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
// Suddenly, a wild scheduler appears:
binding
:=
api
.
Binding
{
ObjectMeta
:
api
.
ObjectMeta
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"foo"
,
Annotations
:
map
[
string
]
string
{
"label1"
:
"value1"
},
},
Target
:
api
.
ObjectReference
{
Name
:
"machine"
},
}
_
,
err
=
bindingRegistry
.
Create
(
ctx
,
&
binding
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
_
,
err
=
bindingRegistry
.
Create
(
ctx
,
&
binding
)
if
err
==
nil
||
!
errors
.
IsConflict
(
err
)
{
t
.
Fatalf
(
"expected resource conflict error, not: %v"
,
err
)
}
}
func
TestEtcdCreateWithExistingContainers
(
t
*
testing
.
T
)
{
...
...
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