mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #8000 from bprashanth/rc_ttl_cleanup
Delete expectations of a deleted rc instead of letting them expire
This commit is contained in:
commit
ddbf851b6e
@ -63,6 +63,7 @@ var expKeyFunc = func(obj interface{}) (string, error) {
|
|||||||
type RCExpectationsManager interface {
|
type RCExpectationsManager interface {
|
||||||
GetExpectations(rc *api.ReplicationController) (*PodExpectations, bool, error)
|
GetExpectations(rc *api.ReplicationController) (*PodExpectations, bool, error)
|
||||||
SatisfiedExpectations(rc *api.ReplicationController) bool
|
SatisfiedExpectations(rc *api.ReplicationController) bool
|
||||||
|
DeleteExpectations(rcKey string)
|
||||||
ExpectCreations(rc *api.ReplicationController, adds int) error
|
ExpectCreations(rc *api.ReplicationController, adds int) error
|
||||||
ExpectDeletions(rc *api.ReplicationController, dels int) error
|
ExpectDeletions(rc *api.ReplicationController, dels int) error
|
||||||
CreationObserved(rc *api.ReplicationController)
|
CreationObserved(rc *api.ReplicationController)
|
||||||
@ -87,6 +88,15 @@ func (r *RCExpectations) GetExpectations(rc *api.ReplicationController) (*PodExp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteExpectations deletes the expectations of the given RC from the TTLStore.
|
||||||
|
func (r *RCExpectations) DeleteExpectations(rcKey string) {
|
||||||
|
if podExp, exists, err := r.GetByKey(rcKey); err == nil && exists {
|
||||||
|
if err := r.Delete(podExp); err != nil {
|
||||||
|
glog.V(2).Infof("Error deleting expectations for rc %v: %v", rcKey, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SatisfiedExpectations returns true if the replication manager has observed the required adds/dels
|
// SatisfiedExpectations returns true if the replication manager has observed the required adds/dels
|
||||||
// for the given rc. Add/del counts are established by the rc at sync time, and updated as pods
|
// for the given rc. Add/del counts are established by the rc at sync time, and updated as pods
|
||||||
// are observed by the replication manager's podController.
|
// are observed by the replication manager's podController.
|
||||||
|
@ -354,6 +354,7 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
|
|||||||
obj, exists, err := rm.controllerStore.Store.GetByKey(key)
|
obj, exists, err := rm.controllerStore.Store.GetByKey(key)
|
||||||
if !exists {
|
if !exists {
|
||||||
glog.Infof("Replication Controller has been deleted %v", key)
|
glog.Infof("Replication Controller has been deleted %v", key)
|
||||||
|
rm.expectations.DeleteExpectations(key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -990,3 +990,38 @@ func TestRCSyncExpectations(t *testing.T) {
|
|||||||
manager.syncReplicationController(getKey(controllerSpec, t))
|
manager.syncReplicationController(getKey(controllerSpec, t))
|
||||||
validateSyncReplication(t, &fakePodControl, 0, 0)
|
validateSyncReplication(t, &fakePodControl, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDeleteControllerAndExpectations(t *testing.T) {
|
||||||
|
client := client.NewOrDie(&client.Config{Host: "", Version: testapi.Version()})
|
||||||
|
manager := NewReplicationManager(client, 10)
|
||||||
|
|
||||||
|
rc := newReplicationController(1)
|
||||||
|
manager.controllerStore.Store.Add(rc)
|
||||||
|
|
||||||
|
fakePodControl := FakePodControl{}
|
||||||
|
manager.podControl = &fakePodControl
|
||||||
|
|
||||||
|
// This should set expectations for the rc
|
||||||
|
manager.syncReplicationController(getKey(rc, t))
|
||||||
|
validateSyncReplication(t, &fakePodControl, 1, 0)
|
||||||
|
fakePodControl.clear()
|
||||||
|
|
||||||
|
// This is to simulate a concurrent addPod, that has a handle on the expectations
|
||||||
|
// as the controller deletes it.
|
||||||
|
podExp, exists, err := manager.expectations.GetExpectations(rc)
|
||||||
|
if !exists || err != nil {
|
||||||
|
t.Errorf("No expectations found for rc")
|
||||||
|
}
|
||||||
|
manager.controllerStore.Delete(rc)
|
||||||
|
manager.syncReplicationController(getKey(rc, t))
|
||||||
|
|
||||||
|
if _, exists, err = manager.expectations.GetExpectations(rc); exists {
|
||||||
|
t.Errorf("Found expectaions, expected none since the rc has been deleted.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// This should have no effect, since we've deleted the rc.
|
||||||
|
podExp.Seen(1, 0)
|
||||||
|
manager.podStore.Store.Replace(make([]interface{}, 0))
|
||||||
|
manager.syncReplicationController(getKey(rc, t))
|
||||||
|
validateSyncReplication(t, &fakePodControl, 0, 0)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user