Skip to content

Commit

Permalink
Add ns query parameter when using a mirror endpoint
Browse files Browse the repository at this point in the history
This is required by some registries that are capable of serving multiple upstreams

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Dec 8, 2023
1 parent 5a9199d commit afa72eb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/registries/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
var _ authn.Keychain = &endpoint{}
var _ http.RoundTripper = &endpoint{}

const (
defaultRegistry = "docker.io"
defaultRegistryHost = "index.docker.io"
)

type endpoint struct {
auth authn.Authenticator
keychain authn.Keychain
Expand Down Expand Up @@ -69,10 +74,17 @@ func (e endpoint) RoundTrip(req *http.Request) (*http.Response, error) {
}
}

// override request host and scheme
// override request host and scheme; set ns from original host
q := req.URL.Query()
if req.Host == defaultRegistryHost {
q.Set("ns", defaultRegistry)
} else {
q.Set("ns", req.Host)
}
req.Host = endpointURL.Host
req.URL.Host = endpointURL.Host
req.URL.Scheme = endpointURL.Scheme
req.URL.RawQuery = q.Encode()
}

if newURL := req.URL.String(); originalURL != newURL {
Expand Down

0 comments on commit afa72eb

Please sign in to comment.