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: Support published Helm charts with different name format #695

Merged
merged 1 commit into from
Apr 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 47 additions & 14 deletions helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
"net/url"
"os"
"path/filepath"
"strings"

"github.com/hashicorp/go-getter"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/cli"
helmgetter "helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/registry"
"helm.sh/helm/v3/pkg/repo"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -141,25 +143,56 @@ func (c *Client) GetChartFromRepo(
)...,
)

helmOutput, err := pull.Run(chartName)
// Charts pulled from OCI registries will have the scheme "oci://" for the chart name.
// We can use the built-in downloader to fetch these charts.
if strings.HasPrefix(chartName, OCIScheme) {
helmOutput, err := pull.Run(chartName)
if err != nil {
return "", fmt.Errorf(
"failed to fetch chart %s:%s from %s: %w, output:\n\n%s",
chartName,
chartVersion,
repoURL,
err,
helmOutput,
)
}
if helmOutput != "" {
c.out.V(4).Info(helmOutput)
}

return filepath.Join(
outputDir,
fmt.Sprintf("%s-%s.tgz", filepath.Base(chartName), chartVersion),
), nil
}

// For non-OCI charts, we need to discover the chart URL first to be able to handle
// different chart names to the expected `<chartName>-<chartVersion>.tgz` format.
chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(
pull.RepoURL,
pull.Username,
pull.Password,
chartName,
chartVersion,
pull.CertFile,
pull.KeyFile,
pull.CaFile,
pull.InsecureSkipTLSverify,
pull.PassCredentialsAll,
helmgetter.All(pull.Settings),
)
if err != nil {
return "", fmt.Errorf(
"failed to fetch chart %s:%s from %s: %w, output:\n\n%s",
"failed to discover chart URL for %s:%s from %s: %w",
chartName,
chartVersion,
repoURL,
err,
helmOutput,
)
}
if helmOutput != "" {
c.out.V(4).Info(helmOutput)
}

return filepath.Join(
outputDir,
fmt.Sprintf("%s-%s.tgz", filepath.Base(chartName), chartVersion),
), nil
return c.GetChartFromURL(outputDir, chartURL, c.tempDir)
}

func (c *Client) GetChartFromURL(outputDir, chartURL, workingDir string) (string, error) {
Expand All @@ -180,11 +213,11 @@ func (c *Client) GetChartFromURL(outputDir, chartURL, workingDir string) (string
u.RawQuery = q.Encode()

dst := filepath.Join(outputDir, filepath.Base(chartURL))
err = getter.GetFile(dst, u.String(), func(c *getter.Client) error {
c.Pwd = workingDir
err = getter.GetFile(dst, u.String(), func(getterClient *getter.Client) error {
getterClient.Pwd = workingDir
return nil
}, func(c *getter.Client) error {
c.Getters = getters
}, func(getterClient *getter.Client) error {
getterClient.Getters = getters
return nil
})
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/helmbundle/push_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ var _ = Describe("Push Bundle", func() {
helm.InsecureSkipTLSverifyOpt(),
)

helpers.ValidateChartIsAvailable(
GinkgoT(),
"127.0.0.1",
port,
"node-feature-discovery",
"0.15.2",
helm.InsecureSkipTLSverifyOpt(),
)

Expect(reg.Shutdown(context.Background())).To((Succeed()))

Eventually(done).Should(BeClosed())
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/helmbundle/serve_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ var _ = Describe("Serve Bundle", func() {
helm.InsecureSkipTLSverifyOpt(),
)

helpers.ValidateChartIsAvailable(
GinkgoT(),
"127.0.0.1",
port,
"node-feature-discovery",
"0.15.2",
helm.InsecureSkipTLSverifyOpt(),
)

close(stopCh)

Eventually(done).Should(BeClosed())
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/helmbundle/testdata/create-success.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
# SPDX-License-Identifier: Apache-2.0

repositories:
jetstack:
stefanprodan:
repoURL: https://stefanprodan.github.io/podinfo
charts:
podinfo:
- "6.2.0"
- "6.1.0"
nfd:
repoURL: https://kubernetes-sigs.github.io/node-feature-discovery/charts/
charts:
node-feature-discovery:
- "0.15.2"
Loading