Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing unmanaged controllers #569

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions pkg/reconcile/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/solo-io/go-utils/contextutils"
"github.com/solo-io/skv2/pkg/ezkube"
"github.com/solo-io/skv2/pkg/utils"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -71,6 +72,8 @@ type Options struct {

// If provided, attempt to verify the resource before beginning the reconcile loop
Verifier verifier.ServerResourceVerifier

UseUnmanagedController bool
}

func NewLoop(
Expand Down Expand Up @@ -117,9 +120,16 @@ func (r *runner) RunReconciler(ctx context.Context, reconciler Reconciler, predi
reconciler: reconciler,
}

ctl, err := controller.New(r.name, r.mgr, controller.Options{
Reconciler: rec,
})
var ctl controller.Controller
if r.options.UseUnmanagedController {
ctl, err = controller.NewUnmanaged(r.name, r.mgr, controller.Options{
Reconciler: rec,
})
} else {
ctl, err = controller.New(r.name, r.mgr, controller.Options{
Reconciler: rec,
})
}
if err != nil {
return err
}
Expand Down Expand Up @@ -153,6 +163,23 @@ func (r *runner) RunReconciler(ctx context.Context, reconciler Reconciler, predi
return err
}

if r.options.UseUnmanagedController {
// Start our controller in a goroutine so that we do not block.
go func() {
// Block until our controller manager is elected leader. We presume our
// entire process will terminate if we lose leadership, so we don't need
// to handle that.
<-r.mgr.Elected()

// Start our controller. This will block until the stop channel is
// closed, or the controller returns an error.
if err := ctl.Start(ctx); err != nil {
contextutils.LoggerFrom(ctx).Error(err)
return
}
}()
}

// Only wait for cache sync if specified in options
if r.options.WaitForCacheSync {
rec.logger.V(1).Info("waiting for cache sync...")
Expand Down
Loading