diff --git a/src/internal/packager/images/pull.go b/src/internal/packager/images/pull.go index 92ed0d5775..a8bb98d327 100644 --- a/src/internal/packager/images/pull.go +++ b/src/internal/packager/images/pull.go @@ -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) } } diff --git a/src/test/e2e/25_helm_test.go b/src/test/e2e/25_helm_test.go index 38478d710c..fef3433e76 100644 --- a/src/test/e2e/25_helm_test.go +++ b/src/test/e2e/25_helm_test.go @@ -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)