Skip to content

Commit

Permalink
Merge pull request #228 from jhernandezb/fix-retry-events
Browse files Browse the repository at this point in the history
pkg/controller: re-add to the queue failed reconcile keys
  • Loading branch information
Phillip Wittrock authored May 30, 2018
2 parents 6fd5269 + 6709f3c commit 8b57ecb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func (gc *GenericController) processNextWorkItem() bool {
if gc.AfterReconcile != nil {
gc.AfterReconcile(rk, err)
}
gc.queue.AddRateLimited(key)
return fmt.Errorf("error syncing %s queue '%s': %s", gc.Name, key, err.Error())
}
if gc.AfterReconcile != nil {
Expand Down
31 changes: 31 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package controller

import (
"fmt"
"sync/atomic"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

Expand Down Expand Up @@ -476,6 +479,34 @@ var _ = Describe("GenericController", func() {
})
})

Describe("Re-queue an item when reconcile returns error", func() {
BeforeEach(func() {
var counter uint64
instance = &GenericController{
Name: "TestInstance",
InformerRegistry: mgr,
Reconcile: func(k types.ReconcileKey) error {
result <- fmt.Sprintf("retry-%d", counter)
atomic.AddUint64(&counter, 1)
return fmt.Errorf("error")
},
}
mgr.AddController(instance)
mgr.RunInformersAndControllers(run.RunArguments{Stop: stop})
})

It("should add the item back to the queue", func() {
instance.Watch(&corev1.Pod{})
// Create a Pod event
fakePodInformer.Add(&corev1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "failed-pod", Namespace: "default"}})
val := ChannelResult{}
Eventually(result).Should(Receive(&val.result))
Expect(val.result).Should(Equal("retry-0"))
Eventually(result).Should(Receive(&val.result))
Expect(val.result).Should(Equal("retry-1"))
})
})

AfterEach(func() {
close(stop)
})
Expand Down

0 comments on commit 8b57ecb

Please sign in to comment.