mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Merge pull request #16851 from mesosphere/sttts-fix-listwatch-mock-deadlock
Auto commit by PR queue bot
This commit is contained in:
commit
919d2c1126
@ -184,7 +184,8 @@ func (lw *MockPodsListWatch) Pods() api.PodList {
|
|||||||
lw.lock.Lock()
|
lw.lock.Lock()
|
||||||
defer lw.lock.Unlock()
|
defer lw.lock.Unlock()
|
||||||
|
|
||||||
return lw.list
|
obj, _ := api.Scheme.DeepCopy(&lw.list)
|
||||||
|
return *(obj.(*api.PodList))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lw *MockPodsListWatch) Pod(name string) *api.Pod {
|
func (lw *MockPodsListWatch) Pod(name string) *api.Pod {
|
||||||
@ -200,44 +201,56 @@ func (lw *MockPodsListWatch) Pod(name string) *api.Pod {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (lw *MockPodsListWatch) Add(pod *api.Pod, notify bool) {
|
func (lw *MockPodsListWatch) Add(pod *api.Pod, notify bool) {
|
||||||
lw.lock.Lock()
|
func() {
|
||||||
defer lw.lock.Unlock()
|
lw.lock.Lock()
|
||||||
|
defer lw.lock.Unlock()
|
||||||
|
lw.list.Items = append(lw.list.Items, *pod)
|
||||||
|
}()
|
||||||
|
|
||||||
lw.list.Items = append(lw.list.Items, *pod)
|
|
||||||
if notify {
|
if notify {
|
||||||
lw.fakeWatcher.Add(pod)
|
lw.fakeWatcher.Add(pod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (lw *MockPodsListWatch) Modify(pod *api.Pod, notify bool) {
|
func (lw *MockPodsListWatch) Modify(pod *api.Pod, notify bool) {
|
||||||
lw.lock.Lock()
|
found := false
|
||||||
defer lw.lock.Unlock()
|
func() {
|
||||||
|
lw.lock.Lock()
|
||||||
|
defer lw.lock.Unlock()
|
||||||
|
|
||||||
for i, otherPod := range lw.list.Items {
|
for i, otherPod := range lw.list.Items {
|
||||||
if otherPod.Name == pod.Name {
|
if otherPod.Name == pod.Name {
|
||||||
lw.list.Items[i] = *pod
|
lw.list.Items[i] = *pod
|
||||||
if notify {
|
found = true
|
||||||
lw.fakeWatcher.Modify(pod)
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
log.Fatalf("Cannot find pod %v to modify in MockPodsListWatch", pod.Name)
|
||||||
|
}()
|
||||||
|
|
||||||
|
if notify && found {
|
||||||
|
lw.fakeWatcher.Modify(pod)
|
||||||
}
|
}
|
||||||
log.Fatalf("Cannot find pod %v to modify in MockPodsListWatch", pod.Name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lw *MockPodsListWatch) Delete(pod *api.Pod, notify bool) {
|
func (lw *MockPodsListWatch) Delete(pod *api.Pod, notify bool) {
|
||||||
lw.lock.Lock()
|
var notifyPod *api.Pod
|
||||||
defer lw.lock.Unlock()
|
func() {
|
||||||
|
lw.lock.Lock()
|
||||||
|
defer lw.lock.Unlock()
|
||||||
|
|
||||||
for i, otherPod := range lw.list.Items {
|
for i, otherPod := range lw.list.Items {
|
||||||
if otherPod.Name == pod.Name {
|
if otherPod.Name == pod.Name {
|
||||||
lw.list.Items = append(lw.list.Items[:i], lw.list.Items[i+1:]...)
|
lw.list.Items = append(lw.list.Items[:i], lw.list.Items[i+1:]...)
|
||||||
if notify {
|
notifyPod = &otherPod
|
||||||
lw.fakeWatcher.Delete(&otherPod)
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
log.Fatalf("Cannot find pod %v to delete in MockPodsListWatch", pod.Name)
|
||||||
|
}()
|
||||||
|
|
||||||
|
if notifyPod != nil && notify {
|
||||||
|
lw.fakeWatcher.Delete(notifyPod)
|
||||||
}
|
}
|
||||||
log.Fatalf("Cannot find pod %v to delete in MockPodsListWatch", pod.Name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a pod with a given index, requiring one port
|
// Create a pod with a given index, requiring one port
|
||||||
|
Loading…
Reference in New Issue
Block a user