Merge pull request #43174 from thaJeztah/move_platformcheck
distribution: remove RootFSDownloadManager interface, and remove "os" argument from Download()
This commit is contained in:
commit
65b8bcc321
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -22,7 +21,6 @@ import (
|
||||||
"github.com/containerd/containerd/remotes/docker/schema1"
|
"github.com/containerd/containerd/remotes/docker/schema1"
|
||||||
distreference "github.com/docker/distribution/reference"
|
distreference "github.com/docker/distribution/reference"
|
||||||
dimages "github.com/docker/docker/daemon/images"
|
dimages "github.com/docker/docker/daemon/images"
|
||||||
"github.com/docker/docker/distribution"
|
|
||||||
"github.com/docker/docker/distribution/metadata"
|
"github.com/docker/docker/distribution/metadata"
|
||||||
"github.com/docker/docker/distribution/xfer"
|
"github.com/docker/docker/distribution/xfer"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
|
@ -52,7 +50,7 @@ type SourceOpt struct {
|
||||||
ContentStore content.Store
|
ContentStore content.Store
|
||||||
CacheAccessor cache.Accessor
|
CacheAccessor cache.Accessor
|
||||||
ReferenceStore reference.Store
|
ReferenceStore reference.Store
|
||||||
DownloadManager distribution.RootFSDownloadManager
|
DownloadManager *xfer.LayerDownloadManager
|
||||||
MetadataStore metadata.V2MetadataService
|
MetadataStore metadata.V2MetadataService
|
||||||
ImageStore image.Store
|
ImageStore image.Store
|
||||||
RegistryHosts docker.RegistryHosts
|
RegistryHosts docker.RegistryHosts
|
||||||
|
@ -564,7 +562,7 @@ func (p *puller) Snapshot(ctx context.Context, g session.Group) (cache.Immutable
|
||||||
}()
|
}()
|
||||||
|
|
||||||
r := image.NewRootFS()
|
r := image.NewRootFS()
|
||||||
rootFS, release, err := p.is.DownloadManager.Download(ctx, *r, runtime.GOOS, layers, pkgprogress.ChanOutput(pchan))
|
rootFS, release, err := p.is.DownloadManager.Download(ctx, *r, layers, pkgprogress.ChanOutput(pchan))
|
||||||
stopProgress()
|
stopProgress()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
nethttp "net/http"
|
nethttp "net/http"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -14,7 +13,6 @@ import (
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
"github.com/containerd/containerd/rootfs"
|
"github.com/containerd/containerd/rootfs"
|
||||||
"github.com/docker/docker/builder/builder-next/adapters/containerimage"
|
"github.com/docker/docker/builder/builder-next/adapters/containerimage"
|
||||||
"github.com/docker/docker/distribution"
|
|
||||||
distmetadata "github.com/docker/docker/distribution/metadata"
|
distmetadata "github.com/docker/docker/distribution/metadata"
|
||||||
"github.com/docker/docker/distribution/xfer"
|
"github.com/docker/docker/distribution/xfer"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
|
@ -70,7 +68,7 @@ type Opt struct {
|
||||||
ContentStore content.Store
|
ContentStore content.Store
|
||||||
CacheManager cache.Manager
|
CacheManager cache.Manager
|
||||||
ImageSource *containerimage.Source
|
ImageSource *containerimage.Source
|
||||||
DownloadManager distribution.RootFSDownloadManager
|
DownloadManager *xfer.LayerDownloadManager
|
||||||
V2MetadataService distmetadata.V2MetadataService
|
V2MetadataService distmetadata.V2MetadataService
|
||||||
Transport nethttp.RoundTripper
|
Transport nethttp.RoundTripper
|
||||||
Exporter exporter.Exporter
|
Exporter exporter.Exporter
|
||||||
|
@ -357,7 +355,7 @@ func (w *Worker) FromRemote(ctx context.Context, remote *solver.Remote) (cache.I
|
||||||
}()
|
}()
|
||||||
|
|
||||||
r := image.NewRootFS()
|
r := image.NewRootFS()
|
||||||
rootFS, release, err := w.DownloadManager.Download(ctx, *r, runtime.GOOS, layers, &discardProgress{})
|
rootFS, release, err := w.DownloadManager.Download(ctx, *r, layers, &discardProgress{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
daemonevents "github.com/docker/docker/daemon/events"
|
daemonevents "github.com/docker/docker/daemon/events"
|
||||||
"github.com/docker/docker/distribution"
|
|
||||||
"github.com/docker/docker/distribution/metadata"
|
"github.com/docker/docker/distribution/metadata"
|
||||||
"github.com/docker/docker/distribution/xfer"
|
"github.com/docker/docker/distribution/xfer"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
|
@ -95,7 +94,7 @@ type ImageService struct {
|
||||||
|
|
||||||
// DistributionServices provides daemon image storage services
|
// DistributionServices provides daemon image storage services
|
||||||
type DistributionServices struct {
|
type DistributionServices struct {
|
||||||
DownloadManager distribution.RootFSDownloadManager
|
DownloadManager *xfer.LayerDownloadManager
|
||||||
V2MetadataService metadata.V2MetadataService
|
V2MetadataService metadata.V2MetadataService
|
||||||
LayerStore layer.Store
|
LayerStore layer.Store
|
||||||
ImageStore image.Store
|
ImageStore image.Store
|
||||||
|
|
|
@ -56,7 +56,7 @@ type ImagePullConfig struct {
|
||||||
Config
|
Config
|
||||||
|
|
||||||
// DownloadManager manages concurrent pulls.
|
// DownloadManager manages concurrent pulls.
|
||||||
DownloadManager RootFSDownloadManager
|
DownloadManager *xfer.LayerDownloadManager
|
||||||
// Schema2Types is the valid schema2 configuration types allowed
|
// Schema2Types is the valid schema2 configuration types allowed
|
||||||
// by the pull operation.
|
// by the pull operation.
|
||||||
Schema2Types []string
|
Schema2Types []string
|
||||||
|
@ -107,15 +107,6 @@ type PushLayer interface {
|
||||||
Release()
|
Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
// RootFSDownloadManager handles downloading of the rootfs
|
|
||||||
type RootFSDownloadManager interface {
|
|
||||||
// Download downloads the layers into the given initial rootfs and
|
|
||||||
// returns the final rootfs.
|
|
||||||
// Given progress output to track download progress
|
|
||||||
// Returns function to release download resources
|
|
||||||
Download(ctx context.Context, initialRootFS image.RootFS, os string, layers []xfer.DownloadDescriptor, progressOutput progress.Output) (image.RootFS, func(), error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type imageConfigStore struct {
|
type imageConfigStore struct {
|
||||||
image.Store
|
image.Store
|
||||||
}
|
}
|
||||||
|
|
|
@ -547,7 +547,7 @@ func (p *v2Puller) pullSchema1(ctx context.Context, ref reference.Reference, unv
|
||||||
descriptors = append(descriptors, layerDescriptor)
|
descriptors = append(descriptors, layerDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
resultRootFS, release, err := p.config.DownloadManager.Download(ctx, *rootFS, runtime.GOOS, descriptors, p.config.ProgressOutput)
|
resultRootFS, release, err := p.config.DownloadManager.Download(ctx, *rootFS, descriptors, p.config.ProgressOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
@ -665,6 +665,12 @@ func (p *v2Puller) pullSchema2Layers(ctx context.Context, target distribution.De
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assume that the operating system is the host OS if blank, and validate it
|
||||||
|
// to ensure we don't cause a panic by an invalid index into the layerstores.
|
||||||
|
if layerStoreOS != "" && !system.IsOSSupported(layerStoreOS) {
|
||||||
|
return "", system.ErrNotSupportedOperatingSystem
|
||||||
|
}
|
||||||
|
|
||||||
if p.config.DownloadManager != nil {
|
if p.config.DownloadManager != nil {
|
||||||
go func() {
|
go func() {
|
||||||
var (
|
var (
|
||||||
|
@ -672,7 +678,7 @@ func (p *v2Puller) pullSchema2Layers(ctx context.Context, target distribution.De
|
||||||
rootFS image.RootFS
|
rootFS image.RootFS
|
||||||
)
|
)
|
||||||
downloadRootFS := *image.NewRootFS()
|
downloadRootFS := *image.NewRootFS()
|
||||||
rootFS, release, err = p.config.DownloadManager.Download(ctx, downloadRootFS, layerStoreOS, descriptors, p.config.ProgressOutput)
|
rootFS, release, err = p.config.DownloadManager.Download(ctx, downloadRootFS, descriptors, p.config.ProgressOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Intentionally do not cancel the config download here
|
// Intentionally do not cancel the config download here
|
||||||
// as the error from config download (if there is one)
|
// as the error from config download (if there is one)
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/distribution"
|
"github.com/docker/distribution"
|
||||||
|
@ -14,7 +13,6 @@ import (
|
||||||
"github.com/docker/docker/pkg/archive"
|
"github.com/docker/docker/pkg/archive"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/docker/pkg/progress"
|
"github.com/docker/docker/pkg/progress"
|
||||||
"github.com/docker/docker/pkg/system"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -106,7 +104,7 @@ type DownloadDescriptorWithRegistered interface {
|
||||||
// Download method is called to get the layer tar data. Layers are then
|
// Download method is called to get the layer tar data. Layers are then
|
||||||
// registered in the appropriate order. The caller must call the returned
|
// registered in the appropriate order. The caller must call the returned
|
||||||
// release function once it is done with the returned RootFS object.
|
// release function once it is done with the returned RootFS object.
|
||||||
func (ldm *LayerDownloadManager) Download(ctx context.Context, initialRootFS image.RootFS, os string, layers []DownloadDescriptor, progressOutput progress.Output) (image.RootFS, func(), error) {
|
func (ldm *LayerDownloadManager) Download(ctx context.Context, initialRootFS image.RootFS, layers []DownloadDescriptor, progressOutput progress.Output) (image.RootFS, func(), error) {
|
||||||
var (
|
var (
|
||||||
topLayer layer.Layer
|
topLayer layer.Layer
|
||||||
topDownload *downloadTransfer
|
topDownload *downloadTransfer
|
||||||
|
@ -116,16 +114,6 @@ func (ldm *LayerDownloadManager) Download(ctx context.Context, initialRootFS ima
|
||||||
downloadsByKey = make(map[string]*downloadTransfer)
|
downloadsByKey = make(map[string]*downloadTransfer)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Assume that the operating system is the host OS if blank, and validate it
|
|
||||||
// to ensure we don't cause a panic by an invalid index into the layerstores.
|
|
||||||
// TODO remove now that LCOW is no longer a thing
|
|
||||||
if os == "" {
|
|
||||||
os = runtime.GOOS
|
|
||||||
}
|
|
||||||
if !system.IsOSSupported(os) {
|
|
||||||
return image.RootFS{}, nil, system.ErrNotSupportedOperatingSystem
|
|
||||||
}
|
|
||||||
|
|
||||||
rootFS := initialRootFS
|
rootFS := initialRootFS
|
||||||
for _, descriptor := range layers {
|
for _, descriptor := range layers {
|
||||||
key := descriptor.Key()
|
key := descriptor.Key()
|
||||||
|
|
|
@ -293,7 +293,7 @@ func TestSuccessfulDownload(t *testing.T) {
|
||||||
}
|
}
|
||||||
firstDescriptor.diffID = l.DiffID()
|
firstDescriptor.diffID = l.DiffID()
|
||||||
|
|
||||||
rootFS, releaseFunc, err := ldm.Download(context.Background(), *image.NewRootFS(), runtime.GOOS, descriptors, progress.ChanOutput(progressChan))
|
rootFS, releaseFunc, err := ldm.Download(context.Background(), *image.NewRootFS(), descriptors, progress.ChanOutput(progressChan))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("download error: %v", err)
|
t.Fatalf("download error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ func TestCancelledDownload(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
descriptors := downloadDescriptors(nil)
|
descriptors := downloadDescriptors(nil)
|
||||||
_, _, err := ldm.Download(ctx, *image.NewRootFS(), runtime.GOOS, descriptors, progress.ChanOutput(progressChan))
|
_, _, err := ldm.Download(ctx, *image.NewRootFS(), descriptors, progress.ChanOutput(progressChan))
|
||||||
if err != context.Canceled {
|
if err != context.Canceled {
|
||||||
close(progressChan)
|
close(progressChan)
|
||||||
t.Fatal("expected download to be cancelled")
|
t.Fatal("expected download to be cancelled")
|
||||||
|
@ -413,7 +413,7 @@ func TestMaxDownloadAttempts(t *testing.T) {
|
||||||
descriptors := downloadDescriptors(¤tDownloads)
|
descriptors := downloadDescriptors(¤tDownloads)
|
||||||
descriptors[4].(*mockDownloadDescriptor).simulateRetries = tc.simulateRetries
|
descriptors[4].(*mockDownloadDescriptor).simulateRetries = tc.simulateRetries
|
||||||
|
|
||||||
_, _, err := ldm.Download(context.Background(), *image.NewRootFS(), runtime.GOOS, descriptors, progress.ChanOutput(progressChan))
|
_, _, err := ldm.Download(context.Background(), *image.NewRootFS(), descriptors, progress.ChanOutput(progressChan))
|
||||||
if tc.expectedErr == "" {
|
if tc.expectedErr == "" {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue