Add rewrite support to hosts.toml loader
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
@@ -197,7 +197,7 @@ type Mirror struct {
|
||||
// The scheme, host and path from the endpoint URL will be used.
|
||||
Endpoints []string `toml:"endpoint" json:"endpoint"`
|
||||
|
||||
// Rewrites are repository rewrite rules for a namespace. When fetching image resources
|
||||
// Rewrites is a map of repository rewrite rules for a namespace. When fetching image resources
|
||||
// from an endpoint and a key matches the repository via regular expression matching
|
||||
// it will be replaced with the corresponding value from the map in the resource request.
|
||||
//
|
||||
|
||||
@@ -437,14 +437,14 @@ func (c *CRIImageService) registryHosts(ctx context.Context, credentials func(ho
|
||||
return func(host string) ([]docker.RegistryHost, error) {
|
||||
var registries []docker.RegistryHost
|
||||
|
||||
endpoints, err := c.registryEndpoints(host)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get registry endpoints: %w", err)
|
||||
}
|
||||
rewrites, err := c.registryRewrites(host)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get registry rewrites: %w", err)
|
||||
}
|
||||
endpoints, err := c.registryEndpoints(host)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get registry endpoints: %w", err)
|
||||
}
|
||||
for _, e := range endpoints {
|
||||
u, err := url.Parse(e)
|
||||
if err != nil {
|
||||
@@ -570,17 +570,13 @@ func (c *CRIImageService) registryEndpoints(host string) ([]string, error) {
|
||||
}
|
||||
|
||||
func (c *CRIImageService) registryRewrites(host string) (map[string]string, error) {
|
||||
var rewrites map[string]string
|
||||
_, ok := c.config.Registry.Mirrors[host]
|
||||
if ok {
|
||||
rewrites = c.config.Registry.Mirrors[host].Rewrites
|
||||
} else {
|
||||
rewrites = c.config.Registry.Mirrors["*"].Rewrites
|
||||
hosts := []string{host, "*"}
|
||||
for _, host := range hosts {
|
||||
if host, ok := c.config.Registry.Mirrors[host]; ok {
|
||||
return host.Rewrites, nil
|
||||
}
|
||||
}
|
||||
if rewrites == nil {
|
||||
rewrites = map[string]string{}
|
||||
}
|
||||
return rewrites, nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// newTransport returns a new HTTP transport used to pull image.
|
||||
|
||||
Reference in New Issue
Block a user