From 95ab9e3a1ef0640451318d168192be9451b2dbe4 Mon Sep 17 00:00:00 2001 From: Daniel Lipovetsky Date: Fri, 8 Nov 2024 10:51:38 -0800 Subject: [PATCH] fix: Allow TLS to pull chart from OCI repository Previously, we created our own registryClient. We were responsible for configuring TLS for the client, but did not. We now allow helm to create the client for us. Because we previously did notcustomize the client in any way, we only gain functionality, and lose none. --- cmd/mindthegap/create/bundle/bundle.go | 1 - helm/client.go | 26 +++----------------------- test/e2e/helmbundle/helpers/helpers.go | 1 - 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/cmd/mindthegap/create/bundle/bundle.go b/cmd/mindthegap/create/bundle/bundle.go index f2d69253..56d54730 100644 --- a/cmd/mindthegap/create/bundle/bundle.go +++ b/cmd/mindthegap/create/bundle/bundle.go @@ -400,7 +400,6 @@ func pullCharts( repoConfig.RepoURL, chartName, chartVersion, - []helm.ConfigOpt{helm.RegistryClientConfigOpt()}, opts..., ) if err != nil { diff --git a/helm/client.go b/helm/client.go index 7b112d24..54638b21 100644 --- a/helm/client.go +++ b/helm/client.go @@ -99,38 +99,18 @@ func CAFileOpt(caFile string) action.PullOpt { } } -type ConfigOpt func(*action.Configuration) error - -func RegistryClientConfigOpt(opts ...registry.ClientOption) ConfigOpt { - return func(cfg *action.Configuration) error { - cl, err := registry.NewClient(opts...) - if err != nil { - return fmt.Errorf("failed to create registry client: %w", err) - } - - cfg.RegistryClient = cl - - return nil +func CertFileOpt(certFile string) action.PullOpt { + return func(p *action.Pull) { + p.CertFile = certFile } } func (c *Client) GetChartFromRepo( outputDir, repoURL, chartName, chartVersion string, - configOpts []ConfigOpt, extraPullOpts ...action.PullOpt, ) (string, error) { cfg := &action.Configuration{Log: c.out.V(4).Infof} - if registry.IsOCI(chartName) { - configOpts = append([]ConfigOpt{RegistryClientConfigOpt()}, configOpts...) - } - - for _, f := range configOpts { - if err := f(cfg); err != nil { - return "", fmt.Errorf("failed to configure helm client: %w", err) - } - } - pull := action.NewPullWithOpts( append( extraPullOpts, diff --git a/test/e2e/helmbundle/helpers/helpers.go b/test/e2e/helmbundle/helpers/helpers.go index 8a03847b..e7f1fc0f 100644 --- a/test/e2e/helmbundle/helpers/helpers.go +++ b/test/e2e/helmbundle/helpers/helpers.go @@ -194,7 +194,6 @@ func ValidateChartIsAvailable( "", fmt.Sprintf("%s://%s:%d/charts/%s", helm.OCIScheme, addr, port, chartName), chartVersion, - []helm.ConfigOpt{helm.RegistryClientConfigOpt()}, pullOpts..., ) gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred())