mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
Correct backwards pod mappings
The mapping of static pod <--> mirror pod UIDs was backwards in a couple places. Fortunately, they canceled each other out. Fixed, and added a test case.
This commit is contained in:
parent
d42030170b
commit
d2532b50ce
@ -130,6 +130,9 @@ func (pm *basicManager) updatePodsInternal(pods ...*api.Pod) {
|
|||||||
} else {
|
} else {
|
||||||
pm.podByUID[pod.UID] = pod
|
pm.podByUID[pod.UID] = pod
|
||||||
pm.podByFullName[podFullName] = pod
|
pm.podByFullName[podFullName] = pod
|
||||||
|
if mirror, ok := pm.mirrorPodByFullName[podFullName]; ok {
|
||||||
|
pm.translationByUID[mirror.UID] = pod.UID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,8 +221,8 @@ func (pm *basicManager) GetUIDTranslations() (podToMirror, mirrorToPod map[types
|
|||||||
podToMirror = make(map[types.UID]types.UID, len(pm.translationByUID))
|
podToMirror = make(map[types.UID]types.UID, len(pm.translationByUID))
|
||||||
mirrorToPod = make(map[types.UID]types.UID, len(pm.translationByUID))
|
mirrorToPod = make(map[types.UID]types.UID, len(pm.translationByUID))
|
||||||
for k, v := range pm.translationByUID {
|
for k, v := range pm.translationByUID {
|
||||||
podToMirror[k] = v
|
mirrorToPod[k] = v
|
||||||
mirrorToPod[v] = k
|
podToMirror[v] = k
|
||||||
}
|
}
|
||||||
return podToMirror, mirrorToPod
|
return podToMirror, mirrorToPod
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ type manager struct {
|
|||||||
podStatuses map[types.UID]versionedPodStatus
|
podStatuses map[types.UID]versionedPodStatus
|
||||||
podStatusesLock sync.RWMutex
|
podStatusesLock sync.RWMutex
|
||||||
podStatusChannel chan podStatusSyncRequest
|
podStatusChannel chan podStatusSyncRequest
|
||||||
// Map from pod UID to latest status version successfully sent to the API server.
|
// Map from (mirror) pod UID to latest status version successfully sent to the API server.
|
||||||
// apiStatusVersions must only be accessed from the sync thread.
|
// apiStatusVersions must only be accessed from the sync thread.
|
||||||
apiStatusVersions map[types.UID]uint64
|
apiStatusVersions map[types.UID]uint64
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ func (m *manager) syncBatch() {
|
|||||||
// Clean up orphaned versions.
|
// Clean up orphaned versions.
|
||||||
for uid := range m.apiStatusVersions {
|
for uid := range m.apiStatusVersions {
|
||||||
_, hasPod := m.podStatuses[uid]
|
_, hasPod := m.podStatuses[uid]
|
||||||
_, hasMirror := podToMirror[uid]
|
_, hasMirror := mirrorToPod[uid]
|
||||||
if !hasPod && !hasMirror {
|
if !hasPod && !hasMirror {
|
||||||
delete(m.apiStatusVersions, uid)
|
delete(m.apiStatusVersions, uid)
|
||||||
}
|
}
|
||||||
@ -304,8 +304,8 @@ func (m *manager) syncBatch() {
|
|||||||
|
|
||||||
for uid, status := range m.podStatuses {
|
for uid, status := range m.podStatuses {
|
||||||
syncedUID := uid
|
syncedUID := uid
|
||||||
if translated, ok := mirrorToPod[uid]; ok {
|
if mirrorUID, ok := podToMirror[uid]; ok {
|
||||||
syncedUID = translated
|
syncedUID = mirrorUID
|
||||||
}
|
}
|
||||||
if m.needsUpdate(syncedUID, status) {
|
if m.needsUpdate(syncedUID, status) {
|
||||||
updatedStatuses = append(updatedStatuses, podStatusSyncRequest{uid, status})
|
updatedStatuses = append(updatedStatuses, podStatusSyncRequest{uid, status})
|
||||||
|
@ -538,3 +538,42 @@ func TestSetContainerReadiness(t *testing.T) {
|
|||||||
m.SetContainerReadiness(testPod, kubecontainer.ContainerID{"test", "foo"}, true)
|
m.SetContainerReadiness(testPod, kubecontainer.ContainerID{"test", "foo"}, true)
|
||||||
verifyUpdates(t, m, 0)
|
verifyUpdates(t, m, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSyncBatchCleanupVersions(t *testing.T) {
|
||||||
|
m := newTestManager(&testclient.Fake{})
|
||||||
|
mirrorPod := *testPod
|
||||||
|
mirrorPod.UID = "mirror-uid"
|
||||||
|
mirrorPod.Name = "mirror_pod"
|
||||||
|
mirrorPod.Annotations = map[string]string{
|
||||||
|
kubetypes.ConfigSourceAnnotationKey: "api",
|
||||||
|
kubetypes.ConfigMirrorAnnotationKey: "mirror",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Orphaned pods should be removed.
|
||||||
|
m.apiStatusVersions[testPod.UID] = 100
|
||||||
|
m.apiStatusVersions[mirrorPod.UID] = 200
|
||||||
|
m.syncBatch()
|
||||||
|
if _, ok := m.apiStatusVersions[testPod.UID]; ok {
|
||||||
|
t.Errorf("Should have cleared status for testPod")
|
||||||
|
}
|
||||||
|
if _, ok := m.apiStatusVersions[mirrorPod.UID]; ok {
|
||||||
|
t.Errorf("Should have cleared status for mirrorPod")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-orphaned pods should not be removed.
|
||||||
|
m.SetPodStatus(testPod, getRandomPodStatus())
|
||||||
|
m.podManager.AddPod(&mirrorPod)
|
||||||
|
staticPod := mirrorPod
|
||||||
|
staticPod.UID = "static-uid"
|
||||||
|
staticPod.Annotations = map[string]string{kubetypes.ConfigSourceAnnotationKey: "file"}
|
||||||
|
m.podManager.AddPod(&staticPod)
|
||||||
|
m.apiStatusVersions[testPod.UID] = 100
|
||||||
|
m.apiStatusVersions[mirrorPod.UID] = 200
|
||||||
|
m.syncBatch()
|
||||||
|
if _, ok := m.apiStatusVersions[testPod.UID]; !ok {
|
||||||
|
t.Errorf("Should not have cleared status for testPod")
|
||||||
|
}
|
||||||
|
if _, ok := m.apiStatusVersions[mirrorPod.UID]; !ok {
|
||||||
|
t.Errorf("Should not have cleared status for mirrorPod")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user