mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #2077 from dchen1107/cleanup
PodUpdate only has the delta changes, not full snapshot of all desired
This commit is contained in:
commit
69ad5c9bff
@ -755,6 +755,28 @@ func (kl *Kubelet) SyncPods(pods []api.BoundPod) error {
|
|||||||
return err
|
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 := ¤t[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
|
// filterHostPortConflicts removes pods that conflict on Port.HostPort values
|
||||||
func filterHostPortConflicts(pods []api.BoundPod) []api.BoundPod {
|
func filterHostPortConflicts(pods []api.BoundPod) []api.BoundPod {
|
||||||
filtered := []api.BoundPod{}
|
filtered := []api.BoundPod{}
|
||||||
@ -782,10 +804,14 @@ func (kl *Kubelet) syncLoop(updates <-chan PodUpdate, handler SyncHandler) {
|
|||||||
select {
|
select {
|
||||||
case u := <-updates:
|
case u := <-updates:
|
||||||
switch u.Op {
|
switch u.Op {
|
||||||
case SET, UPDATE:
|
case SET:
|
||||||
glog.V(3).Infof("Containers changed")
|
glog.V(3).Infof("SET: Containers changed")
|
||||||
kl.pods = u.Pods
|
kl.pods = u.Pods
|
||||||
kl.pods = filterHostPortConflicts(kl.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:
|
default:
|
||||||
panic("syncLoop does not support incremental changes")
|
panic("syncLoop does not support incremental changes")
|
||||||
|
Loading…
Reference in New Issue
Block a user