Skip to content

Commit 498e467

Browse files
Helm Charts: Fix vendor --prune for custom dirs (#717)
* Helm Charts: Fix `vendor --prune` for custom dirs Charts with a custom directory defined are getting pruned 🤦 * Add changelog preemptively * Update changelog. Won't release yet
1 parent 348c32c commit 498e467

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Bug Fixes/Enhancements
6+
7+
- **helm**: Fix `vendor --prune` deleting charts with a custom directory
8+
**[#717](https://github.com/grafana/tanka/pull/717)**
9+
310
## 0.22.0 (2022-06-03)
411

512
### Features

pkg/helm/charts.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ func (c Charts) Vendor(prune bool) error {
107107
repositoriesUpdated := false
108108
log.Println("Vendoring...")
109109
for _, r := range c.Manifest.Requires {
110-
chartName := parseReqName(r.Chart)
111-
chartPath := filepath.Join(dir, chartName)
112-
expectedDirs[chartName] = true
113-
110+
chartSubDir := parseReqName(r.Chart)
114111
if r.Directory != "" {
115-
chartPath = filepath.Join(dir, r.Directory)
112+
chartSubDir = r.Directory
116113
}
114+
chartPath := filepath.Join(dir, chartSubDir)
115+
expectedDirs[chartSubDir] = true
117116

118117
_, err := os.Stat(chartPath)
119118
if err == nil {

pkg/helm/charts_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func TestPrune(t *testing.T) {
137137
err = c.Add([]string{"stable/[email protected]"})
138138
require.NoError(t, err)
139139

140+
// Add a chart with a directory
141+
err = c.Add([]string{"stable/[email protected]:custom-dir"})
142+
require.NoError(t, err)
143+
140144
// Add unrelated files and folders
141145
err = os.WriteFile(filepath.Join(tempDir, "charts", "foo.txt"), []byte("foo"), 0644)
142146
err = os.Mkdir(filepath.Join(tempDir, "charts", "foo"), 0755)
@@ -151,9 +155,11 @@ func TestPrune(t *testing.T) {
151155
listResult, err := os.ReadDir(filepath.Join(tempDir, "charts"))
152156
assert.NoError(t, err)
153157
if prune {
154-
assert.Equal(t, 1, len(listResult))
158+
assert.Equal(t, 2, len(listResult))
159+
assert.Equal(t, "custom-dir", listResult[0].Name())
160+
assert.Equal(t, "prometheus", listResult[1].Name())
155161
} else {
156-
assert.Equal(t, 3, len(listResult))
162+
assert.Equal(t, 4, len(listResult))
157163
chartContent, err := os.ReadFile(filepath.Join(tempDir, "charts", "foo", "Chart.yaml"))
158164
assert.NoError(t, err)
159165
assert.Contains(t, string(chartContent), `foo`)

0 commit comments

Comments
 (0)