func RegistryHostsFromCRIConfig(ctx context.Context, config Registry, credsFuncs ...Credential) source.RegistryHosts {
	paths := filepath.SplitList(config.ConfigPath)
	if len(paths) > 0 {
		return func(ref reference.Spec) ([]docker.RegistryHost, error) {
			hostOptions := dconfig.HostOptions{}
			hostOptions.Credentials = multiCredsFuncs(ref, append(credsFuncs, func(host string, ref reference.Spec) (string, string, error) {
				config := config.Configs[host]
				if config.Auth != nil {
					return ParseAuth(toRuntimeAuthConfig(*config.Auth), host)
				}
				return "", "", nil
			})...)
			hostOptions.HostDir = hostDirFromRoots(paths)
			return dconfig.ConfigureHosts(ctx, hostOptions)(ref.Hostname())
		}
	}
	return func(ref reference.Spec) ([]docker.RegistryHost, error) {
		host := ref.Hostname()
		var registries []docker.RegistryHost

		endpoints, err := registryEndpoints(config, host)
		if err != nil {
			return nil, errors.Wrap(err, "get registry endpoints")
		}
		for _, e := range endpoints {
			u, err := url.Parse(e)
			if err != nil {
				return nil, errors.Wrapf(err, "parse registry endpoint %q from mirrors", e)
			}

			var (
				transport = http.DefaultTransport.(*http.Transport).Clone()
				client    = &http.Client{Transport: transport}
				config    = config.Configs[u.Host]
			)

			if config.TLS != nil {
				transport.TLSClientConfig, err = getTLSConfig(*config.TLS)
				if err != nil {
					return nil, errors.Wrapf(err, "get TLSConfig for registry %q", e)
				}
			}

			authorizer := docker.NewDockerAuthorizer(
				docker.WithAuthClient(client),
				docker.WithAuthCreds(multiCredsFuncs(ref, credsFuncs...)))

			if u.Path == "" {
				u.Path = "/v2"
			}

			registries = append(registries, docker.RegistryHost{
				Client:       client,
				Authorizer:   authorizer,
				Host:         u.Host,
				Scheme:       u.Scheme,
				Path:         u.Path,
				Capabilities: docker.HostCapabilityResolve | docker.HostCapabilityPull,
			})
		}
		return registries, nil
	}
}
// RegistryHostsFromCRIConfig creates RegistryHosts (a set of registry configuration) from CRI-plugin-compatible config.
// NOTE: ported from https://github.com/containerd/containerd/blob/v1.5.2/pkg/cri/server/image_pull.go#L332-L405
// TODO: import this from CRI package once we drop support to continerd v1.4.x
RegistryHostsFromCRIConfig creates RegistryHosts (a set of registry configuration) from CRI-plugin-compatible config.
// RegistryHostsFromCRIConfig creates RegistryHosts ( a set of registry configuration ) from CRI - plugin - compatible config . // NOTE : ported from https : // github . com / containerd / containerd / blob / v1 . 5 . 2 / pkg / cri / server / image_pull . go#L332 - L405 // TODO : import this from CRI package once we drop support to continerd v1 . 4 . x
func RegistryHostsFromCRIConfig(ctx context.Context, config Registry, credsFuncs ...Credential) source.RegistryHosts {
	paths := filepath.SplitList(config.ConfigPath)
	if len(paths) > 0 {
		return func(ref reference.Spec) ([]docker.RegistryHost, error) {
			hostOptions := dconfig.HostOptions{}
			hostOptions.Credentials = multiCredsFuncs(ref, append(credsFuncs, func(host string, ref reference.Spec) (string, string, error) {
				config := config.Configs[host]
				if config.Auth != nil {
					return ParseAuth(toRuntimeAuthConfig(*config.Auth), host)
				}
				return "", "", nil
			})...)
			hostOptions.HostDir = hostDirFromRoots(paths)
			return dconfig.ConfigureHosts(ctx, hostOptions)(ref.Hostname())
		}
	}
	return func(ref reference.Spec) ([]docker.RegistryHost, error) {
		host := ref.Hostname()
		var registries []docker.RegistryHost
		endpoints, err := registryEndpoints(config, host)
		if err != nil {
			return nil, errors.Wrap(err, "get registry endpoints")
		}
		for _, e := range endpoints {
			u, err := url.Parse(e)
			if err != nil {
				return nil, errors.Wrapf(err, "parse registry endpoint %q from mirrors", e)
			}
			var (
				transport = http.DefaultTransport.(*http.Transport).Clone()
				client    = &http.Client{Transport: transport}
				config    = config.Configs[u.Host]
			)
			if config.TLS != nil {
				transport.TLSClientConfig, err = getTLSConfig(*config.TLS)
				if err != nil {
					return nil, errors.Wrapf(err, "get TLSConfig for registry %q", e)
				}
			}
			authorizer := docker.NewDockerAuthorizer(
				docker.WithAuthClient(client),
				docker.WithAuthCreds(multiCredsFuncs(ref, credsFuncs...)))
			if u.Path == "" {
				u.Path = "/v2"
			}
			registries = append(registries, docker.RegistryHost{
				Client:       client,
				Authorizer:   authorizer,
				Host:         u.Host,
				Scheme:       u.Scheme,
				Path:         u.Path,
				Capabilities: docker.HostCapabilityResolve | docker.HostCapabilityPull,
			})
		}
		return registries, nil
	}
}
func RegistryHostsFromCRIConfig ( ctx context . Context , config Registry , credsFuncs ... Credential ) source . RegistryHosts { paths := filepath . SplitList ( config . ConfigPath ) if len ( paths ) > 0 { return func ( ref reference . Spec ) ( [ ] docker . RegistryHost , error ) { hostOptions := dconfig . HostOptions { } hostOptions . Credentials = multiCredsFuncs ( ref , append ( credsFuncs , func ( host string , ref reference . Spec ) ( string , string , error ) { config := config . Configs [ host ] if config . Auth != nil { return ParseAuth ( toRuntimeAuthConfig ( * config . Auth ) , host ) } return " " , " " , nil } ) ... ) hostOptions . HostDir = hostDirFromRoots ( paths ) return dconfig . ConfigureHosts ( ctx , hostOptions ) ( ref . Hostname ( ) ) } } return func ( ref reference . Spec ) ( [ ] docker . RegistryHost , error ) { host := ref . Hostname ( ) var registries [ ] docker . RegistryHost endpoints , err := registryEndpoints ( config , host ) if err != nil { return nil , errors . Wrap ( err , " " ) } for _ , e := range endpoints { u , err := url . Parse ( e ) if err != nil { return nil , errors . Wrapf ( err , " " , e ) } var ( transport = http . DefaultTransport . ( * http . Transport ) . Clone ( ) client = & http . Client { Transport : transport } config = config . Configs [ u . Host ] ) if config . TLS != nil { transport . TLSClientConfig , err = getTLSConfig ( * config . TLS ) if err != nil { return nil , errors . Wrapf ( err , " " , e ) } } authorizer := docker . NewDockerAuthorizer ( docker . WithAuthClient ( client ) , docker . WithAuthCreds ( multiCredsFuncs ( ref , credsFuncs ... ) ) ) if u . Path == " " { u . Path = " " } registries = append ( registries , docker . RegistryHost { Client : client , Authorizer : authorizer , Host : u . Host , Scheme : u . Scheme , Path : u . Path , Capabilities : docker . HostCapabilityResolve | docker . HostCapabilityPull , } ) } return registries , nil } }
RegistryHostsFromCRIConfig creates RegistryHosts (a set of registry configuration) from CRI-plugin-compatible config.
RegistryHostsFromCRIConfig creates RegistryHosts ( a set of registry configuration ) from CRI - plugin - compatible config .