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
286b24b5
Commit
286b24b5
authored
Mar 11, 2015
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5320 from erictune/no_bound_pods_2
Stop updating boundPods objects.
parents
7d53425b
e9b6c75b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
264 deletions
+5
-264
etcd.go
pkg/registry/pod/etcd/etcd.go
+5
-71
etcd_test.go
pkg/registry/pod/etcd/etcd_test.go
+0
-193
No files found.
pkg/registry/pod/etcd/etcd.go
View file @
286b24b5
...
@@ -31,8 +31,6 @@ import (
...
@@ -31,8 +31,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
"github.com/golang/glog"
)
)
// rest implements a RESTStorage for pods against etcd
// rest implements a RESTStorage for pods against etcd
...
@@ -64,7 +62,7 @@ func NewREST(h tools.EtcdHelper, factory pod.BoundPodFactory) (*REST, *BindingRE
...
@@ -64,7 +62,7 @@ func NewREST(h tools.EtcdHelper, factory pod.BoundPodFactory) (*REST, *BindingRE
}
}
statusStore
:=
*
store
statusStore
:=
*
store
bindings
:=
&
podLifecycle
{
h
}
bindings
:=
&
podLifecycle
{}
store
.
CreateStrategy
=
pod
.
Strategy
store
.
CreateStrategy
=
pod
.
Strategy
store
.
UpdateStrategy
=
pod
.
Strategy
store
.
UpdateStrategy
=
pod
.
Strategy
store
.
AfterUpdate
=
bindings
.
AfterUpdate
store
.
AfterUpdate
=
bindings
.
AfterUpdate
...
@@ -130,10 +128,6 @@ func (r *REST) ResourceLocation(ctx api.Context, name string) (string, error) {
...
@@ -130,10 +128,6 @@ func (r *REST) ResourceLocation(ctx api.Context, name string) (string, error) {
return
pod
.
ResourceLocation
(
r
,
ctx
,
name
)
return
pod
.
ResourceLocation
(
r
,
ctx
,
name
)
}
}
func
makeBoundPodsKey
(
machine
string
)
string
{
return
"/registry/nodes/"
+
machine
+
"/boundpods"
}
// BindingREST implements the REST endpoint for binding pods to nodes when etcd is in use.
// BindingREST implements the REST endpoint for binding pods to nodes when etcd is in use.
type
BindingREST
struct
{
type
BindingREST
struct
{
store
*
etcdgeneric
.
Etcd
store
*
etcdgeneric
.
Etcd
...
@@ -185,81 +179,21 @@ func (r *BindingREST) setPodHostTo(ctx api.Context, podID, oldMachine, machine s
...
@@ -185,81 +179,21 @@ func (r *BindingREST) setPodHostTo(ctx api.Context, podID, oldMachine, machine s
// assignPod assigns the given pod to the given machine.
// assignPod assigns the given pod to the given machine.
func
(
r
*
BindingREST
)
assignPod
(
ctx
api
.
Context
,
podID
string
,
machine
string
)
error
{
func
(
r
*
BindingREST
)
assignPod
(
ctx
api
.
Context
,
podID
string
,
machine
string
)
error
{
finalPod
,
err
:=
r
.
setPodHostTo
(
ctx
,
podID
,
""
,
machine
)
_
,
err
:=
r
.
setPodHostTo
(
ctx
,
podID
,
""
,
machine
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
boundPod
,
err
:=
r
.
factory
.
MakeBoundPod
(
machine
,
finalPod
)
if
err
!=
nil
{
return
err
}
contKey
:=
makeBoundPodsKey
(
machine
)
err
=
r
.
store
.
Helper
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
true
,
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
boundPodList
:=
in
.
(
*
api
.
BoundPods
)
boundPodList
.
Items
=
append
(
boundPodList
.
Items
,
*
boundPod
)
return
boundPodList
,
nil
})
if
err
!=
nil
{
// Put the pod's host back the way it was. This is a terrible hack, but
// can't really be helped, since there's not really a way to do atomic
// multi-object changes in etcd.
if
_
,
err2
:=
r
.
setPodHostTo
(
ctx
,
podID
,
machine
,
""
);
err2
!=
nil
{
glog
.
Errorf
(
"Stranding pod %v; couldn't clear host after previous error: %v"
,
podID
,
err2
)
}
}
return
err
return
err
}
}
type
podLifecycle
struct
{
type
podLifecycle
struct
{}
tools
.
EtcdHelper
}
func
(
h
*
podLifecycle
)
AfterUpdate
(
obj
runtime
.
Object
)
error
{
func
(
h
*
podLifecycle
)
AfterUpdate
(
obj
runtime
.
Object
)
error
{
pod
:=
obj
.
(
*
api
.
Pod
)
return
nil
if
len
(
pod
.
Status
.
Host
)
==
0
{
return
nil
}
containerKey
:=
makeBoundPodsKey
(
pod
.
Status
.
Host
)
return
h
.
AtomicUpdate
(
containerKey
,
&
api
.
BoundPods
{},
true
,
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
boundPods
:=
in
.
(
*
api
.
BoundPods
)
for
ix
:=
range
boundPods
.
Items
{
if
boundPods
.
Items
[
ix
]
.
Name
==
pod
.
Name
&&
boundPods
.
Items
[
ix
]
.
Namespace
==
pod
.
Namespace
{
boundPods
.
Items
[
ix
]
.
Spec
=
pod
.
Spec
return
boundPods
,
nil
}
}
// This really shouldn't happen
glog
.
Warningf
(
"Couldn't find: %s in %#v"
,
pod
.
Name
,
boundPods
)
return
boundPods
,
fmt
.
Errorf
(
"failed to update pod, couldn't find %s in %#v"
,
pod
.
Name
,
boundPods
)
})
}
}
func
(
h
*
podLifecycle
)
AfterDelete
(
obj
runtime
.
Object
)
error
{
func
(
h
*
podLifecycle
)
AfterDelete
(
obj
runtime
.
Object
)
error
{
pod
:=
obj
.
(
*
api
.
Pod
)
return
nil
if
len
(
pod
.
Status
.
Host
)
==
0
{
return
nil
}
containerKey
:=
makeBoundPodsKey
(
pod
.
Status
.
Host
)
return
h
.
AtomicUpdate
(
containerKey
,
&
api
.
BoundPods
{},
true
,
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
pods
:=
in
.
(
*
api
.
BoundPods
)
newPods
:=
make
([]
api
.
BoundPod
,
0
,
len
(
pods
.
Items
))
found
:=
false
for
_
,
boundPod
:=
range
pods
.
Items
{
if
boundPod
.
Name
!=
pod
.
Name
||
boundPod
.
Namespace
!=
pod
.
Namespace
{
newPods
=
append
(
newPods
,
boundPod
)
}
else
{
found
=
true
}
}
if
!
found
{
// This really shouldn't happen, it indicates something is broken, and likely
// there is a lost pod somewhere.
// However it is "deleted" so log it and move on
glog
.
Warningf
(
"Couldn't find: %s in %#v"
,
pod
.
Name
,
pods
)
}
pods
.
Items
=
newPods
return
pods
,
nil
})
}
}
// StatusREST implements the REST endpoint for changing the status of a pod.
// StatusREST implements the REST endpoint for changing the status of a pod.
...
...
pkg/registry/pod/etcd/etcd_test.go
View file @
286b24b5
This diff is collapsed.
Click to expand it.
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