Skip to content

Commit

Permalink
fix: Allow TLS to pull chart from OCI repository
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dlipovetsky committed Nov 8, 2024
1 parent 10cf294 commit 95ab9e3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
1 change: 0 additions & 1 deletion cmd/mindthegap/create/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ func pullCharts(
repoConfig.RepoURL,
chartName,
chartVersion,
[]helm.ConfigOpt{helm.RegistryClientConfigOpt()},
opts...,
)
if err != nil {
Expand Down
26 changes: 3 additions & 23 deletions helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion test/e2e/helmbundle/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 95ab9e3

Please sign in to comment.