Skip to content

Commit

Permalink
PodUpdate only has the delta changes, not full snapshot of all desired
Browse files Browse the repository at this point in the history
BoundPods on a node. PR kubernetes#1865 has a wrong assumption, with which any
PodUpdate operation will cause rest of running containers without updates
are killed as an unexpected ones.

Fix kubernetes#2028
  • Loading branch information
dchen1107 committed Oct 30, 2014
1 parent ff9befe commit 445ec71
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,28 @@ func (kl *Kubelet) SyncPods(pods []api.BoundPod) error {
return err
}

func updateBoundPods(changed []api.BoundPod, current []api.BoundPod) []api.BoundPod {
updated := []api.BoundPod{}
m := map[string]*api.BoundPod{}
for i := range changed {
pod := &changed[i]
m[pod.UID] = pod
}

for i := range current {
pod := &current[i]
if m[pod.UID] != nil {
updated = append(updated, *m[pod.UID])
glog.V(4).Infof("pod with UID: %s has a new spec %+v", pod.UID, *m[pod.UID])
} else {
updated = append(updated, *pod)
glog.V(4).Infof("pod with UID: %s stay with the same spec %+v", pod.UID, *pod)
}
}

return updated
}

// filterHostPortConflicts removes pods that conflict on Port.HostPort values
func filterHostPortConflicts(pods []api.BoundPod) []api.BoundPod {
filtered := []api.BoundPod{}
Expand Down Expand Up @@ -782,10 +804,14 @@ func (kl *Kubelet) syncLoop(updates <-chan PodUpdate, handler SyncHandler) {
select {
case u := <-updates:
switch u.Op {
case SET, UPDATE:
glog.V(3).Infof("Containers changed")
case SET:
glog.V(3).Infof("SET: Containers changed")
kl.pods = u.Pods
kl.pods = filterHostPortConflicts(kl.pods)
case UPDATE:
glog.V(3).Infof("Update: Containers changed")
kl.pods = updateBoundPods(u.Pods, kl.pods)
kl.pods = filterHostPortConflicts(kl.pods)

default:
panic("syncLoop does not support incremental changes")
Expand Down

0 comments on commit 445ec71

Please sign in to comment.