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

api/types: cleanup to use more idiomatic names #43530

Merged
merged 8 commits into from
Apr 29, 2022
2 changes: 1 addition & 1 deletion api/server/router/container/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type copyBackend interface {

// stateBackend includes functions to implement to provide container state lifecycle functionality.
type stateBackend interface {
ContainerCreate(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
ContainerCreate(config types.ContainerCreateConfig) (container.CreateResponse, error)
ContainerKill(name string, sig uint64) error
ContainerPause(name string) error
ContainerRename(oldName, newName string) error
Expand Down
6 changes: 3 additions & 3 deletions api/server/router/container/container_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,12 @@ func (s *containerRouter) postContainersWait(ctx context.Context, w http.Respons
return nil
}

var waitError *container.ContainerWaitOKBodyError
var waitError *container.WaitExitError
if status.Err() != nil {
waitError = &container.ContainerWaitOKBodyError{Message: status.Err().Error()}
waitError = &container.WaitExitError{Message: status.Err().Error()}
}

return json.NewEncoder(w).Encode(&container.ContainerWaitOKBody{
return json.NewEncoder(w).Encode(&container.WaitResponse{
StatusCode: int64(status.ExitCode()),
Error: waitError,
})
Expand Down
14 changes: 7 additions & 7 deletions api/server/router/volume/volume_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types/filters"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/volume/service/opts"
"github.com/pkg/errors"
)
Expand All @@ -24,36 +24,36 @@ func (v *volumeRouter) getVolumesList(ctx context.Context, w http.ResponseWriter
if err != nil {
return err
}
return httputils.WriteJSON(w, http.StatusOK, &volumetypes.VolumeListOKBody{Volumes: volumes, Warnings: warnings})
return httputils.WriteJSON(w, http.StatusOK, &volume.ListResponse{Volumes: volumes, Warnings: warnings})
}

func (v *volumeRouter) getVolumeByName(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := httputils.ParseForm(r); err != nil {
return err
}

volume, err := v.backend.Get(ctx, vars["name"], opts.WithGetResolveStatus)
vol, err := v.backend.Get(ctx, vars["name"], opts.WithGetResolveStatus)
if err != nil {
return err
}
return httputils.WriteJSON(w, http.StatusOK, volume)
return httputils.WriteJSON(w, http.StatusOK, vol)
}

func (v *volumeRouter) postVolumesCreate(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := httputils.ParseForm(r); err != nil {
return err
}

var req volumetypes.VolumeCreateBody
var req volume.CreateOptions
if err := httputils.ReadJSON(r, &req); err != nil {
return err
}

volume, err := v.backend.Create(ctx, req.Name, req.Driver, opts.WithCreateOptions(req.DriverOpts), opts.WithCreateLabels(req.Labels))
vol, err := v.backend.Create(ctx, req.Name, req.Driver, opts.WithCreateOptions(req.DriverOpts), opts.WithCreateLabels(req.Labels))
if err != nil {
return err
}
return httputils.WriteJSON(w, http.StatusCreated, volume)
return httputils.WriteJSON(w, http.StatusCreated, vol)
}

func (v *volumeRouter) deleteVolumes(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
Expand Down
49 changes: 26 additions & 23 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,7 @@ definitions:
UsageData:
type: "object"
x-nullable: true
x-go-name: "UsageData"
required: [Size, RefCount]
description: |
Usage details about the volume. This information is used by the
Expand All @@ -2035,7 +2036,7 @@ definitions:
description: "Volume configuration"
type: "object"
title: "VolumeConfig"
x-go-name: "VolumeCreateBody"
x-go-name: "CreateOptions"
properties:
Name:
description: |
Expand Down Expand Up @@ -2072,7 +2073,7 @@ definitions:
VolumeListResponse:
type: "object"
title: "VolumeListResponse"
x-go-name: "VolumeListOKBody"
x-go-name: "ListResponse"
description: "Volume list response"
properties:
Volumes:
Expand Down Expand Up @@ -4616,10 +4617,30 @@ definitions:
Health:
$ref: "#/definitions/Health"

ContainerCreateResponse:
description: "OK response to ContainerCreate operation"
type: "object"
title: "ContainerCreateResponse"
x-go-name: "CreateResponse"
required: [Id, Warnings]
properties:
Id:
description: "The ID of the created container"
type: "string"
x-nullable: false
example: "ede54ee1afda366ab42f824e8a5ffd195155d853ceaec74a927f249ea270c743"
Warnings:
description: "Warnings encountered when creating the container"
type: "array"
x-nullable: false
items:
type: "string"
example: []

ContainerWaitResponse:
description: "OK response to ContainerWait operation"
type: "object"
x-go-name: "ContainerWaitOKBody"
x-go-name: "WaitResponse"
title: "ContainerWaitResponse"
required: [StatusCode, Error]
properties:
Expand All @@ -4633,7 +4654,7 @@ definitions:
ContainerWaitExitError:
description: "container waiting error, if any"
type: "object"
x-go-name: "ContainerWaitOKBodyError"
x-go-name: "WaitExitError"
properties:
Message:
description: "Details of an error"
Expand Down Expand Up @@ -6080,25 +6101,7 @@ paths:
201:
description: "Container created successfully"
schema:
type: "object"
title: "ContainerCreateResponse"
description: "OK response to ContainerCreate operation"
required: [Id, Warnings]
properties:
Id:
description: "The ID of the created container"
type: "string"
x-nullable: false
Warnings:
description: "Warnings encountered when creating the container"
type: "array"
x-nullable: false
items:
type: "string"
examples:
application/json:
Id: "e90e34656806"
Warnings: []
$ref: "#/definitions/ContainerCreateResponse"
400:
description: "bad parameter"
schema:
Expand Down
20 changes: 0 additions & 20 deletions api/types/container/container_create.go

This file was deleted.

19 changes: 19 additions & 0 deletions api/types/container/create_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package container

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

// CreateResponse ContainerCreateResponse
//
// OK response to ContainerCreate operation
// swagger:model CreateResponse
type CreateResponse struct {

// The ID of the created container
// Required: true
ID string `json:"Id"`

// Warnings encountered when creating the container
// Required: true
Warnings []string `json:"Warnings"`
}
16 changes: 16 additions & 0 deletions api/types/container/deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package container // import "github.com/docker/docker/api/types/container"
Copy link
Member

Choose a reason for hiding this comment

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

Wandering if we really need these? The interfaces changed and these aren't used any more so I fail to see why we still have them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I usually have a quick peek if there's external consumers (e.g. https://grep.app/search?q=.ContainerCreateCreatedBody), and if there are, I add the "deprecated" alias, so that linters will give consumers a way to find what to use instead, but remove the alias after one release (having given them time to migrate the code).


// ContainerCreateCreatedBody OK response to ContainerCreate operation
//
// Deprecated: use CreateResponse
type ContainerCreateCreatedBody = CreateResponse

// ContainerWaitOKBody OK response to ContainerWait operation
//
// Deprecated: use WaitResponse
type ContainerWaitOKBody = WaitResponse

// ContainerWaitOKBodyError container waiting error, if any
//
// Deprecated: use WaitExitError
type ContainerWaitOKBodyError = WaitExitError
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package container
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

// ContainerWaitOKBodyError container waiting error, if any
// swagger:model ContainerWaitOKBodyError
type ContainerWaitOKBodyError struct {
// WaitExitError container waiting error, if any
// swagger:model WaitExitError
type WaitExitError struct {

// Details of an error
Message string `json:"Message,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package container
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

// ContainerWaitOKBody ContainerWaitResponse
// WaitResponse ContainerWaitResponse
//
// OK response to ContainerWait operation
// swagger:model ContainerWaitOKBody
type ContainerWaitOKBody struct {
// swagger:model WaitResponse
type WaitResponse struct {

// error
// Required: true
Error *ContainerWaitOKBodyError `json:"Error"`
Error *WaitExitError `json:"Error"`

// Exit code of the container
// Required: true
Expand Down
4 changes: 2 additions & 2 deletions api/types/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ type Volume = volume.Volume
// VolumeUsageData Usage details about the volume. This information is used by the
// `GET /system/df` endpoint, and omitted in other endpoints.
//
// Deprecated: use github.com/docker/docker/api/types/volume.VolumeUsageData
type VolumeUsageData = volume.VolumeUsageData
// Deprecated: use github.com/docker/docker/api/types/volume.UsageData
type VolumeUsageData = volume.UsageData
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package volume
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

// VolumeCreateBody VolumeConfig
// CreateOptions VolumeConfig
//
// Volume configuration
// swagger:model VolumeCreateBody
type VolumeCreateBody struct {
// swagger:model CreateOptions
type CreateOptions struct {

// Name of the volume driver to use.
Driver string `json:"Driver,omitempty"`
Expand Down
11 changes: 11 additions & 0 deletions api/types/volume/deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package volume // import "github.com/docker/docker/api/types/volume"

// VolumeCreateBody Volume configuration
//
// Deprecated: use CreateOptions
type VolumeCreateBody = CreateOptions

// VolumeListOKBody Volume list response
//
// Deprecated: use ListResponse
type VolumeListOKBody = ListResponse
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package volume
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

// VolumeListOKBody VolumeListResponse
// ListResponse VolumeListResponse
//
// Volume list response
// swagger:model VolumeListOKBody
type VolumeListOKBody struct {
// swagger:model ListResponse
type ListResponse struct {

// List of volumes
Volumes []*Volume `json:"Volumes"`
Expand Down
8 changes: 4 additions & 4 deletions api/types/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ type Volume struct {
Status map[string]interface{} `json:"Status,omitempty"`

// usage data
UsageData *VolumeUsageData `json:"UsageData,omitempty"`
UsageData *UsageData `json:"UsageData,omitempty"`
}

// VolumeUsageData Usage details about the volume. This information is used by the
// UsageData Usage details about the volume. This information is used by the
// `GET /system/df` endpoint, and omitted in other endpoints.
//
// swagger:model VolumeUsageData
type VolumeUsageData struct {
// swagger:model UsageData
type UsageData struct {

// The number of containers referencing this volume. This field
// is set to `-1` if the reference-count is not available.
Expand Down
2 changes: 1 addition & 1 deletion builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ExecBackend interface {
// ContainerAttachRaw attaches to container.
ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool, attached chan struct{}) error
// ContainerCreateIgnoreImagesArgsEscaped creates a new Docker container and returns potential warnings
ContainerCreateIgnoreImagesArgsEscaped(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
ContainerCreateIgnoreImagesArgsEscaped(config types.ContainerCreateConfig) (container.CreateResponse, error)
// ContainerRm removes a container specified by `id`.
ContainerRm(name string, config *types.ContainerRmConfig) error
// ContainerKill stops the container execution abruptly.
Expand Down
2 changes: 1 addition & 1 deletion builder/dockerfile/containerbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newContainerManager(docker builder.ExecBackend) *containerManager {
}

// Create a container
func (c *containerManager) Create(runConfig *container.Config, hostConfig *container.HostConfig) (container.ContainerCreateCreatedBody, error) {
func (c *containerManager) Create(runConfig *container.Config, hostConfig *container.HostConfig) (container.CreateResponse, error) {
container, err := c.backend.ContainerCreateIgnoreImagesArgsEscaped(types.ContainerCreateConfig{
Config: runConfig,
HostConfig: hostConfig,
Expand Down
12 changes: 6 additions & 6 deletions builder/dockerfile/dispatchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ func TestRunWithBuildArgs(t *testing.T) {
config: &container.Config{Cmd: origCmd},
}, nil, nil
}
mockBackend.containerCreateFunc = func(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) {
mockBackend.containerCreateFunc = func(config types.ContainerCreateConfig) (container.CreateResponse, error) {
// Check the runConfig.Cmd sent to create()
assert.Check(t, is.DeepEqual(cmdWithShell, config.Config.Cmd))
assert.Check(t, is.Contains(config.Config.Env, "one=two"))
assert.Check(t, is.DeepEqual(strslice.StrSlice{""}, config.Config.Entrypoint))
return container.ContainerCreateCreatedBody{ID: "12345"}, nil
return container.CreateResponse{ID: "12345"}, nil
}
mockBackend.commitFunc = func(cfg backend.CommitConfig) (image.ID, error) {
// Check the runConfig.Cmd sent to commit()
Expand Down Expand Up @@ -536,8 +536,8 @@ func TestRunIgnoresHealthcheck(t *testing.T) {
config: &container.Config{Cmd: origCmd},
}, nil, nil
}
mockBackend.containerCreateFunc = func(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) {
return container.ContainerCreateCreatedBody{ID: "12345"}, nil
mockBackend.containerCreateFunc = func(config types.ContainerCreateConfig) (container.CreateResponse, error) {
return container.CreateResponse{ID: "12345"}, nil
}
mockBackend.commitFunc = func(cfg backend.CommitConfig) (image.ID, error) {
return "", nil
Expand All @@ -563,10 +563,10 @@ func TestRunIgnoresHealthcheck(t *testing.T) {
assert.NilError(t, dispatch(sb, cmd))
assert.Assert(t, sb.state.runConfig.Healthcheck != nil)

mockBackend.containerCreateFunc = func(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) {
mockBackend.containerCreateFunc = func(config types.ContainerCreateConfig) (container.CreateResponse, error) {
// Check the Healthcheck is disabled.
assert.Check(t, is.DeepEqual([]string{"NONE"}, config.Config.Healthcheck.Test))
return container.ContainerCreateCreatedBody{ID: "123456"}, nil
return container.CreateResponse{ID: "123456"}, nil
}

sb.state.buildArgs.AddArg("one", strPtr("two"))
Expand Down