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:
Sebastiaan van Stijn 2023-06-01 18:36:46 +02:00 committed by GitHub
commit e7b1501832
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View file

@ -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()

View file

@ -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{

View file

@ -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
}