Prechádzať zdrojové kódy

split GetRepository from ImageService

The GetRepository method interacts directly with the registry, and does
not depend on the snapshotter, but is used for two purposes;

For the GET /distribution/{name:.*}/json route;
https://github.com/moby/moby/blob/dd3b71d17c614f837c4bba18baed9fa2cb31f1a4/api/server/router/distribution/backend.go#L11-L15

And to satisfy the "executor.ImageBackend" interface as used by Swarm;
https://github.com/moby/moby/blob/58c027ac8ba19a3fa339c65274ea6704ccbec977/daemon/cluster/executor/backend.go#L77

This patch removes the method from the ImageService interface, and instead
implements it through an composite struct that satisfies both interfaces,
and an ImageBackend() method is added to the daemon.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

remove GetRepository from ImageService

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 rokov pred
rodič
commit
a5d46a15f5

+ 2 - 2
cmd/dockerd/daemon.go

@@ -522,7 +522,7 @@ func initRouter(opts routerOptions) {
 		sessionrouter.NewRouter(opts.sessionManager),
 		sessionrouter.NewRouter(opts.sessionManager),
 		swarmrouter.NewRouter(opts.cluster),
 		swarmrouter.NewRouter(opts.cluster),
 		pluginrouter.NewRouter(opts.daemon.PluginManager()),
 		pluginrouter.NewRouter(opts.daemon.PluginManager()),
-		distributionrouter.NewRouter(opts.daemon.ImageService()),
+		distributionrouter.NewRouter(opts.daemon.ImageBackend()),
 	}
 	}
 
 
 	if opts.buildBackend != nil {
 	if opts.buildBackend != nil {
@@ -729,7 +729,7 @@ func createAndStartCluster(cli *DaemonCli, d *daemon.Daemon) (*cluster.Cluster,
 		Name:                   name,
 		Name:                   name,
 		Backend:                d,
 		Backend:                d,
 		VolumeBackend:          d.VolumesService(),
 		VolumeBackend:          d.VolumesService(),
-		ImageBackend:           d.ImageService(),
+		ImageBackend:           d.ImageBackend(),
 		PluginBackend:          d.PluginManager(),
 		PluginBackend:          d.PluginManager(),
 		NetworkSubnetsProvider: d,
 		NetworkSubnetsProvider: d,
 		DefaultAdvertiseAddr:   cli.Config.SwarmDefaultAdvertiseAddr,
 		DefaultAdvertiseAddr:   cli.Config.SwarmDefaultAdvertiseAddr,

+ 0 - 7
daemon/containerd/image_pull.go

@@ -2,14 +2,12 @@ package containerd
 
 
 import (
 import (
 	"context"
 	"context"
-	"errors"
 	"io"
 	"io"
 
 
 	"github.com/containerd/containerd"
 	"github.com/containerd/containerd"
 	"github.com/containerd/containerd/images"
 	"github.com/containerd/containerd/images"
 	"github.com/containerd/containerd/pkg/snapshotters"
 	"github.com/containerd/containerd/pkg/snapshotters"
 	"github.com/containerd/containerd/platforms"
 	"github.com/containerd/containerd/platforms"
-	"github.com/docker/distribution"
 	"github.com/docker/distribution/reference"
 	"github.com/docker/distribution/reference"
 	"github.com/docker/docker/api/types/registry"
 	"github.com/docker/docker/api/types/registry"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/errdefs"
@@ -73,8 +71,3 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
 	_, err = i.client.Pull(ctx, ref.String(), opts...)
 	_, err = i.client.Pull(ctx, ref.String(), opts...)
 	return err
 	return err
 }
 }
-
-// GetRepository returns a repository from the registry.
-func (i *ImageService) GetRepository(ctx context.Context, ref reference.Named, authConfig *registry.AuthConfig) (distribution.Repository, error) {
-	return nil, errdefs.NotImplemented(errors.New("not implemented"))
-}

+ 31 - 0
daemon/daemon.go

@@ -23,12 +23,16 @@ import (
 	"github.com/containerd/containerd/pkg/dialer"
 	"github.com/containerd/containerd/pkg/dialer"
 	"github.com/containerd/containerd/pkg/userns"
 	"github.com/containerd/containerd/pkg/userns"
 	"github.com/containerd/containerd/remotes/docker"
 	"github.com/containerd/containerd/remotes/docker"
+	dist "github.com/docker/distribution"
+	"github.com/docker/distribution/reference"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	containertypes "github.com/docker/docker/api/types/container"
 	containertypes "github.com/docker/docker/api/types/container"
+	registrytypes "github.com/docker/docker/api/types/registry"
 	"github.com/docker/docker/api/types/swarm"
 	"github.com/docker/docker/api/types/swarm"
 	"github.com/docker/docker/api/types/volume"
 	"github.com/docker/docker/api/types/volume"
 	"github.com/docker/docker/builder"
 	"github.com/docker/docker/builder"
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/container"
+	executorpkg "github.com/docker/docker/daemon/cluster/executor"
 	"github.com/docker/docker/daemon/config"
 	"github.com/docker/docker/daemon/config"
 	ctrd "github.com/docker/docker/daemon/containerd"
 	ctrd "github.com/docker/docker/daemon/containerd"
 	"github.com/docker/docker/daemon/events"
 	"github.com/docker/docker/daemon/events"
@@ -37,6 +41,7 @@ import (
 	dlogger "github.com/docker/docker/daemon/logger"
 	dlogger "github.com/docker/docker/daemon/logger"
 	"github.com/docker/docker/daemon/network"
 	"github.com/docker/docker/daemon/network"
 	"github.com/docker/docker/daemon/stats"
 	"github.com/docker/docker/daemon/stats"
+	"github.com/docker/docker/distribution"
 	dmetadata "github.com/docker/docker/distribution/metadata"
 	dmetadata "github.com/docker/docker/distribution/metadata"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/errdefs"
@@ -1466,6 +1471,14 @@ func (daemon *Daemon) ImageService() ImageService {
 	return daemon.imageService
 	return daemon.imageService
 }
 }
 
 
+// ImageBackend returns an image-backend for Swarm and the distribution router.
+func (daemon *Daemon) ImageBackend() executorpkg.ImageBackend {
+	return &imageBackend{
+		ImageService:    daemon.imageService,
+		registryService: daemon.registryService,
+	}
+}
+
 // RegistryService returns the Daemon's RegistryService
 // RegistryService returns the Daemon's RegistryService
 func (daemon *Daemon) RegistryService() *registry.Service {
 func (daemon *Daemon) RegistryService() *registry.Service {
 	return daemon.registryService
 	return daemon.registryService
@@ -1491,3 +1504,21 @@ func (daemon *Daemon) RawSysInfo() *sysinfo.SysInfo {
 
 
 	return daemon.sysInfo
 	return daemon.sysInfo
 }
 }
+
+// imageBackend is used to satisfy the [executorpkg.ImageBackend] and
+// [github.com/docker/docker/api/server/router/distribution.Backend]
+// interfaces.
+type imageBackend struct {
+	ImageService
+	registryService *registry.Service
+}
+
+// GetRepository returns a repository from the registry.
+func (i *imageBackend) GetRepository(ctx context.Context, ref reference.Named, authConfig *registrytypes.AuthConfig) (dist.Repository, error) {
+	return distribution.GetRepository(ctx, ref, &distribution.ImagePullConfig{
+		Config: distribution.Config{
+			AuthConfig:      authConfig,
+			RegistryService: i.registryService,
+		},
+	})
+}

+ 0 - 2
daemon/image_service.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"context"
 	"io"
 	"io"
 
 
-	"github.com/docker/distribution"
 	"github.com/docker/distribution/reference"
 	"github.com/docker/distribution/reference"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/backend"
 	"github.com/docker/docker/api/types/backend"
@@ -73,7 +72,6 @@ type ImageService interface {
 
 
 	// Other
 	// Other
 
 
-	GetRepository(ctx context.Context, ref reference.Named, authConfig *registry.AuthConfig) (distribution.Repository, error)
 	DistributionServices() images.DistributionServices
 	DistributionServices() images.DistributionServices
 	Children(id image.ID) []image.ID
 	Children(id image.ID) []image.ID
 	Cleanup() error
 	Cleanup() error

+ 0 - 11
daemon/images/image_pull.go

@@ -8,7 +8,6 @@ import (
 
 
 	"github.com/containerd/containerd/leases"
 	"github.com/containerd/containerd/leases"
 	"github.com/containerd/containerd/namespaces"
 	"github.com/containerd/containerd/namespaces"
-	dist "github.com/docker/distribution"
 	"github.com/docker/distribution/reference"
 	"github.com/docker/distribution/reference"
 	imagetypes "github.com/docker/docker/api/types/image"
 	imagetypes "github.com/docker/docker/api/types/image"
 	"github.com/docker/docker/api/types/registry"
 	"github.com/docker/docker/api/types/registry"
@@ -134,16 +133,6 @@ func (i *ImageService) pullImageWithReference(ctx context.Context, ref reference
 	return err
 	return err
 }
 }
 
 
-// GetRepository returns a repository from the registry.
-func (i *ImageService) GetRepository(ctx context.Context, ref reference.Named, authConfig *registry.AuthConfig) (dist.Repository, error) {
-	return distribution.GetRepository(ctx, ref, &distribution.ImagePullConfig{
-		Config: distribution.Config{
-			AuthConfig:      authConfig,
-			RegistryService: i.registryService,
-		},
-	})
-}
-
 func tempLease(ctx context.Context, mgr leases.Manager) (context.Context, func(context.Context) error, error) {
 func tempLease(ctx context.Context, mgr leases.Manager) (context.Context, func(context.Context) error, error) {
 	nop := func(context.Context) error { return nil }
 	nop := func(context.Context) error { return nil }
 	_, ok := leases.FromContext(ctx)
 	_, ok := leases.FromContext(ctx)