mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 13:45:06 +00:00
Clear pod cache on delete.
This commit is contained in:
@@ -79,6 +79,13 @@ func (p *PodCache) GetPodStatus(namespace, name string) (*api.PodStatus, error)
|
||||
return &value, nil
|
||||
}
|
||||
|
||||
func (p *PodCache) ClearPodStatus(namespace, name string) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
delete(p.podStatus, objKey{namespace, name})
|
||||
}
|
||||
|
||||
func (p *PodCache) getNodeStatusInCache(name string) (*api.NodeStatus, bool) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
@@ -125,6 +125,36 @@ func TestPodCacheGet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPodCacheDelete(t *testing.T) {
|
||||
cache := NewPodCache(nil, nil, nil, nil)
|
||||
|
||||
expected := api.PodStatus{
|
||||
Info: api.PodInfo{
|
||||
"foo": api.ContainerStatus{},
|
||||
},
|
||||
}
|
||||
cache.podStatus[objKey{api.NamespaceDefault, "foo"}] = expected
|
||||
|
||||
info, err := cache.GetPodStatus(api.NamespaceDefault, "foo")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %+v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(info, &expected) {
|
||||
t.Errorf("Unexpected mismatch. Expected: %+v, Got: %+v", &expected, info)
|
||||
}
|
||||
|
||||
cache.ClearPodStatus(api.NamespaceDefault, "foo")
|
||||
|
||||
_, err = cache.GetPodStatus(api.NamespaceDefault, "foo")
|
||||
if err == nil {
|
||||
t.Errorf("Unexpected non-error after deleting")
|
||||
}
|
||||
if err != client.ErrPodInfoNotAvailable {
|
||||
t.Errorf("Unexpected error: %v, expecting: %v", err, client.ErrPodInfoNotAvailable)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestPodCacheGetMissing(t *testing.T) {
|
||||
cache := NewPodCache(nil, nil, nil, nil)
|
||||
|
||||
|
Reference in New Issue
Block a user