Commit e10f1227 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #33092 from m1093782566/m109-fix-rs-hostloop

Automatic merge from submit-queue fix replica set hot loop <!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, read our contributor guidelines https://github.com/kubernetes/kubernetes/blob/master/CONTRIBUTING.md and developer guide https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md 2. If you want *faster* PR reviews, read how: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/faster_reviews.md 3. Follow the instructions for writing a release note: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/pull-requests.md#release-notes --> **What this PR does / why we need it**: Fix replicas set hot loop. Related issue: #30629
parents aed78e92 a76a743e
...@@ -34,6 +34,7 @@ import ( ...@@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/client/cache" "k8s.io/kubernetes/pkg/client/cache"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
fakeclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/client/restclient" "k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/testing/core" "k8s.io/kubernetes/pkg/client/testing/core"
"k8s.io/kubernetes/pkg/controller" "k8s.io/kubernetes/pkg/controller"
...@@ -640,22 +641,10 @@ func TestControllerUpdateRequeue(t *testing.T) { ...@@ -640,22 +641,10 @@ func TestControllerUpdateRequeue(t *testing.T) {
fakePodControl := controller.FakePodControl{} fakePodControl := controller.FakePodControl{}
manager.podControl = &fakePodControl manager.podControl = &fakePodControl
manager.syncReplicaSet(getKey(rs, t)) // an error from the sync function will be requeued, check to make sure we returned an error
err := manager.syncReplicaSet(getKey(rs, t))
ch := make(chan interface{}) if err == nil {
go func() { t.Errorf("missing error for requeue")
item, _ := manager.queue.Get()
ch <- item
}()
select {
case key := <-ch:
expectedKey := getKey(rs, t)
if key != expectedKey {
t.Errorf("Expected requeue of replica set with key %s got %s", expectedKey, key)
}
case <-time.After(wait.ForeverTestTimeout):
manager.queue.ShutDown()
t.Errorf("Expected to find a ReplicaSet in the queue, found none.")
} }
// 1 Update and 1 GET, both of which fail // 1 Update and 1 GET, both of which fail
fakeHandler.ValidateRequestCount(t, 2) fakeHandler.ValidateRequestCount(t, 2)
...@@ -1088,8 +1077,8 @@ func TestDeletionTimestamp(t *testing.T) { ...@@ -1088,8 +1077,8 @@ func TestDeletionTimestamp(t *testing.T) {
// setupManagerWithGCEnabled creates a RS manager with a fakePodControl // setupManagerWithGCEnabled creates a RS manager with a fakePodControl
// and with garbageCollectorEnabled set to true // and with garbageCollectorEnabled set to true
func setupManagerWithGCEnabled() (manager *ReplicaSetController, fakePodControl *controller.FakePodControl) { func setupManagerWithGCEnabled(objs ...runtime.Object) (manager *ReplicaSetController, fakePodControl *controller.FakePodControl) {
c := clientset.NewForConfigOrDie(&restclient.Config{Host: "", ContentConfig: restclient.ContentConfig{GroupVersion: &registered.GroupOrDie(api.GroupName).GroupVersion}}) c := fakeclientset.NewSimpleClientset(objs...)
fakePodControl = &controller.FakePodControl{} fakePodControl = &controller.FakePodControl{}
manager = NewReplicaSetControllerFromClient(c, controller.NoResyncPeriodFunc, BurstReplicas, 0) manager = NewReplicaSetControllerFromClient(c, controller.NoResyncPeriodFunc, BurstReplicas, 0)
manager.garbageCollectorEnabled = true manager.garbageCollectorEnabled = true
...@@ -1099,9 +1088,9 @@ func setupManagerWithGCEnabled() (manager *ReplicaSetController, fakePodControl ...@@ -1099,9 +1088,9 @@ func setupManagerWithGCEnabled() (manager *ReplicaSetController, fakePodControl
} }
func TestDoNotPatchPodWithOtherControlRef(t *testing.T) { func TestDoNotPatchPodWithOtherControlRef(t *testing.T) {
manager, fakePodControl := setupManagerWithGCEnabled()
labelMap := map[string]string{"foo": "bar"} labelMap := map[string]string{"foo": "bar"}
rs := newReplicaSet(2, labelMap) rs := newReplicaSet(2, labelMap)
manager, fakePodControl := setupManagerWithGCEnabled(rs)
manager.rsStore.Indexer.Add(rs) manager.rsStore.Indexer.Add(rs)
var trueVar = true var trueVar = true
otherControllerReference := api.OwnerReference{UID: uuid.NewUUID(), APIVersion: "v1beta1", Kind: "ReplicaSet", Name: "AnotherRS", Controller: &trueVar} otherControllerReference := api.OwnerReference{UID: uuid.NewUUID(), APIVersion: "v1beta1", Kind: "ReplicaSet", Name: "AnotherRS", Controller: &trueVar}
...@@ -1118,9 +1107,9 @@ func TestDoNotPatchPodWithOtherControlRef(t *testing.T) { ...@@ -1118,9 +1107,9 @@ func TestDoNotPatchPodWithOtherControlRef(t *testing.T) {
} }
func TestPatchPodWithOtherOwnerRef(t *testing.T) { func TestPatchPodWithOtherOwnerRef(t *testing.T) {
manager, fakePodControl := setupManagerWithGCEnabled()
labelMap := map[string]string{"foo": "bar"} labelMap := map[string]string{"foo": "bar"}
rs := newReplicaSet(2, labelMap) rs := newReplicaSet(2, labelMap)
manager, fakePodControl := setupManagerWithGCEnabled(rs)
manager.rsStore.Indexer.Add(rs) manager.rsStore.Indexer.Add(rs)
// add to podStore one more matching pod that doesn't have a controller // add to podStore one more matching pod that doesn't have a controller
// ref, but has an owner ref pointing to other object. Expect a patch to // ref, but has an owner ref pointing to other object. Expect a patch to
...@@ -1139,9 +1128,9 @@ func TestPatchPodWithOtherOwnerRef(t *testing.T) { ...@@ -1139,9 +1128,9 @@ func TestPatchPodWithOtherOwnerRef(t *testing.T) {
} }
func TestPatchPodWithCorrectOwnerRef(t *testing.T) { func TestPatchPodWithCorrectOwnerRef(t *testing.T) {
manager, fakePodControl := setupManagerWithGCEnabled()
labelMap := map[string]string{"foo": "bar"} labelMap := map[string]string{"foo": "bar"}
rs := newReplicaSet(2, labelMap) rs := newReplicaSet(2, labelMap)
manager, fakePodControl := setupManagerWithGCEnabled(rs)
manager.rsStore.Indexer.Add(rs) manager.rsStore.Indexer.Add(rs)
// add to podStore a matching pod that has an ownerRef pointing to the rs, // add to podStore a matching pod that has an ownerRef pointing to the rs,
// but ownerRef.Controller is false. Expect a patch to take control it. // but ownerRef.Controller is false. Expect a patch to take control it.
...@@ -1159,9 +1148,9 @@ func TestPatchPodWithCorrectOwnerRef(t *testing.T) { ...@@ -1159,9 +1148,9 @@ func TestPatchPodWithCorrectOwnerRef(t *testing.T) {
} }
func TestPatchPodFails(t *testing.T) { func TestPatchPodFails(t *testing.T) {
manager, fakePodControl := setupManagerWithGCEnabled()
labelMap := map[string]string{"foo": "bar"} labelMap := map[string]string{"foo": "bar"}
rs := newReplicaSet(2, labelMap) rs := newReplicaSet(2, labelMap)
manager, fakePodControl := setupManagerWithGCEnabled(rs)
manager.rsStore.Indexer.Add(rs) manager.rsStore.Indexer.Add(rs)
// add to podStore two matching pods. Expect two patches to take control // add to podStore two matching pods. Expect two patches to take control
// them. // them.
...@@ -1171,17 +1160,17 @@ func TestPatchPodFails(t *testing.T) { ...@@ -1171,17 +1160,17 @@ func TestPatchPodFails(t *testing.T) {
// control of the pods and create new ones. // control of the pods and create new ones.
fakePodControl.Err = fmt.Errorf("Fake Error") fakePodControl.Err = fmt.Errorf("Fake Error")
err := manager.syncReplicaSet(getKey(rs, t)) err := manager.syncReplicaSet(getKey(rs, t))
if err != nil { if err == nil || err.Error() != "Fake Error" {
t.Fatal(err) t.Errorf("expected Fake Error, got %+v", err)
} }
// 2 patches to take control of pod1 and pod2 (both fail), 2 creates. // 2 patches to take control of pod1 and pod2 (both fail), 2 creates.
validateSyncReplicaSet(t, fakePodControl, 2, 0, 2) validateSyncReplicaSet(t, fakePodControl, 2, 0, 2)
} }
func TestPatchExtraPodsThenDelete(t *testing.T) { func TestPatchExtraPodsThenDelete(t *testing.T) {
manager, fakePodControl := setupManagerWithGCEnabled()
labelMap := map[string]string{"foo": "bar"} labelMap := map[string]string{"foo": "bar"}
rs := newReplicaSet(2, labelMap) rs := newReplicaSet(2, labelMap)
manager, fakePodControl := setupManagerWithGCEnabled(rs)
manager.rsStore.Indexer.Add(rs) manager.rsStore.Indexer.Add(rs)
// add to podStore three matching pods. Expect three patches to take control // add to podStore three matching pods. Expect three patches to take control
// them, and later delete one of them. // them, and later delete one of them.
...@@ -1197,9 +1186,9 @@ func TestPatchExtraPodsThenDelete(t *testing.T) { ...@@ -1197,9 +1186,9 @@ func TestPatchExtraPodsThenDelete(t *testing.T) {
} }
func TestUpdateLabelsRemoveControllerRef(t *testing.T) { func TestUpdateLabelsRemoveControllerRef(t *testing.T) {
manager, fakePodControl := setupManagerWithGCEnabled()
labelMap := map[string]string{"foo": "bar"} labelMap := map[string]string{"foo": "bar"}
rs := newReplicaSet(2, labelMap) rs := newReplicaSet(2, labelMap)
manager, fakePodControl := setupManagerWithGCEnabled(rs)
manager.rsStore.Indexer.Add(rs) manager.rsStore.Indexer.Add(rs)
// put one pod in the podStore // put one pod in the podStore
pod := newPod("pod", rs, api.PodRunning, nil) pod := newPod("pod", rs, api.PodRunning, nil)
...@@ -1236,9 +1225,9 @@ func TestUpdateLabelsRemoveControllerRef(t *testing.T) { ...@@ -1236,9 +1225,9 @@ func TestUpdateLabelsRemoveControllerRef(t *testing.T) {
} }
func TestUpdateSelectorControllerRef(t *testing.T) { func TestUpdateSelectorControllerRef(t *testing.T) {
manager, fakePodControl := setupManagerWithGCEnabled()
labelMap := map[string]string{"foo": "bar"} labelMap := map[string]string{"foo": "bar"}
rs := newReplicaSet(2, labelMap) rs := newReplicaSet(2, labelMap)
manager, fakePodControl := setupManagerWithGCEnabled(rs)
// put 2 pods in the podStore // put 2 pods in the podStore
newPodList(manager.podStore.Indexer, 2, api.PodRunning, labelMap, rs, "pod") newPodList(manager.podStore.Indexer, 2, api.PodRunning, labelMap, rs, "pod")
// update the RS so that its selector no longer matches the pods // update the RS so that its selector no longer matches the pods
...@@ -1270,9 +1259,9 @@ func TestUpdateSelectorControllerRef(t *testing.T) { ...@@ -1270,9 +1259,9 @@ func TestUpdateSelectorControllerRef(t *testing.T) {
// RS controller shouldn't adopt or create more pods if the rc is about to be // RS controller shouldn't adopt or create more pods if the rc is about to be
// deleted. // deleted.
func TestDoNotAdoptOrCreateIfBeingDeleted(t *testing.T) { func TestDoNotAdoptOrCreateIfBeingDeleted(t *testing.T) {
manager, fakePodControl := setupManagerWithGCEnabled()
labelMap := map[string]string{"foo": "bar"} labelMap := map[string]string{"foo": "bar"}
rs := newReplicaSet(2, labelMap) rs := newReplicaSet(2, labelMap)
manager, fakePodControl := setupManagerWithGCEnabled(rs)
now := unversioned.Now() now := unversioned.Now()
rs.DeletionTimestamp = &now rs.DeletionTimestamp = &now
manager.rsStore.Indexer.Add(rs) manager.rsStore.Indexer.Add(rs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment