From 9fd17c8aea7bc843b8a6f78a4332c2dc85205d54 Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Fri, 7 Oct 2022 16:03:06 +0200 Subject: [PATCH] clusterctl: adjust Overrider interface so Path can return an error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Büringer buringerst@vmware.com --- cmd/clusterctl/client/repository/overrides.go | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/clusterctl/client/repository/overrides.go b/cmd/clusterctl/client/repository/overrides.go index 07e0184283e0..e1a0f3e7cd6b 100644 --- a/cmd/clusterctl/client/repository/overrides.go +++ b/cmd/clusterctl/client/repository/overrides.go @@ -17,7 +17,6 @@ limitations under the License. package repository import ( - "fmt" "os" "path/filepath" "strings" @@ -27,7 +26,6 @@ import ( "k8s.io/client-go/util/homedir" "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config" - logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" ) const ( @@ -37,7 +35,7 @@ const ( // Overrider provides behavior to determine the overrides layer. type Overrider interface { - Path() string + Path() (string, error) } // overrides implements the Overrider interface. @@ -67,17 +65,15 @@ func newOverride(o *newOverrideInput) Overrider { // Path returns the fully formed path to the file within the specified // overrides config. -func (o *overrides) Path() string { +func (o *overrides) Path() (string, error) { basepath := filepath.Join(homedir.HomeDir(), config.ConfigFolder, overrideFolder) f, err := o.configVariablesClient.Get(overrideFolderKey) if err == nil && strings.TrimSpace(f) != "" { basepath = f - evaluatedBasePath, err := envsubst.Eval(basepath, os.Getenv) + basepath, err = envsubst.Eval(basepath, os.Getenv) if err != nil { - logf.Log.Info(fmt.Sprintf("⚠️overridesFolder %q could not be evaluated: %v", basepath, err)) - } else { - basepath = evaluatedBasePath + return "", errors.Wrapf(err, "unable to evaluate %s: %q", overrideFolderKey, basepath) } } @@ -86,15 +82,19 @@ func (o *overrides) Path() string { o.providerLabel, o.version, o.filePath, - ) + ), nil } // getLocalOverride return local override file from the config folder, if it exists. // This is required for development purposes, but it can be used also in production as a workaround for problems on the official repositories. func getLocalOverride(info *newOverrideInput) ([]byte, error) { - overridePath := newOverride(info).Path() + overridePath, err := newOverride(info).Path() + if err != nil { + return nil, err + } + // it the local override exists, use it - _, err := os.Stat(overridePath) + _, err = os.Stat(overridePath) if err == nil { content, err := os.ReadFile(overridePath) //nolint:gosec if err != nil {