Merge pull request #45671 from thaJeztah/24.0_backport_c8d_useragent
[24.0 backport] containerd: set user-agent when pushing/pulling images
This commit is contained in:
commit
e7b1501832
3 changed files with 8 additions and 3 deletions
|
@ -45,7 +45,7 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
|
|||
}
|
||||
}
|
||||
|
||||
resolver, _ := i.newResolverFromAuthConfig(authConfig)
|
||||
resolver, _ := i.newResolverFromAuthConfig(ctx, authConfig)
|
||||
opts = append(opts, containerd.WithResolver(resolver))
|
||||
|
||||
jobs := newJobs()
|
||||
|
|
|
@ -62,7 +62,7 @@ func (i *ImageService) PushImage(ctx context.Context, targetRef reference.Named,
|
|||
target := img.Target
|
||||
store := i.client.ContentStore()
|
||||
|
||||
resolver, tracker := i.newResolverFromAuthConfig(authConfig)
|
||||
resolver, tracker := i.newResolverFromAuthConfig(ctx, authConfig)
|
||||
progress := pushProgress{Tracker: tracker}
|
||||
jobsQueue := newJobs()
|
||||
finishProgress := jobsQueue.showProgress(ctx, out, combinedProgress([]progressUpdater{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package containerd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
@ -8,19 +9,23 @@ import (
|
|||
"github.com/containerd/containerd/remotes"
|
||||
"github.com/containerd/containerd/remotes/docker"
|
||||
registrytypes "github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (i *ImageService) newResolverFromAuthConfig(authConfig *registrytypes.AuthConfig) (remotes.Resolver, docker.StatusTracker) {
|
||||
func (i *ImageService) newResolverFromAuthConfig(ctx context.Context, authConfig *registrytypes.AuthConfig) (remotes.Resolver, docker.StatusTracker) {
|
||||
tracker := docker.NewInMemoryTracker()
|
||||
hostsFn := i.registryHosts.RegistryHosts()
|
||||
|
||||
hosts := hostsWrapper(hostsFn, authConfig, i.registryService)
|
||||
headers := http.Header{}
|
||||
headers.Set("User-Agent", dockerversion.DockerUserAgent(ctx))
|
||||
|
||||
return docker.NewResolver(docker.ResolverOptions{
|
||||
Hosts: hosts,
|
||||
Tracker: tracker,
|
||||
Headers: headers,
|
||||
}), tracker
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue