Skip to content

Commit

Permalink
fix: Allow TLS to pull chart from OCI repository (#804)
Browse files Browse the repository at this point in the history
This fix allows us to test the `serve bundle` command using a TLS
client.

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 not customize the client in
any way, we only gain functionality, and lose none.

---------

Co-authored-by: Jimmi Dyson <[email protected]>
  • Loading branch information
dlipovetsky and jimmidyson authored Nov 11, 2024
1 parent 2f2e324 commit 8687f4e
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 33 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: 0 additions & 26 deletions helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,38 +99,12 @@ 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 (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
9 changes: 5 additions & 4 deletions test/e2e/helmbundle/serve_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/mesosphere/mindthegap/test/e2e/helmbundle/helpers"
)

var _ = Describe("Serve Bundle", func() {
var _ = Describe("Serve Helm Bundle", func() {
var (
bundleFile string
cmd *cobra.Command
Expand Down Expand Up @@ -93,7 +93,7 @@ var _ = Describe("Serve Bundle", func() {
ipAddr := helpers.GetFirstNonLoopbackIP(GinkgoT())

tempCertDir := GinkgoT().TempDir()
_, _, certFile, keyFile := helpers.GenerateCertificateAndKeyWithIPSAN(
caCertFile, _, certFile, keyFile := helpers.GenerateCertificateAndKeyWithIPSAN(
GinkgoT(),
tempCertDir,
ipAddr,
Expand Down Expand Up @@ -126,8 +126,9 @@ var _ = Describe("Serve Bundle", func() {

helpers.WaitForTCPPort(GinkgoT(), ipAddr.String(), port)

// TODO Reenable once Helm supports custom CA certs and self-signed certs.
// helpers.ValidateChartIsAvailable(GinkgoT(), "127.0.0.1", port, "podinfo", "6.2.0", helm.CAFileOpt(caCertFile))
helpers.ValidateChartIsAvailable(GinkgoT(), ipAddr.String(), port, "podinfo", "6.2.0", helm.CAFileOpt(caCertFile))

helpers.ValidateChartIsAvailable(GinkgoT(), ipAddr.String(), port, "node-feature-discovery", "0.15.2", helm.CAFileOpt(caCertFile))

close(stopCh)

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/imagebundle/serve_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/mesosphere/mindthegap/test/e2e/imagebundle/helpers"
)

var _ = Describe("Serve Bundle", func() {
var _ = Describe("Serve Image Bundle", func() {
var (
bundleFile string
cmd *cobra.Command
Expand Down

0 comments on commit 8687f4e

Please sign in to comment.