Skip to content

Commit

Permalink
fix: allow host+subpath as the source registry for registry-override (#…
Browse files Browse the repository at this point in the history
…2306)

## Description

Instead of looking for refInfo.Host in the override map loop through the
keys and values in i.RegistryOverrides, check if the refInfo.Reference
begins with an override key and, if it does, replace that override text
with the override value and set it back to actualSrc.

Do not use ImageTransformHostWithoutChecksum since we already have the
parsed ref and all the info we need to do the replacement.

## Related Issue

Fixes #2135 

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed

---------

Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
Co-authored-by: Wayne Starr <Racer159@users.noreply.github.com>
Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 26, 2024
1 parent 51b78e1 commit f6b83e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {
}

actualSrc := refInfo.Reference
if overrideHost, present := i.RegistryOverrides[refInfo.Host]; present {
var err error
actualSrc, err = transform.ImageTransformHostWithoutChecksum(overrideHost, refInfo.Reference)
if err != nil {
metadataImageConcurrency.ErrorChan <- fmt.Errorf("failed to swap override host %s for %s: %w", overrideHost, refInfo.Reference, err)
return
for k, v := range i.RegistryOverrides {
if strings.HasPrefix(refInfo.Reference, k) {
actualSrc = strings.Replace(refInfo.Reference, k, v, 1)
}
}

Expand Down
18 changes: 17 additions & 1 deletion src/test/e2e/25_helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,23 @@ func testHelmChartsExample(t *testing.T) {
require.Contains(t, e2e.StripMessageFormatting(stdErr), "chart \"asdf\" version \"6.4.0\" not found")
require.Contains(t, e2e.StripMessageFormatting(stdErr), "Available charts and versions from \"https://stefanprodan.github.io/podinfo\":")

// Create the package (with a registry override to test that as well)
// Create a test package (with a registry override (host+subpath to host+subpath) to test that as well)
stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io/stefanprodan=docker.io/stefanprodan", "--tmpdir", tmpdir, "--confirm")
require.NoError(t, err, stdOut, stdErr)

// Create a test package (with a registry override (host to host+subpath) to test that as well)
// expect to fail as ghcr.io is overriden and the expected final image doesn't exist but the override works well based on the error message in the output
stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io=localhost:555/noway", "--tmpdir", tmpdir, "--confirm")
require.Error(t, err, stdOut, stdErr)
require.Contains(t, string(stdErr), "localhost:555/noway")

// Create a test package (with a registry override (host+subpath to host) to test that as well)
// works same as the above failing test
stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io/stefanprodan=localhost:555", "--tmpdir", tmpdir, "--confirm")
require.Error(t, err, stdOut, stdErr)
require.Contains(t, string(stdErr), "localhost:555")

// Create the package (with a registry override (host to host) to test that as well)
stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io=docker.io", "--tmpdir", tmpdir, "--confirm")
require.NoError(t, err, stdOut, stdErr)

Expand Down

0 comments on commit f6b83e1

Please sign in to comment.