Skip to content

Commit

Permalink
Merge pull request #1371 from pscarey/helm-watch-subcharts
Browse files Browse the repository at this point in the history
Automatically watch helm subcharts when skipBuildDependencies is enabled
  • Loading branch information
nkubala authored May 7, 2019
2 parents d303b00 + 9216981 commit ceda301
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
9 changes: 9 additions & 0 deletions docs/content/en/docs/how-tos/deployers/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ Each `release` includes the following fields:

{{< schema root="HelmRelease" >}}

### Helm Build Dependencies

The `skipBuildDependencies` flag toggles whether depenedencies of the Helm chart are built with the `helm dep build` command. This command manipulates files inside the `charts` subfolder of the specified Helm chart.

If `skipBuildDependencies` is `false` then `skaffold dev` does **not** watch the `charts` subfolder of the Helm chart, in order to prevent a build loop - the actions of `helm dep build` always trigger another build.

If `skipBuildDependencies` is `true` then `skaffold dev` watches all files inside the Helm chart.


### Example

The following `deploy` section instructs Skaffold to deploy
Expand Down
12 changes: 10 additions & 2 deletions pkg/skaffold/deploy/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,17 @@ func (h *HelmDeployer) Dependencies() ([]string, error) {
if err != nil {
return errors.Wrapf(err, "failure accessing path '%s'", path)
}
if !info.IsDir() && !strings.HasPrefix(path, chartDepsDir) {
deps = append(deps, path)

if !info.IsDir() {
if !strings.HasPrefix(path, chartDepsDir) || release.SkipBuildDependencies {
// We can always add a dependency if it is not contained in our chartDepsDir.
// However, if the file is in our chartDepsDir, we can only include the file
// if we are not running the helm dep build phase, as that modifies files inside
// the chartDepsDir and results in an infinite build loop.
deps = append(deps, path)
}
}

return nil
})
if err != nil {
Expand Down
42 changes: 27 additions & 15 deletions pkg/skaffold/deploy/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,33 @@ func TestExtractChartFilename(t *testing.T) {

func TestHelmDependencies(t *testing.T) {
var tests = []struct {
description string
files []string
valuesFiles []string
expected func(folder *testutil.TempDir) []string
description string
files []string
valuesFiles []string
skipBuildDependencies bool
expected func(folder *testutil.TempDir) []string
}{
{
description: "charts dir is excluded",
files: []string{"Chart.yaml", "charts/xyz.tar", "templates/deploy.yaml"},
description: "charts dir is included when skipBuildDependencies is true",
files: []string{"Chart.yaml", "charts/xyz.tar", "templates/deploy.yaml"},
skipBuildDependencies: true,
expected: func(folder *testutil.TempDir) []string {
return []string{folder.Path("Chart.yaml"), folder.Path("charts/xyz.tar"), folder.Path("templates/deploy.yaml")}
},
},
{
description: "charts dir is excluded when skipBuildDependencies is false",
files: []string{"Chart.yaml", "charts/xyz.tar", "templates/deploy.yaml"},
skipBuildDependencies: false,
expected: func(folder *testutil.TempDir) []string {
return []string{folder.Path("Chart.yaml"), folder.Path("templates/deploy.yaml")}
},
},
{
description: "values file is included",
files: []string{"Chart.yaml"},
valuesFiles: []string{"/folder/values.yaml"},
description: "values file is included",
skipBuildDependencies: false,
files: []string{"Chart.yaml"},
valuesFiles: []string{"/folder/values.yaml"},
expected: func(folder *testutil.TempDir) []string {
return []string{"/folder/values.yaml", folder.Path("Chart.yaml")}
},
Expand All @@ -601,12 +612,13 @@ func TestHelmDependencies(t *testing.T) {
deployer := NewHelmDeployer(makeRunContext(&latest.HelmDeploy{
Releases: []latest.HelmRelease{
{
Name: "skaffold-helm",
ChartPath: folder.Root(),
ValuesFiles: tt.valuesFiles,
Values: map[string]string{"image": "skaffold-helm"},
Overrides: schemautil.HelmOverrides{Values: map[string]interface{}{"foo": "bar"}},
SetValues: map[string]string{"some.key": "somevalue"},
Name: "skaffold-helm",
ChartPath: folder.Root(),
ValuesFiles: tt.valuesFiles,
Values: map[string]string{"image": "skaffold-helm"},
Overrides: schemautil.HelmOverrides{Values: map[string]interface{}{"foo": "bar"}},
SetValues: map[string]string{"some.key": "somevalue"},
SkipBuildDependencies: tt.skipBuildDependencies,
},
},
}, false))
Expand Down

0 comments on commit ceda301

Please sign in to comment.