mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-05 15:21:20 +02:00
Use helm show chart to identify chart version
Signed-off-by: Felipe Santos <felipecassiors@gmail.com>
This commit is contained in:
@@ -14,6 +14,8 @@ import (
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"gopkg.in/yaml.v3"
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
"helm.sh/helm/v3/pkg/cli"
|
||||
"helm.sh/helm/v3/pkg/plugin"
|
||||
|
||||
@@ -599,3 +601,21 @@ func resolveOciChart(ociChart string) (ociChartURL, ociChartTag string) {
|
||||
ociChartURL = fmt.Sprintf("oci://%s", ociChart[:urlTagIndex])
|
||||
return ociChartURL, ociChartTag
|
||||
}
|
||||
|
||||
func (helm *execer) ShowChart(chartPath string) (chart.Metadata, error) {
|
||||
if !helm.IsHelm3() {
|
||||
// show chart command isn't supported in helm2
|
||||
return chart.Metadata{}, fmt.Errorf("helm show isn't supported in helm2")
|
||||
}
|
||||
var helmArgs = []string{"show", "chart", chartPath}
|
||||
out, error := helm.exec(helmArgs, map[string]string{}, nil)
|
||||
if error != nil {
|
||||
return chart.Metadata{}, error
|
||||
}
|
||||
var metadata chart.Metadata
|
||||
error = yaml.Unmarshal(out, &metadata)
|
||||
if error != nil {
|
||||
return chart.Metadata{}, error
|
||||
}
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
@@ -1008,3 +1008,32 @@ func Test_resolveOciChart(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ShowChart(t *testing.T) {
|
||||
helm2Runner := mockRunner{output: []byte("Client: v2.16.1+ge13bc94\n")}
|
||||
helm := New("helm", false, NewLogger(os.Stdout, "info"), "dev", &helm2Runner)
|
||||
_, err := helm.ShowChart("fake-chart")
|
||||
if err == nil {
|
||||
t.Error("helmexec.ShowChart() - helm show isn't supported in helm2")
|
||||
}
|
||||
|
||||
showChartRunner := mockRunner{output: []byte("name: my-chart\nversion: 3.2.0\n")}
|
||||
helm = &execer{
|
||||
helmBinary: "helm",
|
||||
version: *semver.MustParse("3.3.2"),
|
||||
logger: NewLogger(os.Stdout, "info"),
|
||||
kubeContext: "dev",
|
||||
runner: &showChartRunner,
|
||||
}
|
||||
|
||||
metadata, err := helm.ShowChart("my-chart")
|
||||
if err != nil {
|
||||
t.Errorf("helmexec.ShowChart() - unexpected error: %v", err)
|
||||
}
|
||||
if metadata.Name != "my-chart" {
|
||||
t.Errorf("helmexec.ShowChart() - expected chart name was %s, received: %s", "my-chart", metadata.Name)
|
||||
}
|
||||
if metadata.Version != "3.2.0" {
|
||||
t.Errorf("helmexec.ShowChart() - expected chart version was %s, received: %s", "3.2.0", metadata.Version)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package helmexec
|
||||
|
||||
import "helm.sh/helm/v3/pkg/chart"
|
||||
|
||||
// Version represents the version of helm
|
||||
type Version struct {
|
||||
Major int
|
||||
@@ -33,6 +35,7 @@ type Interface interface {
|
||||
IsHelm3() bool
|
||||
GetVersion() Version
|
||||
IsVersionAtLeast(versionStr string) bool
|
||||
ShowChart(chart string) (chart.Metadata, error)
|
||||
}
|
||||
|
||||
type DependencyUpdater interface {
|
||||
|
||||
Reference in New Issue
Block a user