Skip to content

Instantly share code, notes, and snippets.

Created November 11, 2020 07:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
adding a channel of reconcile events
package main
ctrl ""
// First, in the main entry point code for our operator,
func main(){
// ...
// ...we created a channel:
reconcileEvents := make(chan event.GenericEvent)
// ...then, we created a Source to contain that channel:
src := &source.Channel{Source: rotateEvents}
// ...then we created the Controller, using a Manager we had already
// created, and passed in the Source:
if err := ctrl.NewControllerManagedBy(mgr).
Watches(src, &handler.EnqueueRequestForObject{}).
Complete(reconciler); err != nil {
setupLog.Error(err, “unable to create controller”, “controller”, “XXX”)
// ...then we passed the channel to the object that updates our credentials
// (the Rotor that rotates passwords on a reconcile event):
rotorObj := rotor.Rotor{
// ...
Channel: rotateEvents,
go rotorObj.Run()
// ...
// ...
func (r Rotor) Rotate(ctx context.Context, items []XXX) error {
for item := range items {
// ... and that object puts an event in the channel, forcing a reconcile, (and
// resets our ObservedGeneration so that event actually does something):
item.Status.ObservedGeneration = 0
if err := r.Client.Status().Update(ctx, &item); err != nil {
return fmt.Errorf(“marking XXX as needing an update: %s”, err)
// send event to controller for rotation
r.Channel <- event.GenericEvent{
Meta: &item.ObjectMeta,
Object: &item,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment