From 59157082c6bd6165d175f8605166071a8f41f8df Mon Sep 17 00:00:00 2001 From: Ben Luddy Date: Tue, 1 Nov 2022 11:23:46 -0400 Subject: [PATCH] Mop up removal of manifests, configFile, and dataDir config fields. - Removes references from sample config file. - Remove defaulting behavior from ReadAndValidate. - Don't try to load from file if no config file path is available. --- packaging/microshift/config.yaml | 8 -------- pkg/cmd/run.go | 4 ++-- pkg/cmd/showConfig.go | 2 +- pkg/config/config.go | 11 ++++------- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/packaging/microshift/config.yaml b/packaging/microshift/config.yaml index d7c455a40f..edf21931b8 100644 --- a/packaging/microshift/config.yaml +++ b/packaging/microshift/config.yaml @@ -22,17 +22,9 @@ cluster: # MTU for CNI #mtu: "1400" -# Location for data created by MicroShift -#dataDir: /var/lib/microshift - # Log verbosity (0-5) #logVLevel: 0 -# Locations to scan for manifests to load on startup -#manifests: -#- /usr/lib/microshift/manifests -#- /etc/microshift/manifests - # The IP of the node (defaults to IP of default route) #nodeIP: "" diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index f5414cb315..a0a6804c3d 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -57,8 +57,8 @@ func NewRunMicroshiftCommand() *cobra.Command { } func RunMicroshift(cfg *config.MicroshiftConfig, flags *pflag.FlagSet) error { - if err := cfg.ReadAndValidate("", flags); err != nil { - klog.Fatalf("Error in reading and validating flags", err) + if err := cfg.ReadAndValidate(config.GetConfigFile(), flags); err != nil { + klog.Fatalf("Error in reading and validating flags: %v", err) } // fail early if we don't have enough privileges diff --git a/pkg/cmd/showConfig.go b/pkg/cmd/showConfig.go index 4b7b5657c3..1be3aeb117 100644 --- a/pkg/cmd/showConfig.go +++ b/pkg/cmd/showConfig.go @@ -34,7 +34,7 @@ func NewShowConfigCommand(ioStreams genericclioptions.IOStreams) *cobra.Command cfg.NodeName = "" case "effective": // Load the current configuration - if err := cfg.ReadAndValidate("", cmd.Flags()); err != nil { + if err := cfg.ReadAndValidate(config.GetConfigFile(), cmd.Flags()); err != nil { cmdutil.CheckErr(err) } default: diff --git a/pkg/config/config.go b/pkg/config/config.go index 0f2219c634..d7c9ab21e6 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -183,8 +183,6 @@ func StringInList(s string, list []string) bool { return false } -// Note: add a configFile parameter here because of unit test requiring custom -// local directory func (c *MicroshiftConfig) ReadFromConfigFile(configFile string) error { contents, err := os.ReadFile(configFile) if err != nil { @@ -243,11 +241,10 @@ func (c *MicroshiftConfig) ReadFromCmdLine(flags *pflag.FlagSet) error { // Note: add a configFile parameter here because of unit test requiring custom // local directory func (c *MicroshiftConfig) ReadAndValidate(configFile string, flags *pflag.FlagSet) error { - if configFile == "" { - configFile = findConfigFile() - } - if err := c.ReadFromConfigFile(configFile); err != nil { - return err + if configFile != "" { + if err := c.ReadFromConfigFile(configFile); err != nil { + return err + } } if err := c.ReadFromEnv(); err != nil { return err