Skip to content

Commit

Permalink
Fix helm chart resolution issue (#1491)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Tayanovskyy <anton@pulumi.com>
  • Loading branch information
t0yv0 and t0yv0 committed Mar 10, 2021
1 parent e4e32f8 commit bd94a3a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
- Fix bug where rendering manifests results in files being overwritten by subsequent resources with the same kind and name, but different namespace (https://github.com/pulumi/pulumi-kubernetes/pull/1429)
- Update pulumi dependency to fix python Resource.get() functions (https://github.com/pulumi/pulumi-kubernetes/pull/1480)
- Upgrade to Go1.16 (https://github.com/pulumi/pulumi-kubernetes/pull/1486)
- Fix bug preventing helm chart being located in bitnami repo (https://github.com/pulumi/pulumi-kubernetes/pull/1491)

## 2.8.2 (February 23, 2021)

Expand Down
33 changes: 25 additions & 8 deletions provider/pkg/provider/invoke_helm_template.go
Expand Up @@ -160,21 +160,38 @@ func (c *chart) fetch() error {
p.Version = c.opts.HelmFetchOpts.Version
} // If both are set, prefer the top-level version over the FetchOpts version.

chartRef := func() string {
if len(c.opts.Repo) > 0 {
return fmt.Sprintf("%s/%s", strings.TrimSuffix(c.opts.Repo, "/"), c.opts.Chart)
}

return c.opts.Chart
}
chartRef := normalizeChartRef(c.opts.Repo, p.RepoURL, c.opts.Chart)

_, err := p.Run(chartRef())
_, err := p.Run(chartRef)
if err != nil {
return pkgerrors.Wrap(err, "failed to pull chart")
}
return nil
}

// In case URL is not known we prefix the chart ref with the repoName,
// so for example "apache" becomes "bitnami/apache". We should not
// prefix it when URL is known, as that results in an error such as:
//
// failed to pull chart: chart "bitnami/apache" version "1.0.0" not
// found in https://charts.bitnami.com/bitnami repository
func normalizeChartRef(repoName string, repoUrl string, originalChartRef string) string {

// If URL is known, do not prefix
if len(repoUrl) > 0 {
return originalChartRef
}

// Add a prefix if repoName is known and ref is not already prefixed
prefix := fmt.Sprintf("%s/", strings.TrimSuffix(repoName, "/"))
if len(repoName) > 0 && !strings.HasPrefix(originalChartRef, prefix) {
return fmt.Sprintf("%s%s", prefix, originalChartRef)
}

// Otherwise leave as-is
return originalChartRef
}

// template runs the `helm template` action to produce YAML from the Chart configuration.
func (c *chart) template() (string, error) {
cfg := &action.Configuration{
Expand Down
19 changes: 19 additions & 0 deletions provider/pkg/provider/invoke_helm_template_test.go
@@ -0,0 +1,19 @@
package provider

import (
"testing"
)

func TestNormalizeChartRef(t *testing.T) {
check := func(repoName string, repoUrl string, originalChartRef string, expect string) {
actual := normalizeChartRef(repoName, repoUrl, originalChartRef)
if actual != expect {
t.Errorf("Expected normalizeChartRef(%s, %s, %s) to be %s but got %s",
repoName, repoUrl, originalChartRef, expect, actual)
}
}

check("bitnami", "https://charts.bitnami.com/bitnami", "apache", "apache")
check("bitnami", "", "apache", "bitnami/apache")
check("bitnami", "", "bitnami/apache", "bitnami/apache")
}

0 comments on commit bd94a3a

Please sign in to comment.