Skip to content

Commit a21abfe

Browse files
committed
clusterctl: adjust Overrider interface so Path can return an error
Signed-off-by: Stefan Büringer [email protected]
1 parent 324f8e8 commit a21abfe

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

cmd/clusterctl/client/repository/overrides.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package repository
1818

1919
import (
20-
"fmt"
2120
"net/url"
2221
"os"
2322
"path/filepath"
@@ -29,7 +28,6 @@ import (
2928
"k8s.io/client-go/util/homedir"
3029

3130
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
32-
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
3331
)
3432

3533
const (
@@ -39,7 +37,7 @@ const (
3937

4038
// Overrider provides behavior to determine the overrides layer.
4139
type Overrider interface {
42-
Path() string
40+
Path() (string, error)
4341
}
4442

4543
// overrides implements the Overrider interface.
@@ -69,30 +67,28 @@ func newOverride(o *newOverrideInput) Overrider {
6967

7068
// Path returns the fully formed path to the file within the specified
7169
// overrides config.
72-
func (o *overrides) Path() string {
70+
func (o *overrides) Path() (string, error) {
7371
basepath := filepath.Join(homedir.HomeDir(), config.ConfigFolder, overrideFolder)
7472
f, err := o.configVariablesClient.Get(overrideFolderKey)
7573
if err == nil && strings.TrimSpace(f) != "" {
7674
basepath = f
7775

78-
evaluatedBasePath, err := envsubst.Eval(basepath, os.Getenv)
76+
basepath, err = envsubst.Eval(basepath, os.Getenv)
7977
if err != nil {
80-
logf.Log.Info(fmt.Sprintf("⚠️overridesFolder %q could not be evaluated: %v", basepath, err))
81-
} else {
82-
basepath = evaluatedBasePath
78+
return "", errors.Wrapf(err, "unable to evaluate %s: %q", overrideFolderKey, basepath)
8379
}
8480

8581
if runtime.GOOS == "windows" {
8682
parsedBasePath, err := url.Parse(basepath)
8783
if err != nil {
88-
logf.Log.Info(fmt.Sprintf("⚠️overridesFolder %q could not be parsed: %v", basepath, err))
89-
} else {
90-
// in case of windows, we should take care of removing the additional / which is required by the URI standard
91-
// for windows local paths. see https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ for more details.
92-
// Encoded file paths are not required in Windows 10 versions <1803 and are unsupported in Windows 10 >=1803
93-
// https://support.microsoft.com/en-us/help/4467268/url-encoded-unc-paths-not-url-decoded-in-windows-10-version-1803-later
94-
basepath = filepath.FromSlash(strings.TrimPrefix(parsedBasePath.Path, "/"))
84+
return "", errors.Wrapf(err, "unable to parse %s: %q", overrideFolderKey, basepath)
9585
}
86+
87+
// in case of windows, we should take care of removing the additional / which is required by the URI standard
88+
// for windows local paths. see https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ for more details.
89+
// Encoded file paths are not required in Windows 10 versions <1803 and are unsupported in Windows 10 >=1803
90+
// https://support.microsoft.com/en-us/help/4467268/url-encoded-unc-paths-not-url-decoded-in-windows-10-version-1803-later
91+
basepath = filepath.FromSlash(strings.TrimPrefix(parsedBasePath.Path, "/"))
9692
}
9793
}
9894

@@ -101,15 +97,19 @@ func (o *overrides) Path() string {
10197
o.providerLabel,
10298
o.version,
10399
o.filePath,
104-
)
100+
), nil
105101
}
106102

107103
// getLocalOverride return local override file from the config folder, if it exists.
108104
// This is required for development purposes, but it can be used also in production as a workaround for problems on the official repositories.
109105
func getLocalOverride(info *newOverrideInput) ([]byte, error) {
110-
overridePath := newOverride(info).Path()
106+
overridePath, err := newOverride(info).Path()
107+
if err != nil {
108+
return nil, err
109+
}
110+
111111
// it the local override exists, use it
112-
_, err := os.Stat(overridePath)
112+
_, err = os.Stat(overridePath)
113113
if err == nil {
114114
content, err := os.ReadFile(overridePath) //nolint:gosec
115115
if err != nil {

docs/book/src/developer/providers/v1.2-to-v1.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ in Cluster API are kept in sync with the versions used by `sigs.k8s.io/controlle
4040
- A new timeout `nodeVolumeDetachTimeout` has been introduced that defines how long the controller will spend on waiting for all volumes to be detached.
4141
The default value is 0, meaning that the volume can be detached without any time limitations.
4242
- A new annotation `machine.cluster.x-k8s.io/exclude-wait-for-node-volume-detach` has been introduced that allows explicitly skip the waiting for node volume detaching.
43+
- The `Path` func in the `sigs.k8s.io/cluster-api/cmd/clusterctl/client/repository.Overrider` interface has been adjusted to also return an error.
4344

4445
### Other
4546

0 commit comments

Comments
 (0)