Fix the logic of helmfile deps and add tests. #1588
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
helmfile.yaml
:./charts/example/Chart.yaml
:When I run
helmfile deps --skip-repos
with the helmfile.yaml above, it skips updating the deps of the local chartexample
:What I was expecting is that helmfile updates all the dependencies of the chart, like what helmfiles does without the option
--skip-repos
(but skips adding repos of course):The Problem
While I was digging into this issue, I found that the problem is not caused by
--skip-repos
itself.In fact, logics in
UpdateDeps
:helmfile/pkg/state/state.go
Lines 1928 to 1937 in f6bf885
will never get executed, as
release.Chart
is already "normalized path", which means, it won't be considered as a local chart anymore. Here is where the chart get "normalized":helmfile/pkg/app/run.go
Lines 62 to 74 in f6bf885
releaseToChart
contains the paths proceeded bynormalizeChart(st.basePath, chartPath)
, andrel.Chart = chart
overrides the original chart paths in releases.In order to fix that, I've decided not to break the current behavior of
PrepareCharts
but change the logic of determining if it's a local chart.Firstly, I changed
if isLocalChart(release.Chart)
toif pathExists(release.Chart)
. However, I changed it again to the funcDirectoryExistsAt
to make it mockable in unit tests.Other Changes in the PR
Add
SkipDeps
in structChartPrepareOptions
PrepareCharts
skips executinghelm dep build
whenSkipRepos
is true:helmfile/pkg/state/state.go
Lines 943 to 948 in f6bf885
helmfile/pkg/state/state.go
Lines 1086 to 1090 in f6bf885
Therefore, if I run
helmfile deps --skip-repos
:st.runHelmDepBuilds
. ✅UpdateDeps
. ✅If run
helmfile deps
:st.runHelmDepBuilds
. ❌ (Unnecessary)UpdateDeps
. ✅PrepareCharts shouldn't use
SkipRepos
as the condition of runninghelm dep build
or not. So I added another flagSkipDeps
in struct to control whether PrepareCharts needs to build the deps.Helper functions in testfs
helmfile/pkg/testhelper/testfs.go
Lines 54 to 62 in f6bf885
Determining absolute paths with
strings.Contains
sounds not ideal. Changed tostrings.HasPrefix(path, "/")
.helmfile/pkg/testhelper/testfs.go
Lines 64 to 74 in f6bf885
path[0] == '/'
can lead to nil pointer error with empty stringpath
. Changed tostrings.HasPrefix(path, "/")
.Add and fix tests
TestHelmState_UpdateDeps
toTest_normalizeChart
.TestHelmState_UpdateDeps
.TestDeps
inpkg/app/app_test.go
.pkg/remote/remote_test.go
with respect to the changes oftestfs
.