diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index 64cbaeb0a..3ed1b43a8 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -18,6 +18,7 @@ type Client interface { Pull(ref, version, dest string) (string, error) PullWithRepoURL(repoURL, name, version, dest string) (string, error) Uninstall(releaseName string, opts UninstallOptions) error + GetChartRevision(chartPath string) (string, error) Version() string } diff --git a/pkg/helm/v2/chart.go b/pkg/helm/v2/chart.go new file mode 100644 index 000000000..4562a242e --- /dev/null +++ b/pkg/helm/v2/chart.go @@ -0,0 +1,15 @@ +package v2 + +import ( + "fmt" + + "k8s.io/helm/pkg/chartutil" +) + +func (h *HelmV2) GetChartRevision(chartPath string) (string, error) { + chartRequested, err := chartutil.Load(chartPath) + if err != nil { + return "", fmt.Errorf("failed to load chart to determine revision: %w", err) + } + return chartRequested.Metadata.Version, nil +} diff --git a/pkg/helm/v3/chart.go b/pkg/helm/v3/chart.go new file mode 100644 index 000000000..3749f8944 --- /dev/null +++ b/pkg/helm/v3/chart.go @@ -0,0 +1,15 @@ +package v3 + +import ( + "fmt" + + "helm.sh/helm/v3/pkg/chart/loader" +) + +func (h *HelmV3) GetChartRevision(chartPath string) (string, error) { + chartRequested, err := loader.Load(chartPath) + if err != nil { + return "", fmt.Errorf("failed to load chart to determine revision: %w", err) + } + return chartRequested.Metadata.Version, nil +} diff --git a/pkg/release/release.go b/pkg/release/release.go index 3205fc3df..30de39bef 100644 --- a/pkg/release/release.go +++ b/pkg/release/release.go @@ -158,11 +158,15 @@ func (r *Release) prepareChart(client helm.Client, hr *apiV1.HelmRelease) (chart case hr.Spec.RepoChartSource != nil && hr.Spec.RepoURL != "" && hr.Spec.Name != "" && hr.Spec.Version != "": var err error - chartPath, changed, err = chartsync.EnsureChartFetched(client, r.config.ChartCache, hr.Spec.RepoChartSource) - revision = hr.Spec.RepoChartSource.Version + chartPath, _, err = chartsync.EnsureChartFetched(client, r.config.ChartCache, hr.Spec.RepoChartSource) if err != nil { return chart{}, nil, err } + revision, err = client.GetChartRevision(chartPath) + if err != nil { + return chart{}, nil, err + } + changed = hr.Status.LastAttemptedRevision != revision default: return chart{}, nil, fmt.Errorf("could not find valid chart source configuration for release") }