Merge pull request #49442 from thaJeztah/api_rename_container_responses

api/types/container: rename ContainerUpdateOKBody to UpdateResponse, ContainerTopOKBody to TopResponse
This commit is contained in:
Sebastiaan van Stijn
2025-02-11 12:52:17 +01:00
committed by GitHub
16 changed files with 146 additions and 128 deletions

View File

@@ -40,7 +40,7 @@ type stateBackend interface {
ContainerStart(ctx context.Context, name string, checkpoint string, checkpointDir string) error
ContainerStop(ctx context.Context, name string, options container.StopOptions) error
ContainerUnpause(name string) error
ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error)
ContainerUpdate(name string, hostConfig *container.HostConfig) (container.UpdateResponse, error)
ContainerWait(ctx context.Context, name string, condition containerpkg.WaitCondition) (<-chan containerpkg.StateStatus, error)
}
@@ -50,7 +50,7 @@ type monitorBackend interface {
ContainerInspect(ctx context.Context, name string, options backend.ContainerInspectOptions) (*container.InspectResponse, error)
ContainerLogs(ctx context.Context, name string, config *container.LogsOptions) (msgs <-chan *backend.LogMessage, tty bool, err error)
ContainerStats(ctx context.Context, name string, config *backend.ContainerStatsConfig) error
ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error)
ContainerTop(name string, psArgs string) (*container.TopResponse, error)
Containers(ctx context.Context, config *container.ListOptions) ([]*container.Summary, error)
}

View File

@@ -5326,6 +5326,21 @@ definitions:
type: "string"
example: []
ContainerUpdateResponse:
type: "object"
title: "ContainerUpdateResponse"
x-go-name: "UpdateResponse"
description: |-
Response for a successful container-update.
properties:
Warnings:
type: "array"
description: |-
Warnings encountered when updating the container.
items:
type: "string"
example: ["Published ports are discarded when using host network mode"]
ContainerStatsResponse:
description: |
Statistics sample for a container.
@@ -5871,6 +5886,58 @@ definitions:
x-nullable: true
example: 7593984
ContainerTopResponse:
type: "object"
x-go-name: "TopResponse"
title: "ContainerTopResponse"
description: |-
Container "top" response.
properties:
Titles:
description: "The ps column titles"
type: "array"
items:
type: "string"
example:
Titles:
- "UID"
- "PID"
- "PPID"
- "C"
- "STIME"
- "TTY"
- "TIME"
- "CMD"
Processes:
description: |-
Each process running in the container, where each process
is an array of values corresponding to the titles.
type: "array"
items:
type: "array"
items:
type: "string"
example:
Processes:
-
- "root"
- "13642"
- "882"
- "0"
- "17:03"
- "pts/0"
- "00:00:00"
- "/bin/bash"
-
- "root"
- "13735"
- "13642"
- "0"
- "17:06"
- "pts/0"
- "00:00:00"
- "sleep 10"
ContainerWaitResponse:
description: "OK response to ContainerWait operation"
type: "object"
@@ -8072,54 +8139,7 @@ paths:
200:
description: "no error"
schema:
type: "object"
title: "ContainerTopResponse"
description: "OK response to ContainerTop operation"
properties:
Titles:
description: "The ps column titles"
type: "array"
items:
type: "string"
Processes:
description: |
Each process running in the container, where each is process
is an array of values corresponding to the titles.
type: "array"
items:
type: "array"
items:
type: "string"
examples:
application/json:
Titles:
- "UID"
- "PID"
- "PPID"
- "C"
- "STIME"
- "TTY"
- "TIME"
- "CMD"
Processes:
-
- "root"
- "13642"
- "882"
- "0"
- "17:03"
- "pts/0"
- "00:00:00"
- "/bin/bash"
-
- "root"
- "13735"
- "13642"
- "0"
- "17:06"
- "pts/0"
- "00:00:00"
- "sleep 10"
$ref: "#/definitions/ContainerTopResponse"
404:
description: "no such container"
schema:
@@ -8560,14 +8580,7 @@ paths:
200:
description: "The container has been updated."
schema:
type: "object"
title: "ContainerUpdateResponse"
description: "OK response to ContainerUpdate operation"
properties:
Warnings:
type: "array"
items:
type: "string"
$ref: "#/definitions/ContainerUpdateResponse"
404:
description: "no such container"
schema:

View File

@@ -10,6 +10,16 @@ import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// ContainerUpdateOKBody OK response to ContainerUpdate operation
//
// Deprecated: use [UpdateResponse]. This alias will be removed in the next release.
type ContainerUpdateOKBody = UpdateResponse
// ContainerTopOKBody OK response to ContainerTop operation
//
// Deprecated: use [TopResponse]. This alias will be removed in the next release.
type ContainerTopOKBody = TopResponse
// PruneReport contains the response for Engine API:
// POST "/containers/prune"
type PruneReport struct {

View File

@@ -1,22 +0,0 @@
package container // import "github.com/docker/docker/api/types/container"
// ----------------------------------------------------------------------------
// Code generated by `swagger generate operation`. DO NOT EDIT.
//
// See hack/generate-swagger-api.sh
// ----------------------------------------------------------------------------
// ContainerTopOKBody OK response to ContainerTop operation
// swagger:model ContainerTopOKBody
type ContainerTopOKBody struct {
// Each process running in the container, where each is process
// is an array of values corresponding to the titles.
//
// Required: true
Processes [][]string `json:"Processes"`
// The ps column titles
// Required: true
Titles []string `json:"Titles"`
}

View File

@@ -1,16 +0,0 @@
package container // import "github.com/docker/docker/api/types/container"
// ----------------------------------------------------------------------------
// Code generated by `swagger generate operation`. DO NOT EDIT.
//
// See hack/generate-swagger-api.sh
// ----------------------------------------------------------------------------
// ContainerUpdateOKBody OK response to ContainerUpdate operation
// swagger:model ContainerUpdateOKBody
type ContainerUpdateOKBody struct {
// warnings
// Required: true
Warnings []string `json:"Warnings"`
}

View File

@@ -0,0 +1,18 @@
package container
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// TopResponse ContainerTopResponse
//
// Container "top" response.
// swagger:model TopResponse
type TopResponse struct {
// Each process running in the container, where each process
// is an array of values corresponding to the titles.
Processes [][]string `json:"Processes"`
// The ps column titles
Titles []string `json:"Titles"`
}

View File

@@ -0,0 +1,14 @@
package container
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// UpdateResponse ContainerUpdateResponse
//
// Response for a successful container-update.
// swagger:model UpdateResponse
type UpdateResponse struct {
// Warnings encountered when updating the container.
Warnings []string `json:"Warnings"`
}

View File

@@ -93,9 +93,9 @@ type ContainerAPIClient interface {
ContainerStatsOneShot(ctx context.Context, container string) (container.StatsResponseReader, error)
ContainerStart(ctx context.Context, container string, options container.StartOptions) error
ContainerStop(ctx context.Context, container string, options container.StopOptions) error
ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error)
ContainerTop(ctx context.Context, container string, arguments []string) (container.TopResponse, error)
ContainerUnpause(ctx context.Context, container string) error
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error)
ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.UpdateResponse, error)
ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.WaitResponse, <-chan error)
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, container.PathStat, error)
CopyToContainer(ctx context.Context, container, path string, content io.Reader, options container.CopyToContainerOptions) error

View File

@@ -10,10 +10,10 @@ import (
)
// ContainerTop shows process information from within a container.
func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.ContainerTopOKBody, error) {
func (cli *Client) ContainerTop(ctx context.Context, containerID string, arguments []string) (container.TopResponse, error) {
containerID, err := trimID("container", containerID)
if err != nil {
return container.ContainerTopOKBody{}, err
return container.TopResponse{}, err
}
query := url.Values{}
@@ -24,10 +24,10 @@ func (cli *Client) ContainerTop(ctx context.Context, containerID string, argumen
resp, err := cli.get(ctx, "/containers/"+containerID+"/top", query, nil)
defer ensureReaderClosed(resp)
if err != nil {
return container.ContainerTopOKBody{}, err
return container.TopResponse{}, err
}
var response container.ContainerTopOKBody
var response container.TopResponse
err = json.NewDecoder(resp.body).Decode(&response)
return response, err
}

View File

@@ -52,7 +52,7 @@ func TestContainerTop(t *testing.T) {
return nil, fmt.Errorf("args not set in URL query properly. Expected 'arg1 arg2', got %v", args)
}
b, err := json.Marshal(container.ContainerTopOKBody{
b, err := json.Marshal(container.TopResponse{
Processes: [][]string{
{"p1", "p2"},
{"p3"},

View File

@@ -8,19 +8,19 @@ import (
)
// ContainerUpdate updates the resources of a container.
func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) {
func (cli *Client) ContainerUpdate(ctx context.Context, containerID string, updateConfig container.UpdateConfig) (container.UpdateResponse, error) {
containerID, err := trimID("container", containerID)
if err != nil {
return container.ContainerUpdateOKBody{}, err
return container.UpdateResponse{}, err
}
serverResp, err := cli.post(ctx, "/containers/"+containerID+"/update", nil, updateConfig, nil)
defer ensureReaderClosed(serverResp)
if err != nil {
return container.ContainerUpdateOKBody{}, err
return container.UpdateResponse{}, err
}
var response container.ContainerUpdateOKBody
var response container.UpdateResponse
err = json.NewDecoder(serverResp.body).Decode(&response)
return response, err
}

View File

@@ -41,7 +41,7 @@ func TestContainerUpdate(t *testing.T) {
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
}
b, err := json.Marshal(container.ContainerUpdateOKBody{})
b, err := json.Marshal(container.UpdateResponse{})
if err != nil {
return nil, err
}

View File

@@ -50,7 +50,7 @@ func fieldsASCII(s string) []string {
return strings.FieldsFunc(s, fn)
}
func appendProcess2ProcList(procList *container.ContainerTopOKBody, fields []string) {
func appendProcess2ProcList(procList *container.TopResponse, fields []string) {
// Make sure number of fields equals number of header titles
// merging "overhanging" fields
process := fields[:len(procList.Titles)-1]
@@ -67,8 +67,8 @@ func hasPid(procs []uint32, pid int) bool {
return false
}
func parsePSOutput(output []byte, procs []uint32) (*container.ContainerTopOKBody, error) {
procList := &container.ContainerTopOKBody{}
func parsePSOutput(output []byte, procs []uint32) (*container.TopResponse, error) {
procList := &container.TopResponse{}
lines := strings.Split(string(output), "\n")
procList.Titles = fieldsASCII(lines[0])
@@ -139,7 +139,7 @@ func psPidsArg(pids []uint32) string {
// "-ef" if no args are given. An error is returned if the container
// is not found, or is not running, or if there are any problems
// running ps, or parsing the output.
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.ContainerTopOKBody, error) {
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.TopResponse, error) {
if psArgs == "" {
psArgs = "-ef"
}

View File

@@ -6,7 +6,7 @@ import (
"fmt"
"time"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/container"
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
"github.com/docker/go-units"
)
@@ -26,27 +26,27 @@ import (
// task manager does and use the private working set as the memory counter.
// We could return more info for those who really understand how memory
// management works in Windows if we introduced a "raw" stats (above).
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.ContainerTopOKBody, error) {
func (daemon *Daemon) ContainerTop(name string, psArgs string) (*container.TopResponse, error) {
// It's not at all an equivalent to linux 'ps' on Windows
if psArgs != "" {
return nil, errors.New("Windows does not support arguments to top")
}
container, err := daemon.GetContainer(name)
ctr, err := daemon.GetContainer(name)
if err != nil {
return nil, err
}
task, err := func() (libcontainerdtypes.Task, error) {
container.Lock()
defer container.Unlock()
ctr.Lock()
defer ctr.Unlock()
task, err := container.GetRunningTask()
task, err := ctr.GetRunningTask()
if err != nil {
return nil, err
}
if container.Restarting {
return nil, errContainerIsRestarting(container.ID)
if ctr.Restarting {
return nil, errContainerIsRestarting(ctr.ID)
}
return task, nil
}()
@@ -55,8 +55,9 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.
if err != nil {
return nil, err
}
procList := &containertypes.ContainerTopOKBody{}
procList.Titles = []string{"Name", "PID", "CPU", "Private Working Set"}
procList := &container.TopResponse{
Titles: []string{"Name", "PID", "CPU", "Private Working Set"},
}
for _, j := range s {
d := time.Duration((j.KernelTime_100Ns + j.UserTime_100Ns) * 100) // Combined time in nanoseconds

View File

@@ -11,20 +11,20 @@ import (
)
// ContainerUpdate updates configuration of the container
func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error) {
func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig) (container.UpdateResponse, error) {
var warnings []string
daemonCfg := daemon.config()
warnings, err := daemon.verifyContainerSettings(daemonCfg, hostConfig, nil, true)
if err != nil {
return container.ContainerUpdateOKBody{Warnings: warnings}, errdefs.InvalidParameter(err)
return container.UpdateResponse{Warnings: warnings}, errdefs.InvalidParameter(err)
}
if err := daemon.update(name, hostConfig); err != nil {
return container.ContainerUpdateOKBody{Warnings: warnings}, err
return container.UpdateResponse{Warnings: warnings}, err
}
return container.ContainerUpdateOKBody{Warnings: warnings}, nil
return container.UpdateResponse{Warnings: warnings}, nil
}
func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) error {

View File

@@ -18,6 +18,8 @@ swagger generate model -f api/swagger.yaml \
swagger generate model -f api/swagger.yaml \
-t api -m types/container --skip-validator -C api/swagger-gen.yaml \
-n ContainerCreateResponse \
-n ContainerUpdateResponse \
-n ContainerTopResponse \
-n ContainerWaitResponse \
-n ContainerWaitExitError \
-n ChangeType \
@@ -44,8 +46,6 @@ swagger generate operation -f api/swagger.yaml \
-t api -a types -m types -C api/swagger-gen.yaml \
-T api/templates --skip-responses --skip-parameters --skip-validator \
-n Authenticate \
-n ContainerTop \
-n ContainerUpdate \
-n ImageHistory
swagger generate model -f api/swagger.yaml \