mirror of
https://github.com/helmfile/helmfile.git
synced 2026-09-30 06:02:58 +02:00
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>
This commit is contained in:
@@ -33,19 +33,23 @@ type ociChart struct {
|
||||
digest string
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
LocalDockerRegistry struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Port int `yaml:"port"`
|
||||
ChartDir string `yaml:"chartDir"`
|
||||
} `yaml:"localDockerRegistry"`
|
||||
LocalChartRepoServer struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Port int `yaml:"port"`
|
||||
ChartDir string `yaml:"chartDir"`
|
||||
} `yaml:"localChartRepoServer"`
|
||||
ChartifyTempDir string `yaml:"chartifyTempDir"`
|
||||
HelmfileArgs []string `yaml:"helmfileArgs"`
|
||||
}
|
||||
|
||||
func TestHelmfileTemplateWithBuildCommand(t *testing.T) {
|
||||
type Config struct {
|
||||
LocalDockerRegistry struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Port int `yaml:"port"`
|
||||
} `yaml:"localDockerRegistry"`
|
||||
LocalChartRepoServer struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Port int `yaml:"port"`
|
||||
} `yaml:"localChartRepoServer"`
|
||||
ChartifyTempDir string `yaml:"chartifyTempDir"`
|
||||
HelmfileArgs []string `yaml:"helmfileArgs"`
|
||||
}
|
||||
localChartPortSets := make(map[int]struct{})
|
||||
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
projectRoot := filepath.Join(filepath.Dir(filename), "..", "..", "..", "..")
|
||||
@@ -54,7 +58,7 @@ func TestHelmfileTemplateWithBuildCommand(t *testing.T) {
|
||||
helmfileBin = helmfileBin + ".exe"
|
||||
}
|
||||
testdataDir := "testdata/snapshot"
|
||||
chartsDir := "testdata/charts"
|
||||
defaultChartsDir := "testdata/charts"
|
||||
|
||||
entries, err := os.ReadDir(testdataDir)
|
||||
require.NoError(t, err)
|
||||
@@ -81,6 +85,21 @@ func TestHelmfileTemplateWithBuildCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if config.LocalChartRepoServer.Enabled {
|
||||
if _, ok := localChartPortSets[config.LocalChartRepoServer.Port]; ok {
|
||||
t.Fatalf("Port %d is already in use", config.LocalChartRepoServer.Port)
|
||||
} else {
|
||||
localChartPortSets[config.LocalChartRepoServer.Port] = struct{}{}
|
||||
}
|
||||
if config.LocalChartRepoServer.ChartDir == "" {
|
||||
config.LocalChartRepoServer.ChartDir = defaultChartsDir
|
||||
}
|
||||
helmtesting.StartChartRepoServer(t, helmtesting.ChartRepoServerConfig{
|
||||
Port: config.LocalChartRepoServer.Port,
|
||||
ChartsDir: config.LocalChartRepoServer.ChartDir,
|
||||
})
|
||||
}
|
||||
|
||||
// We run `helmfile build` by default.
|
||||
// If you want to test `helmfile template`, set the following in the config.yaml:
|
||||
//
|
||||
@@ -139,11 +158,14 @@ func TestHelmfileTemplateWithBuildCommand(t *testing.T) {
|
||||
|
||||
// We helm-package and helm-push every test chart saved in the ./testdata/charts directory
|
||||
// to the local registry, so that they can be accessed by helmfile and helm invoked while testing.
|
||||
charts, err := os.ReadDir(chartsDir)
|
||||
if config.LocalDockerRegistry.ChartDir == "" {
|
||||
config.LocalDockerRegistry.ChartDir = defaultChartsDir
|
||||
}
|
||||
charts, err := os.ReadDir(config.LocalDockerRegistry.ChartDir)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, c := range charts {
|
||||
chartPath := filepath.Join(chartsDir, c.Name())
|
||||
chartPath := filepath.Join(config.LocalDockerRegistry.ChartDir, c.Name())
|
||||
if !c.IsDir() {
|
||||
t.Fatalf("%s is not a directory", c)
|
||||
}
|
||||
@@ -160,13 +182,6 @@ func TestHelmfileTemplateWithBuildCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if config.LocalChartRepoServer.Enabled {
|
||||
helmtesting.StartChartRepoServer(t, helmtesting.ChartRepoServerConfig{
|
||||
Port: config.LocalChartRepoServer.Port,
|
||||
ChartsDir: chartsDir,
|
||||
})
|
||||
}
|
||||
|
||||
inputFile := filepath.Join(testdataDir, name, "input.yaml")
|
||||
outputFile := filepath.Join(testdataDir, name, "output.yaml")
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ Adding repo myrepo http://localhost:18080/
|
||||
"myrepo" has been added to your repositories
|
||||
|
||||
Building dependency release=foo, chart=$WD/temp1/foo
|
||||
Hang tight while we grab the latest from your chart repositories...
|
||||
...Successfully got an update from the "myrepo" chart repository
|
||||
Update Complete. ⎈Happy Helming!⎈
|
||||
Saving 1 charts
|
||||
Downloading raw from repo http://localhost:18080/
|
||||
Deleting outdated charts
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
localChartRepoServer:
|
||||
enabled: true
|
||||
port: 18080
|
||||
port: 18081
|
||||
chartifyTempDir: temp1
|
||||
helmfileArgs:
|
||||
- --enable-live-output
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
repositories:
|
||||
- name: myrepo
|
||||
url: http://localhost:18080/
|
||||
url: http://localhost:18081/
|
||||
|
||||
releases:
|
||||
- name: foo
|
||||
|
||||
+5
-2
@@ -1,10 +1,13 @@
|
||||
Live output is enabled
|
||||
Adding repo myrepo http://localhost:18080/
|
||||
Adding repo myrepo http://localhost:18081/
|
||||
"myrepo" has been added to your repositories
|
||||
|
||||
Building dependency release=foo, chart=$WD/temp1/foo
|
||||
Hang tight while we grab the latest from your chart repositories...
|
||||
...Successfully got an update from the "myrepo" chart repository
|
||||
Update Complete. ⎈Happy Helming!⎈
|
||||
Saving 1 charts
|
||||
Downloading raw from repo http://localhost:18080/
|
||||
Downloading raw from repo http://localhost:18081/
|
||||
Deleting outdated charts
|
||||
|
||||
Templating release=foo, chart=$WD/temp1/foo
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
Building dependency release=foo, chart=$WD/temp1/foo
|
||||
Hang tight while we grab the latest from your chart repositories...
|
||||
...Successfully got an update from the "myrepo" chart repository
|
||||
...Successfully got an update from the "istio" chart repository
|
||||
Update Complete. ⎈Happy Helming!⎈
|
||||
Saving 1 charts
|
||||
Downloading raw from repo oci://localhost:5000/myrepo
|
||||
Deleting outdated charts
|
||||
|
||||
@@ -51,7 +51,7 @@ merged environment: &{default map[] map[]}
|
||||
helm> $HelmVersion
|
||||
helm>
|
||||
Building dependency release=foo, chart=../../charts/raw-0.1.0
|
||||
exec: helm dependency build ../../charts/raw-0.1.0 --skip-refresh
|
||||
exec: helm dependency build ../../charts/raw-0.1.0
|
||||
1 release(s) found in input.yaml
|
||||
|
||||
processing 1 groups of releases in this order:
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
localChartRepoServer:
|
||||
enabled: true
|
||||
port: 18080
|
||||
port: 18082
|
||||
chartifyTempDir: temp1
|
||||
helmfileArgs:
|
||||
- --environment
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
repositories:
|
||||
- name: myrepo
|
||||
url: http://localhost:18080/
|
||||
url: http://localhost:18082/
|
||||
|
||||
environments:
|
||||
prod:
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
Adding repo myrepo http://localhost:18080/
|
||||
Adding repo myrepo http://localhost:18082/
|
||||
"myrepo" has been added to your repositories
|
||||
|
||||
Templating release=raw, chart=myrepo/raw
|
||||
|
||||
Reference in New Issue
Block a user