Skip to content

Commit e9eba45

Browse files
authored
fix: only instantiate ValueConverter when webhook is enabled (#1192)
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
1 parent ccf4ea1 commit e9eba45

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

pkg/reconciler/reconciler.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,6 @@ func Run(opts Options) {
213213
klog.Fatalf("Instantiating Remediator: %v", err)
214214
}
215215

216-
converter, err := declared.NewValueConverter(discoveryClient)
217-
if err != nil {
218-
klog.Fatalf("Instantiating converter: %v", err)
219-
}
220-
221216
// Configure the Parser.
222217
var parser parse.Parser
223218
fs := parse.FileSource{
@@ -243,7 +238,6 @@ func Run(opts Options) {
243238
RetryPeriod: opts.RetryPeriod,
244239
StatusUpdatePeriod: opts.StatusUpdatePeriod,
245240
DiscoveryInterface: discoveryClient,
246-
Converter: converter,
247241
RenderingEnabled: opts.RenderingEnabled,
248242
Files: parse.Files{FileSource: fs},
249243
WebhookEnabled: opts.WebhookEnabled,
@@ -254,6 +248,15 @@ func Run(opts Options) {
254248
Remediator: rem,
255249
},
256250
}
251+
// Only instantiate the converter when the webhook is enabled because the
252+
// instantiation pulls fresh schemas from the openapi discovery endpoint.
253+
if opts.WebhookEnabled {
254+
parseOpts.Converter, err = declared.NewValueConverter(discoveryClient)
255+
if err != nil {
256+
klog.Fatalf("Instantiating converter: %v", err)
257+
}
258+
}
259+
257260
nsControllerState := namespacecontroller.NewState()
258261
if opts.ReconcilerScope == declared.RootReconciler {
259262
rootOpts := &parse.RootOptions{

0 commit comments

Comments
 (0)