Skip to content

Commit

Permalink
Avoid fragile global initialization of scheme (#3620)
Browse files Browse the repository at this point in the history
Move to normal codepath
  • Loading branch information
justinsb authored Oct 14, 2022
1 parent 9dd3319 commit 3eb9918
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions porch/controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"k8s.io/klog/v2/klogr"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand All @@ -48,8 +47,6 @@ import (
)

var (
scheme = runtime.NewScheme()

reconcilers = map[string]newReconciler{
"rootsyncsets": func() Reconciler {
return &rootsyncset.RootSyncSetReconciler{}
Expand All @@ -75,11 +72,6 @@ type newReconciler func() Reconciler
//+kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups="",resources=events,verbs=create;patch

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

func main() {
err := run(context.Background())
if err != nil {
Expand All @@ -105,6 +97,11 @@ func run(ctx context.Context) error {

flag.Parse()

scheme := runtime.NewScheme()
if err := clientgoscheme.AddToScheme(scheme); err != nil {
return fmt.Errorf("error initializing scheme: %w", err)
}

managerOptions := ctrl.Options{
Scheme: scheme,
MetricsBindAddress: ":8080",
Expand Down

0 comments on commit 3eb9918

Please sign in to comment.