Skip to content

Commit

Permalink
fix: only instantiate ValueConverter when webhook is enabled (#1192)
Browse files Browse the repository at this point in the history
When instantiating the ValueConverter, it also calls the Refresh
function to pull fresh schemas from the OpenAPI discovery endpoint,
which is very memory-intensive. This commit changes it to only
instantiate the converter when webhook is enabled, so it will reduce
memory usage when the webhook is not used.

b/295389452
  • Loading branch information
nan-yu authored Apr 8, 2024
1 parent ccf4ea1 commit e9eba45
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@ func Run(opts Options) {
klog.Fatalf("Instantiating Remediator: %v", err)
}

converter, err := declared.NewValueConverter(discoveryClient)
if err != nil {
klog.Fatalf("Instantiating converter: %v", err)
}

// Configure the Parser.
var parser parse.Parser
fs := parse.FileSource{
Expand All @@ -243,7 +238,6 @@ func Run(opts Options) {
RetryPeriod: opts.RetryPeriod,
StatusUpdatePeriod: opts.StatusUpdatePeriod,
DiscoveryInterface: discoveryClient,
Converter: converter,
RenderingEnabled: opts.RenderingEnabled,
Files: parse.Files{FileSource: fs},
WebhookEnabled: opts.WebhookEnabled,
Expand All @@ -254,6 +248,15 @@ func Run(opts Options) {
Remediator: rem,
},
}
// Only instantiate the converter when the webhook is enabled because the
// instantiation pulls fresh schemas from the openapi discovery endpoint.
if opts.WebhookEnabled {
parseOpts.Converter, err = declared.NewValueConverter(discoveryClient)
if err != nil {
klog.Fatalf("Instantiating converter: %v", err)
}
}

nsControllerState := namespacecontroller.NewState()
if opts.ReconcilerScope == declared.RootReconciler {
rootOpts := &parse.RootOptions{
Expand Down

0 comments on commit e9eba45

Please sign in to comment.