Fix bootstrap failure on Windows when working directory is on different drive than TEMP
When running flux bootstrap from a drive (e.g. D:\) different from where %TEMP% lives (typically C:\), filepath.Rel fails because Go can't compute relative paths across different drive letters. The original code converted absolute paths to relative as a workaround for a kustomize bug (kubernetes-sigs/kustomize#2789) that was caused by go-getter. Since kustomize dropped go-getter in 2021, absolute paths work fine now. Instead of hard-failing when filepath.Rel errors, keep the absolute path as a fallback. Signed-off-by: Varun Chawla <varun_6april@hotmail.com>
This commit is contained in:
@@ -169,19 +169,19 @@ func BuildWithRoot(root, base string) ([]byte, error) {
|
|||||||
return nil, fmt.Errorf("%s not found", konfig.DefaultKustomizationFileName())
|
return nil, fmt.Errorf("%s not found", konfig.DefaultKustomizationFileName())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(hidde): work around for a bug in kustomize causing it to
|
// Convert absolute paths to relative when possible, for kustomize
|
||||||
// not properly handle absolute paths on Windows.
|
// compatibility. If filepath.Rel fails (e.g. paths on different
|
||||||
// Convert the path to a relative path to the working directory
|
// Windows drives), keep the absolute path — kustomize handles
|
||||||
// as a temporary fix:
|
// absolute paths correctly since go-getter was removed.
|
||||||
// https://github.com/kubernetes-sigs/kustomize/issues/2789
|
// See: https://github.com/kubernetes-sigs/kustomize/issues/2789
|
||||||
|
// https://github.com/fluxcd/flux2/issues/1153
|
||||||
if filepath.IsAbs(base) {
|
if filepath.IsAbs(base) {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
base, err = filepath.Rel(wd, base)
|
if relBase, err := filepath.Rel(wd, base); err == nil {
|
||||||
if err != nil {
|
base = relBase
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user