8000 api/types: move ImageLoadResponse to api/types/image · moby/moby@052c897 · GitHub
[go: up one dir, main page]

Skip to content

Commit 052c897

Browse files
committed
api/types: move ImageLoadResponse to api/types/image
This moves the type, but we should consider removing this type, and just returning an io.ReadCloser This type was added in 9fd2c0f; > Make docker load to output json when the response content type is json > Swarm hijacks the response from docker load and returns JSON rather > than plain text like the Engine does. This makes the API library to return > information to figure that out. However the "load" endpoint unconditionally returns JSON; https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255 Commit 96d7db6 made the response-type depend on whether "quiet" was set, but this logic got changed in a follow-up 2f27632, which made the JSON response-type unconditionally, but the output produced depend on whether"quiet" was set. We should deprecated the "quiet" option, as it's really a client responsibility. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 41979cd commit 052c897

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

api/types/client.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ type ImageBuildResponse struct {
130130
OSType string
131131
}
132132

133-
// ImageLoadResponse returns information to the client about a load process.
134-
type ImageLoadResponse struct {
135-
// Body must be closed to avoid a resource leak
136-
Body io.ReadCloser
137-
JSON bool
138-
}
139-
140133
// RequestPrivilegeFunc is a functio 8000 n interface that
141134
// clients can supply to retry operations after
142135
// getting an authorization error.

api/types/image/image.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package image
22

3-
import "time"
3+
import (
4+
"io"
5+
"time"
6+
)
47

58
// Metadata contains engine-local data about the image.
69
type Metadata struct {
@@ -14,3 +17,31 @@ type PruneReport struct {
1417
ImagesDeleted []DeleteResponse
1518
SpaceReclaimed uint64
1619
}
20+
21+
// LoadResponse returns information to the client about a load process.
22+
//
23+
// TODO(thaJeztah): remove this type, and just use an io.ReadCloser
24+
//
25+
// This type was added in https://github.com/moby/moby/pull/18878, related
26+
// to https://github.com/moby/moby/issues/19177;
27+
//
28+
// Make docker load to output json when the response content type is json
29+
// Swarm hijacks the response from docker load and returns JSON rather
30+
// than plain text like the Engine does. This makes the API library to return
31+
// information to figure that out.
32+
//
33+
// However the "load" endpoint unconditionally returns JSON;
34+
// https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255
35+
//
36+
// PR https://github.com/moby/moby/pull/21959 made the response-type depend
37+
// on whether "quiet" was set, but this logic got changed in a follow-up
38+
// https://github.com/moby/moby/pull/25557, which made the JSON response-type
39+
// unconditionally, but the output produced depend on whether"quiet" was set.
40+
//
41+
// We should deprecated the "quiet" option, as it's really a client
42+
// responsibility.
43+
type LoadResponse struct {
44+
// Body must be closed to avoid a resource leak
45+
Body io.ReadCloser
46+
JSON bool
47+
}

api/types/types_deprecated.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,8 @@ type ImageSearchOptions = registry.SearchOptions
128128
//
129129
// Deprecated: use [image.ImportSource].
130130
type ImageImportSource image.ImportSource
131+
132+
// ImageLoadResponse returns information to the client about a load process.
133+
//
134+
// Deprecated: use [image.LoadResponse].
135+
type ImageLoadResponse = image.LoadResponse

client/image_load.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"net/http"
77
"net/url"
88

9-
"github.com/docker/docker/api/types"
9+
"github.com/docker/docker/api/types/image"
1010
)
1111

1212
// ImageLoad loads an image in the docker host from the client host.
1313
// It's up to the caller to close the io.ReadCloser in the
1414
// ImageLoadResponse returned by this function.
15-
func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error) {
15+
func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (image.LoadResponse, error) {
1616
v := url.Values{}
1717
v.Set("quiet", "0")
1818
if quiet {
@@ -22,9 +22,9 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, quiet bool) (
2222
"Content-Type": {"application/x-tar"},
2323
})
2424
if err != nil {
25-
return types.ImageLoadResponse{}, err
25+
return image.LoadResponse{}, err
2626
}
27-
return types.ImageLoadResponse{
27+
return image.LoadResponse{
2828
Body: resp.body,
2929
JSON: resp.header.Get("Content-Type") == "application/json",
3030
}, nil

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type ImageAPIClient interface {
9595
ImageImport(ctx context.Context, source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
9696
ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
9797
ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error)
98-
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
98+
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (image.LoadResponse, error)
9999
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error)
100100
ImagePush(ctx context.Context, ref string, options image.PushOptions) (io.ReadCloser, error)
101101
ImageRemove(ctx context.Context, image string, options image.RemoveOptions) ([]image.DeleteResponse, error)

0 commit comments

Comments
 (0)
0