Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix helm chart resolution issue #1491

Merged
merged 1 commit into from Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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")
}