From 48cc19bee3ede809be80a5295c2daacc19f0071c Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:39:16 +0200 Subject: [PATCH] add comments and improve variable names Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- cmd/controller/app/start.go | 14 +++++++++++--- cmd/webhook/app/webhook.go | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/cmd/controller/app/start.go b/cmd/controller/app/start.go index eccdda36c..2e4b6fb0f 100644 --- a/cmd/controller/app/start.go +++ b/cmd/controller/app/start.go @@ -116,14 +116,22 @@ to renew certificates at an appropriate time before expiry.`, return cmd } +// loadConfigFromFile loads the configuration from the provided config file +// path, if one is provided. After loading the config file, the flags are +// re-parsed to ensure that any flags provided to the command line override +// those provided in the config file. +// The newConfigHook is called when the options have been loaded from the +// flags (but not yet the config file) and is re-called after the config file +// has been loaded. This allows us to use the logging options and feature flags +// set by the flags to log errors when loading the config file. func loadConfigFromFile( cmd *cobra.Command, allArgs []string, configFilePath string, cfg *config.ControllerConfiguration, - fn func() error, + newConfigHook func() error, ) error { - if err := fn(); err != nil { + if err := newConfigHook(); err != nil { return err } @@ -155,7 +163,7 @@ func loadConfigFromFile( return fmt.Errorf("failed to re-parse flags: %w", err) } - if err := fn(); err != nil { + if err := newConfigHook(); err != nil { return err } } diff --git a/cmd/webhook/app/webhook.go b/cmd/webhook/app/webhook.go index 16885bcab..1d3d16ab0 100644 --- a/cmd/webhook/app/webhook.go +++ b/cmd/webhook/app/webhook.go @@ -111,14 +111,22 @@ functionality for cert-manager.`, return cmd } +// loadConfigFromFile loads the configuration from the provided config file +// path, if one is provided. After loading the config file, the flags are +// re-parsed to ensure that any flags provided to the command line override +// those provided in the config file. +// The newConfigHook is called when the options have been loaded from the +// flags (but not yet the config file) and is re-called after the config file +// has been loaded. This allows us to use the logging options and feature flags +// set by the flags to log errors when loading the config file. func loadConfigFromFile( cmd *cobra.Command, allArgs []string, configFilePath string, cfg *config.WebhookConfiguration, - fn func() error, + newConfigHook func() error, ) error { - if err := fn(); err != nil { + if err := newConfigHook(); err != nil { return err } @@ -150,7 +158,7 @@ func loadConfigFromFile( return fmt.Errorf("failed to re-parse flags: %w", err) } - if err := fn(); err != nil { + if err := newConfigHook(); err != nil { return err } }