feat: add go-getter suppport for ad-hoc
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
b7233d1238
commit
1781ac6a8c
|
|
@ -45,21 +45,7 @@ type Chartify struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) downloadChartWithGoGetter(r *ReleaseSpec) (string, error) {
|
func (st *HelmState) downloadChartWithGoGetter(r *ReleaseSpec) (string, error) {
|
||||||
var pathElems []string
|
return st.goGetterChart(r.Chart, r.Directory, r.CacheDir(), r.ForceGoGetter)
|
||||||
|
|
||||||
if r.Namespace != "" {
|
|
||||||
pathElems = append(pathElems, r.Namespace)
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.KubeContext != "" {
|
|
||||||
pathElems = append(pathElems, r.KubeContext)
|
|
||||||
}
|
|
||||||
|
|
||||||
pathElems = append(pathElems, r.Name)
|
|
||||||
|
|
||||||
cacheDir := filepath.Join(pathElems...)
|
|
||||||
|
|
||||||
return st.goGetterChart(r.Chart, r.Directory, cacheDir, r.ForceGoGetter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) goGetterChart(chart, dir, cacheDir string, force bool) (string, error) {
|
func (st *HelmState) goGetterChart(chart, dir, cacheDir string, force bool) (string, error) {
|
||||||
|
|
@ -116,23 +102,15 @@ func (st *HelmState) PrepareChartify(helm helmexec.Interface, release *ReleaseSp
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range release.Dependencies {
|
for _, d := range release.Dependencies {
|
||||||
chart := d.Chart
|
dependenceChart, err := st.goGetterChart(d.Chart, "", release.CacheDir(), release.ForceGoGetter)
|
||||||
if st.fs.DirectoryExistsAt(chart) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// Otherwise helm-dependency-up on the temporary chart generated by chartify ends up errors like:
|
if err != nil {
|
||||||
// Error: directory /tmp/chartify945964195/myapp-57fb4495cf/test/integration/charts/httpbin not found]
|
return nil, clean, err
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Opts.AdhocChartDependencies = append(c.Opts.AdhocChartDependencies, chartify.ChartDependency{
|
c.Opts.AdhocChartDependencies = append(c.Opts.AdhocChartDependencies, chartify.ChartDependency{
|
||||||
Alias: d.Alias,
|
Alias: d.Alias,
|
||||||
Chart: chart,
|
Chart: dependenceChart,
|
||||||
Version: d.Version,
|
Version: d.Version,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/helmfile/helmfile/pkg/maputil"
|
"github.com/helmfile/helmfile/pkg/maputil"
|
||||||
"github.com/helmfile/helmfile/pkg/tmpl"
|
"github.com/helmfile/helmfile/pkg/tmpl"
|
||||||
|
|
@ -220,3 +221,20 @@ func (r ReleaseSpec) Clone() (*ReleaseSpec, error) {
|
||||||
func (r ReleaseSpec) Desired() bool {
|
func (r ReleaseSpec) Desired() bool {
|
||||||
return r.Installed == nil || *r.Installed
|
return r.Installed == nil || *r.Installed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CacheDir returns the cache directory for the release.
|
||||||
|
func (r ReleaseSpec) CacheDir() string {
|
||||||
|
var pathElems []string
|
||||||
|
|
||||||
|
if r.Namespace != "" {
|
||||||
|
pathElems = append(pathElems, r.Namespace)
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.KubeContext != "" {
|
||||||
|
pathElems = append(pathElems, r.KubeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
pathElems = append(pathElems, r.Name)
|
||||||
|
|
||||||
|
return filepath.Join(pathElems...)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,3 +43,60 @@ func TestExecuteTemplateExpressions(t *testing.T) {
|
||||||
require.NoErrorf(t, err, "failed to execute template expressions: %v", err)
|
require.NoErrorf(t, err, "failed to execute template expressions: %v", err)
|
||||||
require.Equalf(t, result.ValuesTemplate[0].(map[string]interface{})["fullnameOverride"], "foo", "failed to execute template expressions")
|
require.Equalf(t, result.ValuesTemplate[0].(map[string]interface{})["fullnameOverride"], "foo", "failed to execute template expressions")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCacheDir(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
rs ReleaseSpec
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
rs: ReleaseSpec{},
|
||||||
|
want: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "namespace",
|
||||||
|
rs: ReleaseSpec{Namespace: "baz"},
|
||||||
|
want: "baz",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "kubeContext",
|
||||||
|
rs: ReleaseSpec{KubeContext: "qux"},
|
||||||
|
want: "qux",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "name",
|
||||||
|
rs: ReleaseSpec{Name: "foo"},
|
||||||
|
want: "foo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "namespace and kubeContext",
|
||||||
|
rs: ReleaseSpec{Namespace: "baz", KubeContext: "qux"},
|
||||||
|
want: "baz/qux",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "namespace and name",
|
||||||
|
rs: ReleaseSpec{Namespace: "baz", Name: "foo"},
|
||||||
|
want: "baz/foo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "kubeContext and name",
|
||||||
|
rs: ReleaseSpec{KubeContext: "qux", Name: "foo"},
|
||||||
|
want: "qux/foo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "namespace and kubeContext and name",
|
||||||
|
rs: ReleaseSpec{Namespace: "baz", KubeContext: "qux", Name: "foo"},
|
||||||
|
want: "baz/qux/foo",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := tt.rs.CacheDir(); got != tt.want {
|
||||||
|
t.Errorf("ReleaseSpec.CacheDir() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue