3export const upstreamRegHosts = ['docker.io', 'ghcr.io', 'quay.io', 'registry.k8s.io', 'gcr.io'] 5export const regcacheName = 'regcache' 7const splitImgHost = (image: string): {host: string | null, repoRef: string} => { 8 const firstSlash = image.indexOf('/') 9 if (firstSlash < 0) return {host: null, repoRef: image} 10 const first = image.slice(0, firstSlash) 11 if (first.includes('.') || first.includes(':') || first === 'localhost') return {host: first, repoRef: image.slice(firstSlash + 1)} 12 return {host: null, repoRef: image} 15export const regcacheImgRef = ({image, cacheHost}: {image: string, cacheHost: string}): string => { 16 if (image.startsWith(`${cacheHost}/`)) return image 17 const {host, repoRef} = splitImgHost(image) 18 if (!host || host === 'docker.io' || host === 'index.docker.io') { 19 const repoPath = repoRef.includes('/') ? repoRef : `library/${repoRef}` 20 return `${cacheHost}/docker.io/${repoPath}` 22 if (!upstreamRegHosts.includes(host)) return image 23 return `${cacheHost}/${host}/${repoRef}` 26export const getRegcacheTargetHost = (): string | undefined => { 27 const {regcacheEnabled, regcacheHost, regcacheLanHost} = getKlusterCtx() 28 if (!regcacheEnabled) return undefined 29 return regcacheLanHost || regcacheHost