Skip to content

Commit

Permalink
Fix Helm chart OCI registry handling (#356)
Browse files Browse the repository at this point in the history
* fix handling for oci registries

* update release notes and test

* add valid registry login case
  • Loading branch information
dbw7 authored Apr 8, 2024
1 parent 922d269 commit 17faffd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

---
Expand Down
6 changes: 4 additions & 2 deletions pkg/registry/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 31 additions & 3 deletions pkg/registry/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
},
Expand Down

0 comments on commit 17faffd

Please sign in to comment.