diff --git a/CHANGELOG.md b/CHANGELOG.md index 624a335612..c48778e607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,8 @@ BUG FIXES: * Helm * Don't set TTL for server certificates when using Vault as the secrets backend. [[GH-1104](https://github.com/hashicorp/consul-k8s/pull/1104)] * Fix PodSecurityPolicies for clients/mesh gateways when hostNetwork is used. [[GH-1090](https://github.com/hashicorp/consul-k8s/pull/1090)] +* CLI + * Fix `install` and `upgrade` commands for Windows. [[GH-1139](https://github.com/hashicorp/consul-k8s/pull/1139)] ## 0.41.1 (February 24, 2022) diff --git a/cli/helm/chart.go b/cli/helm/chart.go index 3558e688ca..a4a13dff8f 100644 --- a/cli/helm/chart.go +++ b/cli/helm/chart.go @@ -2,7 +2,8 @@ package helm import ( "embed" - "path/filepath" + "path" + "strings" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" @@ -34,9 +35,15 @@ func LoadChart(chart embed.FS, chartDirName string) (*chart.Chart, error) { func ReadChartFiles(chart embed.FS, chartDirName string) ([]*loader.BufferedFile, error) { var chartFiles []*loader.BufferedFile + // NOTE: Because we're using the embedded filesystem, we must use path.* functions, + // *not* filepath.* functions. This is because the embedded filesystem always uses + // linux-style separators, even if this code is running on Windows. If we use + // filepath.* functions, then Go on Windows will try to use `\` delimiters to access + // the embedded filesystem, which will then fail. + // Load Chart.yaml and values.yaml first. for _, f := range []string{chartFileName, valuesFileName} { - file, err := readFile(chart, filepath.Join(chartDirName, f), chartDirName) + file, err := readFile(chart, path.Join(chartDirName, f), chartDirName) if err != nil { return nil, err } @@ -44,7 +51,7 @@ func ReadChartFiles(chart embed.FS, chartDirName string) ([]*loader.BufferedFile } // Now load everything under templates/. - dirs, err := chart.ReadDir(filepath.Join(chartDirName, templatesDirName)) + dirs, err := chart.ReadDir(path.Join(chartDirName, templatesDirName)) if err != nil { return nil, err } @@ -54,7 +61,7 @@ func ReadChartFiles(chart embed.FS, chartDirName string) ([]*loader.BufferedFile continue } - file, err := readFile(chart, filepath.Join(chartDirName, templatesDirName, f.Name()), chartDirName) + file, err := readFile(chart, path.Join(chartDirName, templatesDirName, f.Name()), chartDirName) if err != nil { return nil, err } @@ -86,11 +93,7 @@ func readFile(chart embed.FS, f string, pathPrefix string) (*loader.BufferedFile if err != nil { return nil, err } - // Remove the path prefix. - rel, err := filepath.Rel(pathPrefix, f) - if err != nil { - return nil, err - } + rel := strings.TrimPrefix(f, pathPrefix+"/") return &loader.BufferedFile{ Name: rel, Data: bytes,