From 3122cc53faf2ab8eb07f87053189ac88b39457c1 Mon Sep 17 00:00:00 2001 From: Emil Davtyan Date: Tue, 30 Jan 2018 13:35:22 +0100 Subject: [PATCH 1/4] Produce errors when empty ids are passed into inspect calls. If a blank nodeID was previously passed in it resulted in a node list request. The response would then fail to umarshal into a `Node` type returning a JSON error. This adds an extra validation to all inspect calls to check that the ID that is required is provided and if not return an error. Signed-off-by: Emil Davtyan Upstream-commit: 3e6bbefd268f51755be5af0644995297a71a05d7 Component: engine --- components/engine/client/config_inspect.go | 3 +++ .../engine/client/config_inspect_test.go | 24 +++++++++++++++++++ components/engine/client/container_inspect.go | 6 +++++ .../engine/client/container_inspect_test.go | 13 ++++++++++ .../engine/client/distribution_inspect.go | 3 +++ .../client/distribution_inspect_test.go | 13 ++++++++++ components/engine/client/image_inspect.go | 3 +++ .../engine/client/image_inspect_test.go | 13 ++++++++++ components/engine/client/network_inspect.go | 3 +++ .../engine/client/network_inspect_test.go | 13 ++++++++++ components/engine/client/node_inspect.go | 3 +++ components/engine/client/node_inspect_test.go | 13 ++++++++++ components/engine/client/plugin_inspect.go | 3 +++ .../engine/client/plugin_inspect_test.go | 13 ++++++++++ components/engine/client/secret_inspect.go | 3 +++ .../engine/client/secret_inspect_test.go | 13 ++++++++++ components/engine/client/service_inspect.go | 3 +++ .../engine/client/service_inspect_test.go | 13 ++++++++++ components/engine/client/task_inspect.go | 3 +++ components/engine/client/task_inspect_test.go | 13 ++++++++++ components/engine/client/volume_inspect.go | 6 +---- .../engine/client/volume_inspect_test.go | 16 +++++-------- 22 files changed, 181 insertions(+), 15 deletions(-) diff --git a/components/engine/client/config_inspect.go b/components/engine/client/config_inspect.go index b44d6fdd7e..a03b46d411 100644 --- a/components/engine/client/config_inspect.go +++ b/components/engine/client/config_inspect.go @@ -11,6 +11,9 @@ import ( // ConfigInspectWithRaw returns the config information with raw data func (cli *Client) ConfigInspectWithRaw(ctx context.Context, id string) (swarm.Config, []byte, error) { + if id == "" { + return swarm.Config{}, nil, objectNotFoundError{object: "config", id: id} + } if err := cli.NewVersionError("1.30", "config inspect"); err != nil { return swarm.Config{}, nil, err } diff --git a/components/engine/client/config_inspect_test.go b/components/engine/client/config_inspect_test.go index fab0c286f5..5a188d056c 100644 --- a/components/engine/client/config_inspect_test.go +++ b/components/engine/client/config_inspect_test.go @@ -10,10 +10,34 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) +func TestConfigInspectNotFound(t *testing.T) { + client := &Client{ + client: newMockClient(errorMock(http.StatusNotFound, "Server error")), + } + + _, _, err := client.ConfigInspectWithRaw(context.Background(), "unknown") + if err == nil || !IsErrNotFound(err) { + t.Fatalf("expected a NotFoundError error, got %v", err) + } +} + +func TestConfigInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.ConfigInspectWithRaw(context.Background(), "") + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestConfigInspectUnsupported(t *testing.T) { client := &Client{ version: "1.29", diff --git a/components/engine/client/container_inspect.go b/components/engine/client/container_inspect.go index a15db14be8..2da90a43df 100644 --- a/components/engine/client/container_inspect.go +++ b/components/engine/client/container_inspect.go @@ -12,6 +12,9 @@ import ( // ContainerInspect returns the container information. func (cli *Client) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error) { + if containerID == "" { + return types.ContainerJSON{}, objectNotFoundError{object: "container", id: containerID} + } serverResp, err := cli.get(ctx, "/containers/"+containerID+"/json", nil, nil) if err != nil { return types.ContainerJSON{}, wrapResponseError(err, serverResp, "container", containerID) @@ -25,6 +28,9 @@ func (cli *Client) ContainerInspect(ctx context.Context, containerID string) (ty // ContainerInspectWithRaw returns the container information and its raw representation. func (cli *Client) ContainerInspectWithRaw(ctx context.Context, containerID string, getSize bool) (types.ContainerJSON, []byte, error) { + if containerID == "" { + return types.ContainerJSON{}, nil, objectNotFoundError{object: "container", id: containerID} + } query := url.Values{} if getSize { query.Set("size", "1") diff --git a/components/engine/client/container_inspect_test.go b/components/engine/client/container_inspect_test.go index 37259e40bd..9915a89239 100644 --- a/components/engine/client/container_inspect_test.go +++ b/components/engine/client/container_inspect_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/docker/docker/api/types" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -35,6 +36,18 @@ func TestContainerInspectContainerNotFound(t *testing.T) { } } +func TestContainerInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.ContainerInspectWithRaw(context.Background(), "", true) + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestContainerInspect(t *testing.T) { expectedURL := "/containers/container_id/json" client := &Client{ diff --git a/components/engine/client/distribution_inspect.go b/components/engine/client/distribution_inspect.go index aa5bc6a6c6..b2cf02e0c7 100644 --- a/components/engine/client/distribution_inspect.go +++ b/components/engine/client/distribution_inspect.go @@ -12,6 +12,9 @@ import ( func (cli *Client) DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registrytypes.DistributionInspect, error) { // Contact the registry to retrieve digest and platform information var distributionInspect registrytypes.DistributionInspect + if image == "" { + return distributionInspect, objectNotFoundError{object: "distribution", id: image} + } if err := cli.NewVersionError("1.30", "distribution inspect"); err != nil { return distributionInspect, err diff --git a/components/engine/client/distribution_inspect_test.go b/components/engine/client/distribution_inspect_test.go index eff28d7ca7..4da49bcea8 100644 --- a/components/engine/client/distribution_inspect_test.go +++ b/components/engine/client/distribution_inspect_test.go @@ -4,6 +4,7 @@ import ( "net/http" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -16,3 +17,15 @@ func TestDistributionInspectUnsupported(t *testing.T) { _, err := client.DistributionInspect(context.Background(), "foobar:1.0", "") assert.EqualError(t, err, `"distribution inspect" requires API version 1.30, but the Docker daemon API version is 1.29`) } + +func TestDistributionInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, err := client.DistributionInspect(context.Background(), "", "") + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} diff --git a/components/engine/client/image_inspect.go b/components/engine/client/image_inspect.go index 1bc5919907..42a0884023 100644 --- a/components/engine/client/image_inspect.go +++ b/components/engine/client/image_inspect.go @@ -11,6 +11,9 @@ import ( // ImageInspectWithRaw returns the image information and its raw representation. func (cli *Client) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) { + if imageID == "" { + return types.ImageInspect{}, nil, objectNotFoundError{object: "image", id: imageID} + } serverResp, err := cli.get(ctx, "/images/"+imageID+"/json", nil, nil) if err != nil { return types.ImageInspect{}, nil, wrapResponseError(err, serverResp, "image", imageID) diff --git a/components/engine/client/image_inspect_test.go b/components/engine/client/image_inspect_test.go index b5721f39fe..b578a4a6ae 100644 --- a/components/engine/client/image_inspect_test.go +++ b/components/engine/client/image_inspect_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/docker/docker/api/types" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -36,6 +37,18 @@ func TestImageInspectImageNotFound(t *testing.T) { } } +func TestImageInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.ImageInspectWithRaw(context.Background(), "") + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestImageInspect(t *testing.T) { expectedURL := "/images/image_id/json" expectedTags := []string{"tag1", "tag2"} diff --git a/components/engine/client/network_inspect.go b/components/engine/client/network_inspect.go index afabe65970..a37c60402d 100644 --- a/components/engine/client/network_inspect.go +++ b/components/engine/client/network_inspect.go @@ -18,6 +18,9 @@ func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options // NetworkInspectWithRaw returns the information for a specific network configured in the docker host and its raw representation. func (cli *Client) NetworkInspectWithRaw(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error) { + if networkID == "" { + return types.NetworkResource{}, nil, objectNotFoundError{object: "network", id: networkID} + } var ( networkResource types.NetworkResource resp serverResponse diff --git a/components/engine/client/network_inspect_test.go b/components/engine/client/network_inspect_test.go index 56399c7bc2..c134be5fec 100644 --- a/components/engine/client/network_inspect_test.go +++ b/components/engine/client/network_inspect_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -34,6 +35,18 @@ func TestNetworkInspectNotFoundError(t *testing.T) { assert.True(t, IsErrNotFound(err)) } +func TestNetworkInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.NetworkInspectWithRaw(context.Background(), "", types.NetworkInspectOptions{}) + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestNetworkInspect(t *testing.T) { expectedURL := "/networks/network_id" client := &Client{ diff --git a/components/engine/client/node_inspect.go b/components/engine/client/node_inspect.go index 791d2c0066..bcd391153a 100644 --- a/components/engine/client/node_inspect.go +++ b/components/engine/client/node_inspect.go @@ -11,6 +11,9 @@ import ( // NodeInspectWithRaw returns the node information. func (cli *Client) NodeInspectWithRaw(ctx context.Context, nodeID string) (swarm.Node, []byte, error) { + if nodeID == "" { + return swarm.Node{}, nil, objectNotFoundError{object: "node", id: nodeID} + } serverResp, err := cli.get(ctx, "/nodes/"+nodeID, nil, nil) if err != nil { return swarm.Node{}, nil, wrapResponseError(err, serverResp, "node", nodeID) diff --git a/components/engine/client/node_inspect_test.go b/components/engine/client/node_inspect_test.go index 6260da517d..e5e315b144 100644 --- a/components/engine/client/node_inspect_test.go +++ b/components/engine/client/node_inspect_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -35,6 +36,18 @@ func TestNodeInspectNodeNotFound(t *testing.T) { } } +func TestNodeInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.NodeInspectWithRaw(context.Background(), "") + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestNodeInspect(t *testing.T) { expectedURL := "/nodes/node_id" client := &Client{ diff --git a/components/engine/client/plugin_inspect.go b/components/engine/client/plugin_inspect.go index 6a6fc18dfe..0b9e07ebdc 100644 --- a/components/engine/client/plugin_inspect.go +++ b/components/engine/client/plugin_inspect.go @@ -11,6 +11,9 @@ import ( // PluginInspectWithRaw inspects an existing plugin func (cli *Client) PluginInspectWithRaw(ctx context.Context, name string) (*types.Plugin, []byte, error) { + if name == "" { + return nil, nil, objectNotFoundError{object: "plugin", id: name} + } resp, err := cli.get(ctx, "/plugins/"+name+"/json", nil, nil) if err != nil { return nil, nil, wrapResponseError(err, resp, "plugin", name) diff --git a/components/engine/client/plugin_inspect_test.go b/components/engine/client/plugin_inspect_test.go index fae407eb9b..066e00797d 100644 --- a/components/engine/client/plugin_inspect_test.go +++ b/components/engine/client/plugin_inspect_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/docker/docker/api/types" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -24,6 +25,18 @@ func TestPluginInspectError(t *testing.T) { } } +func TestPluginInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.PluginInspectWithRaw(context.Background(), "") + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestPluginInspect(t *testing.T) { expectedURL := "/plugins/plugin_name" client := &Client{ diff --git a/components/engine/client/secret_inspect.go b/components/engine/client/secret_inspect.go index 6927ea96fa..11d8434eb1 100644 --- a/components/engine/client/secret_inspect.go +++ b/components/engine/client/secret_inspect.go @@ -14,6 +14,9 @@ func (cli *Client) SecretInspectWithRaw(ctx context.Context, id string) (swarm.S if err := cli.NewVersionError("1.25", "secret inspect"); err != nil { return swarm.Secret{}, nil, err } + if id == "" { + return swarm.Secret{}, nil, objectNotFoundError{object: "secret", id: id} + } resp, err := cli.get(ctx, "/secrets/"+id, nil, nil) if err != nil { return swarm.Secret{}, nil, wrapResponseError(err, resp, "secret", id) diff --git a/components/engine/client/secret_inspect_test.go b/components/engine/client/secret_inspect_test.go index 66dbb48d83..4b56d97190 100644 --- a/components/engine/client/secret_inspect_test.go +++ b/components/engine/client/secret_inspect_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -47,6 +48,18 @@ func TestSecretInspectSecretNotFound(t *testing.T) { } } +func TestSecretInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.SecretInspectWithRaw(context.Background(), "") + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestSecretInspect(t *testing.T) { expectedURL := "/v1.25/secrets/secret_id" client := &Client{ diff --git a/components/engine/client/service_inspect.go b/components/engine/client/service_inspect.go index 3e9699e5e0..52792efbb9 100644 --- a/components/engine/client/service_inspect.go +++ b/components/engine/client/service_inspect.go @@ -14,6 +14,9 @@ import ( // ServiceInspectWithRaw returns the service information and the raw data. func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error) { + if serviceID == "" { + return swarm.Service{}, nil, objectNotFoundError{object: "service", id: serviceID} + } query := url.Values{} query.Set("insertDefaults", fmt.Sprintf("%v", opts.InsertDefaults)) serverResp, err := cli.get(ctx, "/services/"+serviceID, query, nil) diff --git a/components/engine/client/service_inspect_test.go b/components/engine/client/service_inspect_test.go index ade62535ca..8fab3a1dbb 100644 --- a/components/engine/client/service_inspect_test.go +++ b/components/engine/client/service_inspect_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -36,6 +37,18 @@ func TestServiceInspectServiceNotFound(t *testing.T) { } } +func TestServiceInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.ServiceInspectWithRaw(context.Background(), "", types.ServiceInspectOptions{}) + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestServiceInspect(t *testing.T) { expectedURL := "/services/service_id" client := &Client{ diff --git a/components/engine/client/task_inspect.go b/components/engine/client/task_inspect.go index dc08cedb96..f7afa6c11e 100644 --- a/components/engine/client/task_inspect.go +++ b/components/engine/client/task_inspect.go @@ -11,6 +11,9 @@ import ( // TaskInspectWithRaw returns the task information and its raw representation.. func (cli *Client) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) { + if taskID == "" { + return swarm.Task{}, nil, objectNotFoundError{object: "task", id: taskID} + } serverResp, err := cli.get(ctx, "/tasks/"+taskID, nil, nil) if err != nil { return swarm.Task{}, nil, wrapResponseError(err, serverResp, "task", taskID) diff --git a/components/engine/client/task_inspect_test.go b/components/engine/client/task_inspect_test.go index 148cdad3a7..910006731b 100644 --- a/components/engine/client/task_inspect_test.go +++ b/components/engine/client/task_inspect_test.go @@ -10,6 +10,7 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" + "github.com/pkg/errors" "golang.org/x/net/context" ) @@ -24,6 +25,18 @@ func TestTaskInspectError(t *testing.T) { } } +func TestTaskInspectWithEmptyID(t *testing.T) { + client := &Client{ + client: newMockClient(func(req *http.Request) (*http.Response, error) { + return nil, errors.New("should not make request") + }), + } + _, _, err := client.TaskInspectWithRaw(context.Background(), "") + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } +} + func TestTaskInspect(t *testing.T) { expectedURL := "/tasks/task_id" client := &Client{ diff --git a/components/engine/client/volume_inspect.go b/components/engine/client/volume_inspect.go index 9889343849..684bcf513f 100644 --- a/components/engine/client/volume_inspect.go +++ b/components/engine/client/volume_inspect.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "io/ioutil" - "path" "github.com/docker/docker/api/types" "golang.org/x/net/context" @@ -18,15 +17,12 @@ func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Vo // VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) { - // The empty ID needs to be handled here because with an empty ID the - // request url will not contain a trailing / which calls the volume list API - // instead of volume inspect if volumeID == "" { return types.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID} } var volume types.Volume - resp, err := cli.get(ctx, path.Join("/volumes", volumeID), nil, nil) + resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil) if err != nil { return volume, nil, wrapResponseError(err, resp, "volume", volumeID) } diff --git a/components/engine/client/volume_inspect_test.go b/components/engine/client/volume_inspect_test.go index 7d01f44ed2..6ac6f681db 100644 --- a/components/engine/client/volume_inspect_test.go +++ b/components/engine/client/volume_inspect_test.go @@ -11,6 +11,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/internal/testutil" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/net/context" @@ -35,20 +36,15 @@ func TestVolumeInspectNotFound(t *testing.T) { } func TestVolumeInspectWithEmptyID(t *testing.T) { - expectedURL := "/volumes/" - client := &Client{ client: newMockClient(func(req *http.Request) (*http.Response, error) { - assert.Equal(t, req.URL.Path, expectedURL) - return &http.Response{ - StatusCode: http.StatusNotFound, - Body: ioutil.NopCloser(bytes.NewReader(nil)), - }, nil + return nil, errors.New("should not make request") }), } - _, err := client.VolumeInspect(context.Background(), "") - testutil.ErrorContains(t, err, "No such volume: ") - + _, _, err := client.VolumeInspectWithRaw(context.Background(), "") + if !IsErrNotFound(err) { + t.Fatalf("Expected NotFoundError, got %v", err) + } } func TestVolumeInspect(t *testing.T) { From 9e1c0d71874b219e7acfdb16bf8a756ce0eae5cf Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 13 Feb 2018 14:29:14 -0500 Subject: [PATCH 2/4] Remove unnecessary getLayerInit Signed-off-by: Daniel Nephin Upstream-commit: c502bcff33e10be55f15366e123b25574016a9af Component: engine --- components/engine/daemon/create.go | 2 +- components/engine/daemon/daemon.go | 7 ------- components/engine/daemon/daemon_unix.go | 7 +++++-- components/engine/daemon/daemon_windows.go | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/components/engine/daemon/create.go b/components/engine/daemon/create.go index 05231dfcec..7e6b6519fe 100644 --- a/components/engine/daemon/create.go +++ b/components/engine/daemon/create.go @@ -266,7 +266,7 @@ func (daemon *Daemon) setRWLayer(container *container.Container) error { rwLayerOpts := &layer.CreateRWLayerOpts{ MountLabel: container.MountLabel, - InitFunc: daemon.getLayerInit(), + InitFunc: setupInitLayer(daemon.idMappings), StorageOpt: container.HostConfig.StorageOpt, } diff --git a/components/engine/daemon/daemon.go b/components/engine/daemon/daemon.go index ab28a56ebe..97694234af 100644 --- a/components/engine/daemon/daemon.go +++ b/components/engine/daemon/daemon.go @@ -32,7 +32,6 @@ import ( "github.com/sirupsen/logrus" // register graph drivers _ "github.com/docker/docker/daemon/graphdriver/register" - "github.com/docker/docker/daemon/initlayer" "github.com/docker/docker/daemon/stats" dmetadata "github.com/docker/docker/distribution/metadata" "github.com/docker/docker/distribution/xfer" @@ -41,7 +40,6 @@ import ( "github.com/docker/docker/layer" "github.com/docker/docker/libcontainerd" "github.com/docker/docker/migrate/v1" - "github.com/docker/docker/pkg/containerfs" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/locker" "github.com/docker/docker/pkg/plugingetter" @@ -1142,11 +1140,6 @@ func prepareTempDir(rootDir string, rootIDs idtools.IDPair) (string, error) { return tmpDir, idtools.MkdirAllAndChown(tmpDir, 0700, rootIDs) } -func (daemon *Daemon) setupInitLayer(initPath containerfs.ContainerFS) error { - rootIDs := daemon.idMappings.RootPair() - return initlayer.Setup(initPath, rootIDs) -} - func (daemon *Daemon) setGenericResources(conf *config.Config) error { genericResources, err := config.ParseGenericResources(conf.NodeGenericResources) if err != nil { diff --git a/components/engine/daemon/daemon_unix.go b/components/engine/daemon/daemon_unix.go index 55ff9f8574..b98b29aa61 100644 --- a/components/engine/daemon/daemon_unix.go +++ b/components/engine/daemon/daemon_unix.go @@ -23,6 +23,7 @@ import ( containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" "github.com/docker/docker/daemon/config" + "github.com/docker/docker/daemon/initlayer" "github.com/docker/docker/image" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/containerfs" @@ -1000,8 +1001,10 @@ func removeDefaultBridgeInterface() { } } -func (daemon *Daemon) getLayerInit() func(containerfs.ContainerFS) error { - return daemon.setupInitLayer +func setupInitLayer(idMappings *idtools.IDMappings) func(containerfs.ContainerFS) error { + return func(initPath containerfs.ContainerFS) error { + return initlayer.Setup(initPath, idMappings.RootPair()) + } } // Parse the remapped root (user namespace) option, which can be one of: diff --git a/components/engine/daemon/daemon_windows.go b/components/engine/daemon/daemon_windows.go index 7b5d954e98..5dd90de8a0 100644 --- a/components/engine/daemon/daemon_windows.go +++ b/components/engine/daemon/daemon_windows.go @@ -54,7 +54,7 @@ func parseSecurityOpt(container *container.Container, config *containertypes.Hos return nil } -func (daemon *Daemon) getLayerInit() func(containerfs.ContainerFS) error { +func setupInitLayer(idMappings *idtools.IDMappings) func(containerfs.ContainerFS) error { return nil } From a5927022374a928d638a67e32641de940acb39eb Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 13 Feb 2018 14:32:05 -0500 Subject: [PATCH 3/4] Remove duplicate rootFSToAPIType Signed-off-by: Daniel Nephin Upstream-commit: 4ceea53b5e6a86c39122e99f6ffbc1142d28a174 Component: engine --- components/engine/daemon/daemon_unix.go | 12 ------------ components/engine/daemon/daemon_windows.go | 12 ------------ components/engine/daemon/image_inspect.go | 12 ++++++++++++ 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/components/engine/daemon/daemon_unix.go b/components/engine/daemon/daemon_unix.go index b98b29aa61..670d564b8a 100644 --- a/components/engine/daemon/daemon_unix.go +++ b/components/engine/daemon/daemon_unix.go @@ -24,7 +24,6 @@ import ( "github.com/docker/docker/container" "github.com/docker/docker/daemon/config" "github.com/docker/docker/daemon/initlayer" - "github.com/docker/docker/image" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/containerfs" "github.com/docker/docker/pkg/idtools" @@ -1360,17 +1359,6 @@ func (daemon *Daemon) setDefaultIsolation() error { return nil } -func rootFSToAPIType(rootfs *image.RootFS) types.RootFS { - var layers []string - for _, l := range rootfs.DiffIDs { - layers = append(layers, l.String()) - } - return types.RootFS{ - Type: rootfs.Type, - Layers: layers, - } -} - // setupDaemonProcess sets various settings for the daemon's process func setupDaemonProcess(config *config.Config) error { // setup the daemons oom_score_adj diff --git a/components/engine/daemon/daemon_windows.go b/components/engine/daemon/daemon_windows.go index 5dd90de8a0..50507e5fad 100644 --- a/components/engine/daemon/daemon_windows.go +++ b/components/engine/daemon/daemon_windows.go @@ -11,7 +11,6 @@ import ( containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" "github.com/docker/docker/daemon/config" - "github.com/docker/docker/image" "github.com/docker/docker/pkg/containerfs" "github.com/docker/docker/pkg/fileutils" "github.com/docker/docker/pkg/idtools" @@ -629,17 +628,6 @@ func (daemon *Daemon) setDefaultIsolation() error { return nil } -func rootFSToAPIType(rootfs *image.RootFS) types.RootFS { - var layers []string - for _, l := range rootfs.DiffIDs { - layers = append(layers, l.String()) - } - return types.RootFS{ - Type: rootfs.Type, - Layers: layers, - } -} - func setupDaemonProcess(config *config.Config) error { return nil } diff --git a/components/engine/daemon/image_inspect.go b/components/engine/daemon/image_inspect.go index 066466e047..731057cf34 100644 --- a/components/engine/daemon/image_inspect.go +++ b/components/engine/daemon/image_inspect.go @@ -5,6 +5,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" + "github.com/docker/docker/image" "github.com/docker/docker/layer" "github.com/docker/docker/pkg/system" "github.com/pkg/errors" @@ -90,3 +91,14 @@ func (daemon *Daemon) LookupImage(name string) (*types.ImageInspect, error) { return imageInspect, nil } + +func rootFSToAPIType(rootfs *image.RootFS) types.RootFS { + var layers []string + for _, l := range rootfs.DiffIDs { + layers = append(layers, l.String()) + } + return types.RootFS{ + Type: rootfs.Type, + Layers: layers, + } +} From 75d038d03f95193a4490dfb0990fc796b1ece2dd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 17 Feb 2018 00:35:34 +0100 Subject: [PATCH 4/4] Update containerd/continuity to fix ARM 32-bit builds This updates the containerd/continuity package to d8fb8589b0e8e85b8c8bbaa8840226d0dfeb7371 which fixes builds failing on ARM 32-bit, after this dependency was added in b3aab5e31faf04d8a29f17be55562e4d0c0cb364 Signed-off-by: Sebastiaan van Stijn Upstream-commit: f0947a541866ca05b030afe07dd659887a655e3e Component: engine --- components/engine/vendor.conf | 2 +- .../github.com/containerd/continuity/fs/stat_linux.go | 3 ++- .../github.com/containerd/continuity/sysx/xattr_openbsd.go | 7 +++++++ .../containerd/continuity/sysx/xattr_unsupported.go | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 components/engine/vendor/github.com/containerd/continuity/sysx/xattr_openbsd.go diff --git a/components/engine/vendor.conf b/components/engine/vendor.conf index 11ffb11cd3..939c53625b 100644 --- a/components/engine/vendor.conf +++ b/components/engine/vendor.conf @@ -110,7 +110,7 @@ google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944 # containerd github.com/containerd/containerd 3fa104f843ec92328912e042b767d26825f202aa github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6 -github.com/containerd/continuity 992a5f112bd2211d0983a1cc8562d2882848f3a3 +github.com/containerd/continuity d8fb8589b0e8e85b8c8bbaa8840226d0dfeb7371 github.com/containerd/cgroups c0710c92e8b3a44681d1321dcfd1360fc5c6c089 github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e github.com/containerd/go-runc 4f6e87ae043f859a38255247b49c9abc262d002f diff --git a/components/engine/vendor/github.com/containerd/continuity/fs/stat_linux.go b/components/engine/vendor/github.com/containerd/continuity/fs/stat_linux.go index 25bc652581..1dbb0212b6 100644 --- a/components/engine/vendor/github.com/containerd/continuity/fs/stat_linux.go +++ b/components/engine/vendor/github.com/containerd/continuity/fs/stat_linux.go @@ -22,5 +22,6 @@ func StatMtime(st *syscall.Stat_t) syscall.Timespec { // StatATimeAsTime returns st.Atim as a time.Time func StatATimeAsTime(st *syscall.Stat_t) time.Time { - return time.Unix(st.Atim.Sec, st.Atim.Nsec) + // The int64 conversions ensure the line compiles for 32-bit systems as well. + return time.Unix(int64(st.Atim.Sec), int64(st.Atim.Nsec)) // nolint: unconvert } diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_openbsd.go b/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_openbsd.go new file mode 100644 index 0000000000..723619977d --- /dev/null +++ b/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_openbsd.go @@ -0,0 +1,7 @@ +package sysx + +import ( + "errors" +) + +var unsupported = errors.New("extended attributes unsupported on OpenBSD") diff --git a/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_unsupported.go b/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_unsupported.go index a8dd9f245f..c8389bc136 100644 --- a/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_unsupported.go +++ b/components/engine/vendor/github.com/containerd/continuity/sysx/xattr_unsupported.go @@ -1,4 +1,4 @@ -// +build freebsd solaris +// +build freebsd openbsd solaris package sysx