Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cli to work on windows #1139

Merged
merged 2 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 12 additions & 9 deletions cli/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package helm

import (
"embed"
"path/filepath"
"path"
"strings"

"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
Expand Down Expand Up @@ -34,17 +35,23 @@ 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
}
chartFiles = append(chartFiles, file)
}

// 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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rel() doesn't exist in the path package. I looked at copying it from filepath but it uses a lot of internal stuff to filepath so not an easy copy. I think we're okay just trimming the prefix here because we're always passing in pathPrefix (hence variable name), not something we need to properly calculate the relative directory of.

rel, err := filepath.Rel(pathPrefix, f)
if err != nil {
return nil, err
}
rel := strings.TrimPrefix(f, pathPrefix+"/")
return &loader.BufferedFile{
Name: rel,
Data: bytes,
Expand Down