Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c8d: implement GetRepository (split GetRepository from ImageService) #45285

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func initRouter(opts routerOptions) {
sessionrouter.NewRouter(opts.sessionManager),
swarmrouter.NewRouter(opts.cluster),
pluginrouter.NewRouter(opts.daemon.PluginManager()),
distributionrouter.NewRouter(opts.daemon.ImageService()),
distributionrouter.NewRouter(opts.daemon.ImageBackend()),
}

if opts.buildBackend != nil {
Expand Down Expand Up @@ -729,7 +729,7 @@ func createAndStartCluster(cli *DaemonCli, d *daemon.Daemon) (*cluster.Cluster,
Name: name,
Backend: d,
VolumeBackend: d.VolumesService(),
ImageBackend: d.ImageService(),
ImageBackend: d.ImageBackend(),
PluginBackend: d.PluginManager(),
NetworkSubnetsProvider: d,
DefaultAdvertiseAddr: cli.Config.SwarmDefaultAdvertiseAddr,
Expand Down
7 changes: 0 additions & 7 deletions daemon/containerd/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package containerd

import (
"context"
"errors"
"io"

"github.com/containerd/containerd"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/pkg/snapshotters"
"github.com/containerd/containerd/platforms"
"github.com/docker/distribution"
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs"
Expand Down Expand Up @@ -73,8 +71,3 @@ func (i *ImageService) PullImage(ctx context.Context, image, tagOrDigest string,
_, err = i.client.Pull(ctx, ref.String(), opts...)
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 changes: 31 additions & 0 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ import (
"github.com/containerd/containerd/pkg/dialer"
"github.com/containerd/containerd/pkg/userns"
"github.com/containerd/containerd/remotes/docker"
dist "github.com/docker/distribution"
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
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/volume"
"github.com/docker/docker/builder"
"github.com/docker/docker/container"
executorpkg "github.com/docker/docker/daemon/cluster/executor"
"github.com/docker/docker/daemon/config"
ctrd "github.com/docker/docker/daemon/containerd"
"github.com/docker/docker/daemon/events"
Expand All @@ -37,6 +41,7 @@ import (
dlogger "github.com/docker/docker/daemon/logger"
"github.com/docker/docker/daemon/network"
"github.com/docker/docker/daemon/stats"
"github.com/docker/docker/distribution"
dmetadata "github.com/docker/docker/distribution/metadata"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/errdefs"
Expand Down Expand Up @@ -1466,6 +1471,14 @@ func (daemon *Daemon) ImageService() ImageService {
return daemon.imageService
}

// ImageBackend returns an image-backend for Swarm and the distribution router.
func (daemon *Daemon) ImageBackend() executorpkg.ImageBackend {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's rather unfortunate that we have this public method just so that we can create a router and a cluster on startup. The daemon here acts like an options object that carries around things used by other unrelated things

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. I think we should make a pass at looking what's there, and if all of these are needed. I feel there's a lot of "ad-hoc" (oh, we need a new backend, just add something).

return &imageBackend{
ImageService: daemon.imageService,
registryService: daemon.registryService,
}
}

// RegistryService returns the Daemon's RegistryService
func (daemon *Daemon) RegistryService() *registry.Service {
return daemon.registryService
Expand All @@ -1491,3 +1504,21 @@ func (daemon *Daemon) RawSysInfo() *sysinfo.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,
},
})
}
2 changes: 0 additions & 2 deletions daemon/image_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"io"

"github.com/docker/distribution"
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend"
Expand Down Expand Up @@ -73,7 +72,6 @@ type ImageService interface {

// Other

GetRepository(ctx context.Context, ref reference.Named, authConfig *registry.AuthConfig) (distribution.Repository, error)
DistributionServices() images.DistributionServices
Children(id image.ID) []image.ID
Cleanup() error
Expand Down
11 changes: 0 additions & 11 deletions daemon/images/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/containerd/containerd/leases"
"github.com/containerd/containerd/namespaces"
dist "github.com/docker/distribution"
"github.com/docker/distribution/reference"
imagetypes "github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/registry"
Expand Down Expand Up @@ -134,16 +133,6 @@ func (i *ImageService) pullImageWithReference(ctx context.Context, ref reference
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) {
nop := func(context.Context) error { return nil }
_, ok := leases.FromContext(ctx)
Expand Down