Skip to content

Commit 8b57ecb

Browse files
author
Phillip Wittrock
authored
Merge pull request #228 from jhernandezb/fix-retry-events
pkg/controller: re-add to the queue failed reconcile keys
2 parents 6fd5269 + 6709f3c commit 8b57ecb

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pkg/controller/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ func (gc *GenericController) processNextWorkItem() bool {
315315
if gc.AfterReconcile != nil {
316316
gc.AfterReconcile(rk, err)
317317
}
318+
gc.queue.AddRateLimited(key)
318319
return fmt.Errorf("error syncing %s queue '%s': %s", gc.Name, key, err.Error())
319320
}
320321
if gc.AfterReconcile != nil {

pkg/controller/controller_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ limitations under the License.
1717
package controller
1818

1919
import (
20+
"fmt"
21+
"sync/atomic"
22+
2023
. "github.com/onsi/ginkgo"
2124
. "github.com/onsi/gomega"
2225

@@ -476,6 +479,34 @@ var _ = Describe("GenericController", func() {
476479
})
477480
})
478481

482+
Describe("Re-queue an item when reconcile returns error", func() {
483+
BeforeEach(func() {
484+
var counter uint64
485+
instance = &GenericController{
486+
Name: "TestInstance",
487+
InformerRegistry: mgr,
488+
Reconcile: func(k types.ReconcileKey) error {
489+
result <- fmt.Sprintf("retry-%d", counter)
490+
atomic.AddUint64(&counter, 1)
491+
return fmt.Errorf("error")
492+
},
493+
}
494+
mgr.AddController(instance)
495+
mgr.RunInformersAndControllers(run.RunArguments{Stop: stop})
496+
})
497+
498+
It("should add the item back to the queue", func() {
499+
instance.Watch(&corev1.Pod{})
500+
// Create a Pod event
501+
fakePodInformer.Add(&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "failed-pod", Namespace: "default"}})
502+
val := ChannelResult{}
503+
Eventually(result).Should(Receive(&val.result))
504+
Expect(val.result).Should(Equal("retry-0"))
505+
Eventually(result).Should(Receive(&val.result))
506+
Expect(val.result).Should(Equal("retry-1"))
507+
})
508+
})
509+
479510
AfterEach(func() {
480511
close(stop)
481512
})

0 commit comments

Comments
 (0)