Skip to content

Commit

Permalink
Add support for adhoc dependency to local chart
Browse files Browse the repository at this point in the history
Helmfile has been providing a feature called "adhoc chart dependency" that basially enabled you to add Chart.yaml `dependencies` entry adhocly without forking or modifying the chart.

It was missing the support for using a local chart as the adhoc dependency. This patch adds that.

Usage:

`releases[].dependencies[].chart` is enhanced to accept the fs path to the local chart:

```
releases:
- name: foo
  chart: ./path/to/foo
  dependencies:
  - chart: ./path/to/bar
```

Resolves #1762
  • Loading branch information
mumoshu committed Apr 9, 2021
1 parent 74cd2bc commit 1b9b081
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/spf13/cobra v1.1.1
github.com/tatsushid/go-prettytable v0.0.0-20141013043238-ed2d14c29939
github.com/urfave/cli v1.22.5
github.com/variantdev/chartify v0.7.3
github.com/variantdev/chartify v0.8.0
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363
github.com/variantdev/vals v0.13.0
go.uber.org/multierr v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ github.com/variantdev/chartify v0.7.2 h1:H7a9xD4rfyKkLDhCO/Oj3VfYnJRb92Dqk+GR6vp
github.com/variantdev/chartify v0.7.2/go.mod h1:qF4XzQlkfH/6k2jAi1hLas+lK4zSCa8kY+r5JdmLA68=
github.com/variantdev/chartify v0.7.3 h1:uX0mN8PmYHZDWILcg41sQfasJ7TT/CYnYWSmDgsIBIA=
github.com/variantdev/chartify v0.7.3/go.mod h1:qF4XzQlkfH/6k2jAi1hLas+lK4zSCa8kY+r5JdmLA68=
github.com/variantdev/chartify v0.8.0 h1:yIBsS/dIUeMjWP8U6JWlT3PM0Lky7en9QBi+MgDu2U8=
github.com/variantdev/chartify v0.8.0/go.mod h1:qF4XzQlkfH/6k2jAi1hLas+lK4zSCa8kY+r5JdmLA68=
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363 h1:KrfQBEUn+wEOQ/6UIfoqRDvn+Q/wZridQ7t0G1vQqKE=
github.com/variantdev/dag v0.0.0-20191028002400-bb0b3c785363/go.mod h1:pH1TQsNSLj2uxMo9NNl9zdGy01Wtn+/2MT96BrKmVyE=
github.com/variantdev/vals v0.13.0 h1:zdtTBjoWKkUGdFauxETkDVjqWXdjUNwI+ggWcUmpxv8=
Expand Down
53 changes: 26 additions & 27 deletions pkg/state/helmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/roboll/helmfile/pkg/helmexec"
"github.com/roboll/helmfile/pkg/remote"
Expand Down Expand Up @@ -85,7 +84,7 @@ func (st *HelmState) goGetterChart(chart, dir, cacheDir string, force bool) (str
}

func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSpec, chart string, workerIndex int) (*Chartify, func(), error) {
chartify := &Chartify{
c := &Chartify{
Opts: &chartify.ChartifyOpts{
WorkaroundOutputDirIssue: true,
EnableKustomizeAlphaPlugins: true,
Expand All @@ -110,25 +109,25 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp
}

for _, d := range release.Dependencies {
var dep string

if d.Alias != "" {
dep += d.Alias + "="
} else {
a := strings.Split(d.Chart, "/")

chart := a[len(a)-1]

dep += chart + "="
}

dep += d.Chart

if d.Version != "" {
dep += ":" + d.Version
chart := d.Chart
if st.directoryExistsAt(chart) {
var err error

// Otherwise helm-dependency-up on the temporary chart generated by chartify ends up errors like:
// Error: directory /tmp/chartify945964195/myapp-57fb4495cf/test/integration/charts/httpbin not found]
// which is due to that the temporary chart is generated outside of the current working directory/basePath,
// and therefore the relative path in `chart` points to somewhere inexistent.
chart, err = filepath.Abs(filepath.Join(st.basePath, chart))
if err != nil {
return nil, clean, err
}
}

chartify.Opts.AdhocChartDependencies = append(chartify.Opts.AdhocChartDependencies, dep)
c.Opts.AdhocChartDependencies = append(c.Opts.AdhocChartDependencies, chartify.ChartDependency{
Alias: d.Alias,
Chart: chart,
Version: d.Version,
})

shouldRun = true
}
Expand All @@ -143,7 +142,7 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp
filesNeedCleaning = append(filesNeedCleaning, generatedFiles...)

for _, f := range generatedFiles {
chartify.Opts.JsonPatches = append(chartify.Opts.JsonPatches, f)
c.Opts.JsonPatches = append(c.Opts.JsonPatches, f)
}

shouldRun = true
Expand All @@ -157,7 +156,7 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp
}

for _, f := range generatedFiles {
chartify.Opts.StrategicMergePatches = append(chartify.Opts.StrategicMergePatches, f)
c.Opts.StrategicMergePatches = append(c.Opts.StrategicMergePatches, f)
}

filesNeedCleaning = append(filesNeedCleaning, generatedFiles...)
Expand All @@ -173,7 +172,7 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp
}

for _, f := range generatedFiles {
chartify.Opts.Transformers = append(chartify.Opts.Transformers, f)
c.Opts.Transformers = append(c.Opts.Transformers, f)
}

filesNeedCleaning = append(filesNeedCleaning, generatedFiles...)
Expand All @@ -182,7 +181,7 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp
}

if release.ForceNamespace != "" {
chartify.Opts.OverrideNamespace = release.ForceNamespace
c.Opts.OverrideNamespace = release.ForceNamespace

shouldRun = true
}
Expand All @@ -195,11 +194,11 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp

filesNeedCleaning = append(filesNeedCleaning, generatedFiles...)

chartify.Opts.ValuesFiles = generatedFiles
chartify.Opts.TemplateData = st.newReleaseTemplateData(release)
chartify.Opts.TemplateFuncs = st.newReleaseTemplateFuncMap(dir)
c.Opts.ValuesFiles = generatedFiles
c.Opts.TemplateData = st.newReleaseTemplateData(release)
c.Opts.TemplateFuncs = st.newReleaseTemplateFuncMap(dir)

return chartify, clean, nil
return c, clean, nil
}

return nil, clean, nil
Expand Down

0 comments on commit 1b9b081

Please sign in to comment.