Bläddra i källkod

daemon/images: remove leftover LCOW platform checks

This removes some of the checks that were added in 0cba7740d41369eee33b671f26276325580bc07b,
but should no longer be needed.

- `ImageService.ImageDelete()`: no need to validate image platform to delete it.
- `ImageService.ImageHistory()`: no need to validate image platform to show its
  history; if it made it into the local image cache, it should be valid.
- `ImageService.ImportImage()`: `dockerfile.BuildFromConfig()` is used for
  `docker (container) commmit` and `docker (image) import`. For `docker import`,
   it's more transparent to perform validation early.
- `ImageService.LookupImage()`: no need to validate image platform to inspect it;
  if it made it into the local image cache, it should be valid.
- `ImageService.SquashImage()`: same. This code was actually broken, because it
  wrapped an `err` that was always `nil`, so would never return an error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 år sedan
förälder
incheckning
b2ef2e8c83

+ 0 - 4
daemon/images/image_delete.go

@@ -11,7 +11,6 @@ import (
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/errdefs"
 	"github.com/docker/docker/image"
 	"github.com/docker/docker/image"
 	"github.com/docker/docker/pkg/stringid"
 	"github.com/docker/docker/pkg/stringid"
-	"github.com/docker/docker/pkg/system"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 )
 )
 
 
@@ -68,9 +67,6 @@ func (i *ImageService) ImageDelete(imageRef string, force, prune bool) ([]types.
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
-	if !system.IsOSSupported(img.OperatingSystem()) {
-		return nil, errors.Errorf("unable to delete image: %q", system.ErrNotSupportedOperatingSystem)
-	}
 
 
 	imgID := img.ID()
 	imgID := img.ID()
 	repoRefs := i.referenceStore.References(imgID.Digest())
 	repoRefs := i.referenceStore.References(imgID.Digest())

+ 0 - 4
daemon/images/image_history.go

@@ -7,7 +7,6 @@ import (
 	"github.com/docker/distribution/reference"
 	"github.com/docker/distribution/reference"
 	"github.com/docker/docker/api/types/image"
 	"github.com/docker/docker/api/types/image"
 	"github.com/docker/docker/layer"
 	"github.com/docker/docker/layer"
-	"github.com/docker/docker/pkg/system"
 )
 )
 
 
 // ImageHistory returns a slice of ImageHistory structures for the specified image
 // ImageHistory returns a slice of ImageHistory structures for the specified image
@@ -32,9 +31,6 @@ func (i *ImageService) ImageHistory(name string) ([]*image.HistoryResponseItem,
 			if len(img.RootFS.DiffIDs) <= layerCounter {
 			if len(img.RootFS.DiffIDs) <= layerCounter {
 				return nil, fmt.Errorf("too many non-empty layers in History section")
 				return nil, fmt.Errorf("too many non-empty layers in History section")
 			}
 			}
-			if !system.IsOSSupported(img.OperatingSystem()) {
-				return nil, system.ErrNotSupportedOperatingSystem
-			}
 			rootFS.Append(img.RootFS.DiffIDs[layerCounter])
 			rootFS.Append(img.RootFS.DiffIDs[layerCounter])
 			l, err := i.layerStore.Get(rootFS.ChainID())
 			l, err := i.layerStore.Get(rootFS.ChainID())
 			if err != nil {
 			if err != nil {

+ 4 - 1
daemon/images/image_import.go

@@ -20,6 +20,7 @@ import (
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/archive"
 	"github.com/docker/docker/pkg/progress"
 	"github.com/docker/docker/pkg/progress"
 	"github.com/docker/docker/pkg/streamformatter"
 	"github.com/docker/docker/pkg/streamformatter"
+	"github.com/docker/docker/pkg/system"
 	specs "github.com/opencontainers/image-spec/specs-go/v1"
 	specs "github.com/opencontainers/image-spec/specs-go/v1"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 )
 )
@@ -58,7 +59,9 @@ func (i *ImageService) ImportImage(src string, repository string, platform *spec
 		p := platforms.DefaultSpec()
 		p := platforms.DefaultSpec()
 		platform = &p
 		platform = &p
 	}
 	}
-
+	if !system.IsOSSupported(platform.OS) {
+		return errdefs.InvalidParameter(system.ErrNotSupportedOperatingSystem)
+	}
 	config, err := dockerfile.BuildFromConfig(&container.Config{}, changes, platform.OS)
 	config, err := dockerfile.BuildFromConfig(&container.Config{}, changes, platform.OS)
 	if err != nil {
 	if err != nil {
 		return err
 		return err

+ 1 - 4
daemon/images/image_inspect.go

@@ -7,7 +7,6 @@ import (
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/image"
 	"github.com/docker/docker/image"
 	"github.com/docker/docker/layer"
 	"github.com/docker/docker/layer"
-	"github.com/docker/docker/pkg/system"
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 )
 )
 
 
@@ -18,9 +17,7 @@ func (i *ImageService) LookupImage(name string) (*types.ImageInspect, error) {
 	if err != nil {
 	if err != nil {
 		return nil, errors.Wrapf(err, "no such image: %s", name)
 		return nil, errors.Wrapf(err, "no such image: %s", name)
 	}
 	}
-	if !system.IsOSSupported(img.OperatingSystem()) {
-		return nil, system.ErrNotSupportedOperatingSystem
-	}
+
 	refs := i.referenceStore.References(img.ID().Digest())
 	refs := i.referenceStore.References(img.ID().Digest())
 	repoTags := []string{}
 	repoTags := []string{}
 	repoDigests := []string{}
 	repoDigests := []string{}

+ 0 - 3
daemon/images/images.go

@@ -285,9 +285,6 @@ func (i *ImageService) SquashImage(id, parent string) (string, error) {
 		rootFS := image.NewRootFS()
 		rootFS := image.NewRootFS()
 		parentImg = &image.Image{RootFS: rootFS}
 		parentImg = &image.Image{RootFS: rootFS}
 	}
 	}
-	if !system.IsOSSupported(img.OperatingSystem()) {
-		return "", errors.Wrap(err, system.ErrNotSupportedOperatingSystem.Error())
-	}
 	l, err := i.layerStore.Get(img.RootFS.ChainID())
 	l, err := i.layerStore.Get(img.RootFS.ChainID())
 	if err != nil {
 	if err != nil {
 		return "", errors.Wrap(err, "error getting image layer")
 		return "", errors.Wrap(err, "error getting image layer")