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>
This commit is contained in:
Indrek Juhkam
2022-12-13 13:12:07 +08:00
committed by yxxhero
parent 197fdcdabd
commit 608bb0b525
18 changed files with 91 additions and 41 deletions
+4 -1
View File
@@ -1015,6 +1015,7 @@ type chartPrepareResult struct {
chartPath string
err error
buildDeps bool
skipRefresh bool
chartFetchedByGoGetter bool
}
@@ -1263,6 +1264,7 @@ func (st *HelmState) PrepareCharts(helm helmexec.Interface, dir string, concurre
releaseContext: release.KubeContext,
chartPath: chartPath,
buildDeps: buildDeps,
skipRefresh: !isLocal,
chartFetchedByGoGetter: chartFetchedByGoGetter,
}
}
@@ -1314,7 +1316,8 @@ func (st *HelmState) runHelmDepBuilds(helm helmexec.Interface, concurrency int,
//
// See https://github.com/roboll/helmfile/issues/1521
for _, r := range builds {
if err := helm.BuildDeps(r.releaseName, r.chartPath); err != nil {
buildDepsFlags := getBuildDepsFlags(helm, r)
if err := helm.BuildDeps(r.releaseName, r.chartPath, buildDepsFlags...); err != nil {
if r.chartFetchedByGoGetter {
diagnostic := fmt.Sprintf(
"WARN: `helm dep build` failed. While processing release %q, Helmfile observed that remote chart %q fetched by go-getter is seemingly broken. "+
+11
View File
@@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"strings"
"github.com/helmfile/helmfile/pkg/helmexec"
)
var (
@@ -62,3 +64,12 @@ func normalizeChart(basePath, chart string) string {
}
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
}