Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #490 from fluxcd/bugfix/issue-469
Browse files Browse the repository at this point in the history
Fix: prevent spurious upgrades for semver ranges
  • Loading branch information
hiddeco committed Jul 20, 2020
2 parents 0ed00cd + 67150c1 commit 8d35598
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/helm/helm.go
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions 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
}
15 changes: 15 additions & 0 deletions 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
}
8 changes: 6 additions & 2 deletions pkg/release/release.go
Expand Up @@ -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")
}
Expand Down

0 comments on commit 8d35598

Please sign in to comment.