Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow host+subpath as the source registry for registry-override #2306

Merged
merged 4 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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