Skip to content

Commit

Permalink
Create a new runnable context
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Sep 9, 2022
1 parent bde70b3 commit 19c3a5a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -114,7 +115,7 @@ func Initialize(injectCloudProvider func(context.Context, cloudprovider.Options)
Scheme: scheme,
MetricsBindAddress: fmt.Sprintf(":%d", opts.MetricsPort),
HealthProbeBindAddress: fmt.Sprintf(":%d", opts.HealthProbePort),
BaseContext: func() context.Context { return ctx },
BaseContext: newRunnableContext(controllerRuntimeConfig, opts, logging.FromContext(ctx)),
})

if opts.EnableProfiling {
Expand Down Expand Up @@ -267,3 +268,13 @@ func LoggingContextOrDie(config *rest.Config, cmw *informer.InformedWatcher) con
startinformers()
return ctx
}

func newRunnableContext(config *rest.Config, options *options.Options, logger *zap.SugaredLogger) func() context.Context {
return func() context.Context {
ctx := context.Background()
ctx = logging.WithLogger(ctx, logger)
ctx = injection.WithConfig(ctx, config)
ctx = injection.WithOptions(ctx, *options)
return ctx
}
}

0 comments on commit 19c3a5a

Please sign in to comment.