Files
helmfile/pkg/state/util.go
T
Indrek Juhkam 608bb0b525 Avoid --skip-refresh on local charts (#541)
All the dependencies get correctly installed when dealing with remote
charts.

If there's a local chart that depends on remote dependencies then those
don't get automatically installed. See #526. They end up with this
error:

```
Error: no cached repository for helm-manager-b6cf96b91af4f01317d185adfbe32610179e5246214be9646a52cb0b86032272 found. (try 'helm repo update'): open /root/.cache/helm/repository/helm-manager-b6cf96b91af4f01317d185adfbe32610179e5246214be9646a52cb0b86032272-index.yaml: no such file or directory
```

One workaround for that would be to add the repositories from the local
charts. Something like this:

```
cd local-chart/ && helm dependency list $dir 2> /dev/null | tail +2 | head -n -1 | awk '{ print "helm repo add " $1 " " $3 }' | while read cmd; do $cmd; done
```

This however is not trivial to parse and implement.

An easier fix which I did here is just to not allow doing
`--skip-refresh` for local repositories.

Fixes #526

Signed-off-by: Indrek Juhkam <indrek@urgas.eu>

Signed-off-by: Indrek Juhkam <indrek@urgas.eu>
Signed-off-by: yxxhero <aiopsclub@163.com>
2022-12-13 13:12:07 +08:00

76 lines
1.8 KiB
Go

package state
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/helmfile/helmfile/pkg/helmexec"
)
var (
// current working directory
currentDirSymbol = "."
// parent directory
parentDirSymbol = ".."
)
func isLocalChart(chart string) bool {
if strings.HasPrefix(chart, fmt.Sprintf("%s%c", currentDirSymbol, os.PathSeparator)) || strings.HasPrefix(chart, fmt.Sprintf("%s%c", parentDirSymbol, os.PathSeparator)) {
return true
}
uriLike := strings.Contains(chart, "://")
if uriLike {
return false
}
return chart == "" ||
filepath.IsAbs(chart) ||
!strings.Contains(chart, "/") ||
(len(strings.Split(chart, "/")) != 2 &&
len(strings.Split(chart, "/")) != 3)
}
func resolveRemoteChart(repoAndChart string) (string, string, bool) {
if isLocalChart(repoAndChart) {
return "", "", false
}
uriLike := strings.Contains(repoAndChart, "://")
if uriLike {
return "", "", false
}
parts := strings.SplitN(repoAndChart, "/", 2)
if len(parts) < 2 {
return "", "", false
}
repo := parts[0]
chart := parts[1]
return repo, chart, true
}
// normalizeChart allows for the distinction between a file path reference and repository references.
// - Any single (or double character) followed by a `/` will be considered a local file reference and
// be constructed relative to the `base path`.
// - Everything else is assumed to be an absolute path or an actual <repository>/<chart> reference.
func normalizeChart(basePath, chart string) string {
if !isLocalChart(chart) || filepath.IsAbs(chart) {
return chart
}
return filepath.Join(basePath, chart)
}
func getBuildDepsFlags(helm helmexec.Interface, cpr *chartPrepareResult) []string {
flags := []string{}
if helm.IsHelm3() && cpr.skipRefresh {
flags = append(flags, "--skip-refresh")
}
return flags
}