Skip to content

Commit

Permalink
clusterctl: adjust Overrider interface so Path can return an error
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Oct 7, 2022
1 parent 850c2a6 commit 9fd17c8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions cmd/clusterctl/client/repository/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package repository

import (
"fmt"
"os"
"path/filepath"
"strings"
Expand All @@ -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 (
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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 {
Expand Down

0 comments on commit 9fd17c8

Please sign in to comment.