Use helm show chart to identify chart version

Signed-off-by: Felipe Santos <felipecassiors@gmail.com>
This commit is contained in:
Felipe Santos
2022-10-03 22:04:08 -03:00
parent 3165551f9a
commit f15bdbbb0c
17 changed files with 115 additions and 24 deletions
+20
View File
@@ -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
}