diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 49f787d3..dc766399 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -15,6 +15,7 @@ ## Bug Fixes * [#352](https://github.com/suse-edge/edge-image-builder/issues/352) - Resizing raw images results in dracut-pre-mount failure +* [#355](https://github.com/suse-edge/edge-image-builder/issues/355) - Helm fails getting charts stored in unauthenticated OCI registries * [#359](https://github.com/suse-edge/edge-image-builder/issues/359) - Helm validation does not check if a chart uses an undefined repository --- diff --git a/pkg/registry/helm.go b/pkg/registry/helm.go index 5b461085..c2dd48f7 100644 --- a/pkg/registry/helm.go +++ b/pkg/registry/helm.go @@ -77,8 +77,10 @@ func downloadChart(chart *image.HelmChart, repo *image.HelmRepository, helmClien if err := helmClient.AddRepo(repo); err != nil { return "", fmt.Errorf("adding repo: %w", err) } - } else if err := helmClient.RegistryLogin(repo); err != nil { - return "", fmt.Errorf("logging into registry: %w", err) + } else if repo.Authentication.Username != "" && repo.Authentication.Password != "" { + if err := helmClient.RegistryLogin(repo); err != nil { + return "", fmt.Errorf("logging into registry: %w", err) + } } chartPath, err := helmClient.Pull(chart.Name, repo, chart.Version, destDir) diff --git a/pkg/registry/helm_test.go b/pkg/registry/helm_test.go index 221948c6..61766add 100644 --- a/pkg/registry/helm_test.go +++ b/pkg/registry/helm_test.go @@ -193,10 +193,41 @@ func TestDownloadChart_FailedAddingRepo(t *testing.T) { assert.Empty(t, chartPath) } +func TestDownloadChart_ValidRegistryLogin(t *testing.T) { + helmChart := &image.HelmChart{} + helmRepo := &image.HelmRepository{ + URL: "oci://registry-1.docker.io/bitnamicharts/apache", + Authentication: image.HelmAuthentication{ + Username: "valid", + Password: "login", + }, + } + + helmClient := mockHelmClient{ + addRepoFunc: func(repository *image.HelmRepository) error { + return nil + }, + registryLoginFunc: func(repository *image.HelmRepository) error { + return nil + }, + pullFunc: func(chart string, repository *image.HelmRepository, version, destDir string) (string, error) { + return "apache-chart.tgz", nil + }, + } + + chartPath, err := downloadChart(helmChart, helmRepo, helmClient, "") + require.NoError(t, err) + assert.Equal(t, "apache-chart.tgz", chartPath) +} + func TestDownloadChart_FailedRegistryLogin(t *testing.T) { helmChart := &image.HelmChart{} helmRepo := &image.HelmRepository{ URL: "oci://registry-1.docker.io/bitnamicharts/apache", + Authentication: image.HelmAuthentication{ + Username: "wrong", + Password: "creds", + }, } helmClient := mockHelmClient{ @@ -250,9 +281,6 @@ func TestDownloadChart(t *testing.T) { addRepoFunc: func(repository *image.HelmRepository) error { return nil }, - registryLoginFunc: func(repository *image.HelmRepository) error { - return nil - }, pullFunc: func(chart string, repository *image.HelmRepository, version, destDir string) (string, error) { return "apache-chart.tgz", nil },