diff --git a/helm/client.go b/helm/client.go index f44a688e..7b112d24 100644 --- a/helm/client.go +++ b/helm/client.go @@ -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" @@ -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 `-.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) { @@ -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 { diff --git a/test/e2e/helmbundle/push_bundle_test.go b/test/e2e/helmbundle/push_bundle_test.go index 511980c5..71fca774 100644 --- a/test/e2e/helmbundle/push_bundle_test.go +++ b/test/e2e/helmbundle/push_bundle_test.go @@ -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()) diff --git a/test/e2e/helmbundle/serve_bundle_test.go b/test/e2e/helmbundle/serve_bundle_test.go index 1b47a789..24a324f4 100644 --- a/test/e2e/helmbundle/serve_bundle_test.go +++ b/test/e2e/helmbundle/serve_bundle_test.go @@ -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()) diff --git a/test/e2e/helmbundle/testdata/create-success.yaml b/test/e2e/helmbundle/testdata/create-success.yaml index c22a84ef..caa56cf6 100644 --- a/test/e2e/helmbundle/testdata/create-success.yaml +++ b/test/e2e/helmbundle/testdata/create-success.yaml @@ -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"