mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
client: remove API-version compatibility for API < v1.44
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -3,7 +3,6 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -25,54 +24,28 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config
|
|||||||
|
|
||||||
var response container.CreateResponse
|
var response container.CreateResponse
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cli.NewVersionError(ctx, "1.25", "stop timeout"); config.StopTimeout != nil && err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
if err := cli.NewVersionError(ctx, "1.41", "specify container image platform"); platform != nil && err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
if err := cli.NewVersionError(ctx, "1.44", "specify health-check start interval"); config.Healthcheck != nil && config.Healthcheck.StartInterval != 0 && err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
if err := cli.NewVersionError(ctx, "1.44", "specify mac-address per network"); hasEndpointSpecificMacAddress(networkingConfig) && err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if hostConfig != nil {
|
if hostConfig != nil {
|
||||||
if platform != nil && platform.OS == "linux" && versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
// When using API under 1.42, the Linux daemon doesn't respect the ConsoleSize
|
|
||||||
hostConfig.ConsoleSize = [2]uint{0, 0}
|
|
||||||
}
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.44") {
|
|
||||||
for _, m := range hostConfig.Mounts {
|
|
||||||
if m.BindOptions != nil {
|
|
||||||
// ReadOnlyNonRecursive can be safely ignored when API < 1.44
|
|
||||||
if m.BindOptions.ReadOnlyForceRecursive {
|
|
||||||
return response, errors.New("bind-recursive=readonly requires API v1.44 or later")
|
|
||||||
}
|
|
||||||
if m.BindOptions.NonRecursive && versions.LessThan(cli.ClientVersion(), "1.40") {
|
|
||||||
return response, errors.New("bind-recursive=disabled requires API v1.40 or later")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hostConfig.CapAdd = normalizeCapabilities(hostConfig.CapAdd)
|
hostConfig.CapAdd = normalizeCapabilities(hostConfig.CapAdd)
|
||||||
hostConfig.CapDrop = normalizeCapabilities(hostConfig.CapDrop)
|
hostConfig.CapDrop = normalizeCapabilities(hostConfig.CapDrop)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since API 1.44, the container-wide MacAddress is deprecated and triggers a WARNING if it's specified.
|
// FIXME(thaJeztah): remove this once we updated our (integration) tests;
|
||||||
if versions.GreaterThanOrEqualTo(cli.ClientVersion(), "1.44") {
|
// some integration tests depend on this to test old API versions; see https://github.com/moby/moby/pull/51120#issuecomment-3376224865
|
||||||
config.MacAddress = "" //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
|
if config.MacAddress != "" { //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
|
||||||
|
// Make sure we negotiated (if the client is configured to do so),
|
||||||
|
// as code below contains API-version specific handling of options.
|
||||||
|
//
|
||||||
|
// Normally, version-negotiation (if enabled) would not happen until
|
||||||
|
// the API request is made.
|
||||||
|
if err := cli.checkVersion(ctx); err != nil {
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
if versions.GreaterThanOrEqualTo(cli.ClientVersion(), "1.44") {
|
||||||
|
// Since API 1.44, the container-wide MacAddress is deprecated and triggers a WARNING if it's specified.
|
||||||
|
//
|
||||||
|
// FIXME(thaJeztah): remove the field from the API
|
||||||
|
config.MacAddress = "" //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/container"
|
"github.com/moby/moby/api/types/container"
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExecCreateOptions is a small subset of the Config struct that holds the configuration
|
// ExecCreateOptions is a small subset of the Config struct that holds the configuration
|
||||||
@@ -32,22 +31,6 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string,
|
|||||||
return container.ExecCreateResponse{}, err
|
return container.ExecCreateResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return container.ExecCreateResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cli.NewVersionError(ctx, "1.25", "env"); len(options.Env) != 0 && err != nil {
|
|
||||||
return container.ExecCreateResponse{}, err
|
|
||||||
}
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
options.ConsoleSize = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
req := container.ExecCreateRequest{
|
req := container.ExecCreateRequest{
|
||||||
User: options.User,
|
User: options.User,
|
||||||
Privileged: options.Privileged,
|
Privileged: options.Privileged,
|
||||||
@@ -86,19 +69,6 @@ type ExecStartOptions struct {
|
|||||||
|
|
||||||
// ContainerExecStart starts an exec process already created in the docker host.
|
// ContainerExecStart starts an exec process already created in the docker host.
|
||||||
func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config ExecStartOptions) error {
|
func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config ExecStartOptions) error {
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
config.ConsoleSize = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
req := container.ExecStartRequest{
|
req := container.ExecStartRequest{
|
||||||
Detach: config.Detach,
|
Detach: config.Detach,
|
||||||
Tty: config.Tty,
|
Tty: config.Tty,
|
||||||
@@ -133,9 +103,6 @@ type ExecAttachOptions = ExecStartOptions
|
|||||||
//
|
//
|
||||||
// [stdcopy.StdCopy]: https://pkg.go.dev/github.com/moby/moby/api/pkg/stdcopy#StdCopy
|
// [stdcopy.StdCopy]: https://pkg.go.dev/github.com/moby/moby/api/pkg/stdcopy#StdCopy
|
||||||
func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config ExecAttachOptions) (HijackedResponse, error) {
|
func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config ExecAttachOptions) (HijackedResponse, error) {
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
config.ConsoleSize = nil
|
|
||||||
}
|
|
||||||
req := container.ExecStartRequest{
|
req := container.ExecStartRequest{
|
||||||
Detach: config.Detach,
|
Detach: config.Detach,
|
||||||
Tty: config.Tty,
|
Tty: config.Tty,
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerRestart stops, and starts a container again.
|
// ContainerRestart stops, and starts a container again.
|
||||||
@@ -22,17 +20,7 @@ func (cli *Client) ContainerRestart(ctx context.Context, containerID string, opt
|
|||||||
query.Set("t", strconv.Itoa(*options.Timeout))
|
query.Set("t", strconv.Itoa(*options.Timeout))
|
||||||
}
|
}
|
||||||
if options.Signal != "" {
|
if options.Signal != "" {
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
query.Set("signal", options.Signal)
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if versions.GreaterThanOrEqualTo(cli.version, "1.42") {
|
|
||||||
query.Set("signal", options.Signal)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
|
resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
|
||||||
defer ensureReaderClosed(resp)
|
defer ensureReaderClosed(resp)
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerStopOptions holds the options to stop or restart a container.
|
// ContainerStopOptions holds the options to stop or restart a container.
|
||||||
@@ -44,17 +42,7 @@ func (cli *Client) ContainerStop(ctx context.Context, containerID string, option
|
|||||||
query.Set("t", strconv.Itoa(*options.Timeout))
|
query.Set("t", strconv.Itoa(*options.Timeout))
|
||||||
}
|
}
|
||||||
if options.Signal != "" {
|
if options.Signal != "" {
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
query.Set("signal", options.Signal)
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if versions.GreaterThanOrEqualTo(cli.version, "1.42") {
|
|
||||||
query.Set("signal", options.Signal)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil)
|
resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil)
|
||||||
defer ensureReaderClosed(resp)
|
defer ensureReaderClosed(resp)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/container"
|
"github.com/moby/moby/api/types/container"
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const containerWaitErrorMsgLimit = 2 * 1024 /* Max: 2KiB */
|
const containerWaitErrorMsgLimit = 2 * 1024 /* Max: 2KiB */
|
||||||
@@ -41,19 +40,6 @@ func (cli *Client) ContainerWait(ctx context.Context, containerID string, condit
|
|||||||
return resultC, errC
|
return resultC, errC
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
errC <- err
|
|
||||||
return resultC, errC
|
|
||||||
}
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.30") {
|
|
||||||
return cli.legacyContainerWait(ctx, containerID)
|
|
||||||
}
|
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
if condition != "" {
|
if condition != "" {
|
||||||
query.Set("condition", string(condition))
|
query.Set("condition", string(condition))
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,11 +27,6 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu
|
|||||||
return HijackedResponse{}, err
|
return HijackedResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
// Prior to 1.42, Content-Type is always set to raw-stream and not relevant
|
|
||||||
mediaType = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return NewHijackedResponse(conn, mediaType), nil
|
return NewHijackedResponse(conn, mediaType), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBuildOptions) (url.Values, error) {
|
func (cli *Client) imageBuildOptionsToQuery(_ context.Context, options ImageBuildOptions) (url.Values, error) {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
if len(options.Tags) > 0 {
|
if len(options.Tags) > 0 {
|
||||||
query["t"] = options.Tags
|
query["t"] = options.Tags
|
||||||
@@ -79,9 +79,7 @@ func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
if options.Squash {
|
if options.Squash {
|
||||||
if err := cli.NewVersionError(ctx, "1.25", "squash"); err != nil {
|
// TODO(thaJeztah): squash is experimental, and deprecated when using BuildKit?
|
||||||
return query, err
|
|
||||||
}
|
|
||||||
query.Set("squash", "1")
|
query.Set("squash", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +155,6 @@ func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBu
|
|||||||
query.Set("session", options.SessionID)
|
query.Set("session", options.SessionID)
|
||||||
}
|
}
|
||||||
if options.Platform != "" {
|
if options.Platform != "" {
|
||||||
if err := cli.NewVersionError(ctx, "1.32", "platform"); err != nil {
|
|
||||||
return query, err
|
|
||||||
}
|
|
||||||
query.Set("platform", strings.ToLower(options.Platform))
|
query.Set("platform", strings.ToLower(options.Platform))
|
||||||
}
|
}
|
||||||
if options.BuildID != "" {
|
if options.BuildID != "" {
|
||||||
|
|||||||
@@ -18,26 +18,28 @@ import (
|
|||||||
func (cli *Client) ImageList(ctx context.Context, options ImageListOptions) ([]image.Summary, error) {
|
func (cli *Client) ImageList(ctx context.Context, options ImageListOptions) ([]image.Summary, error) {
|
||||||
var images []image.Summary
|
var images []image.Summary
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return images, err
|
|
||||||
}
|
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
|
|
||||||
options.Filters.updateURLValues(query)
|
options.Filters.updateURLValues(query)
|
||||||
if options.All {
|
if options.All {
|
||||||
query.Set("all", "1")
|
query.Set("all", "1")
|
||||||
}
|
}
|
||||||
if options.SharedSize && versions.GreaterThanOrEqualTo(cli.version, "1.42") {
|
if options.SharedSize {
|
||||||
query.Set("shared-size", "1")
|
query.Set("shared-size", "1")
|
||||||
}
|
}
|
||||||
if options.Manifests && versions.GreaterThanOrEqualTo(cli.version, "1.47") {
|
if options.Manifests {
|
||||||
query.Set("manifests", "1")
|
// Make sure we negotiated (if the client is configured to do so),
|
||||||
|
// as code below contains API-version specific handling of options.
|
||||||
|
//
|
||||||
|
// Normally, version-negotiation (if enabled) would not happen until
|
||||||
|
// the API request is made.
|
||||||
|
if err := cli.checkVersion(ctx); err != nil {
|
||||||
|
return images, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if versions.GreaterThanOrEqualTo(cli.version, "1.47") {
|
||||||
|
query.Set("manifests", "1")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.get(ctx, "/images/json", query, nil)
|
resp, err := cli.get(ctx, "/images/json", query, nil)
|
||||||
|
|||||||
@@ -123,9 +123,8 @@ func TestImageListWithSharedSize(t *testing.T) {
|
|||||||
options ImageListOptions
|
options ImageListOptions
|
||||||
sharedSize string // expected value for the shared-size query param, or empty if it should not be set.
|
sharedSize string // expected value for the shared-size query param, or empty if it should not be set.
|
||||||
}{
|
}{
|
||||||
{name: "unset after 1.42, no options set", version: "1.42"},
|
{name: "unset, no options set"},
|
||||||
{name: "set after 1.42, if requested", version: "1.42", options: ImageListOptions{SharedSize: true}, sharedSize: "1"},
|
{name: "set", options: ImageListOptions{SharedSize: true}, sharedSize: "1"},
|
||||||
{name: "unset before 1.42, even if requested", version: "1.41", options: ImageListOptions{SharedSize: true}},
|
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
@@ -5,21 +5,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/network"
|
"github.com/moby/moby/api/types/network"
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NetworkCreate creates a new network in the docker host.
|
// NetworkCreate creates a new network in the docker host.
|
||||||
func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
|
func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
req := network.CreateRequest{
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return network.CreateResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
networkCreateRequest := network.CreateRequest{
|
|
||||||
Name: name,
|
Name: name,
|
||||||
Driver: options.Driver,
|
Driver: options.Driver,
|
||||||
Scope: options.Scope,
|
Scope: options.Scope,
|
||||||
@@ -35,27 +25,6 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo
|
|||||||
Labels: options.Labels,
|
Labels: options.Labels,
|
||||||
}
|
}
|
||||||
|
|
||||||
var req any
|
|
||||||
if versions.LessThan(cli.version, "1.44") {
|
|
||||||
// CheckDuplicate is removed in API v1.44, and no longer used by
|
|
||||||
// daemons supporting that API version (v25.0.0-beta.1 and up)
|
|
||||||
// regardless of the API version used, but it must be set to true
|
|
||||||
// when sent to older daemons.
|
|
||||||
//
|
|
||||||
// TODO(thaJeztah) remove this once daemon versions v24.0 and lower are no
|
|
||||||
// longer expected to be used (when Mirantis Container Runtime v23
|
|
||||||
// is EOL); https://github.com/moby/moby/blob/v2.0.0-beta.0/project/BRANCHES-AND-TAGS.md
|
|
||||||
req = struct {
|
|
||||||
network.CreateRequest
|
|
||||||
CheckDuplicate bool
|
|
||||||
}{
|
|
||||||
CreateRequest: networkCreateRequest,
|
|
||||||
CheckDuplicate: true,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
req = networkCreateRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
|
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
|
||||||
defer ensureReaderClosed(resp)
|
defer ensureReaderClosed(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/moby/moby/api/types/registry"
|
"github.com/moby/moby/api/types/registry"
|
||||||
"github.com/moby/moby/api/types/swarm"
|
"github.com/moby/moby/api/types/swarm"
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,21 +18,12 @@ import (
|
|||||||
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
|
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
|
||||||
var response swarm.ServiceCreateResponse
|
var response swarm.ServiceCreateResponse
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure containerSpec is not nil when no runtime is set or the runtime is set to container
|
// Make sure containerSpec is not nil when no runtime is set or the runtime is set to container
|
||||||
if service.TaskTemplate.ContainerSpec == nil && (service.TaskTemplate.Runtime == "" || service.TaskTemplate.Runtime == swarm.RuntimeContainer) {
|
if service.TaskTemplate.ContainerSpec == nil && (service.TaskTemplate.Runtime == "" || service.TaskTemplate.Runtime == swarm.RuntimeContainer) {
|
||||||
service.TaskTemplate.ContainerSpec = &swarm.ContainerSpec{}
|
service.TaskTemplate.ContainerSpec = &swarm.ContainerSpec{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateServiceSpec(service, cli.version); err != nil {
|
if err := validateServiceSpec(service); err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +162,7 @@ func digestWarning(image string) string {
|
|||||||
return fmt.Sprintf("image %s could not be accessed on a registry to record\nits digest. Each node will access %s independently,\npossibly leading to different nodes running different\nversions of the image.\n", image, image)
|
return fmt.Sprintf("image %s could not be accessed on a registry to record\nits digest. Each node will access %s independently,\npossibly leading to different nodes running different\nversions of the image.\n", image, image)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateServiceSpec(s swarm.ServiceSpec, apiVersion string) error {
|
func validateServiceSpec(s swarm.ServiceSpec) error {
|
||||||
if s.TaskTemplate.ContainerSpec != nil && s.TaskTemplate.PluginSpec != nil {
|
if s.TaskTemplate.ContainerSpec != nil && s.TaskTemplate.PluginSpec != nil {
|
||||||
return errors.New("must not specify both a container spec and a plugin spec in the task template")
|
return errors.New("must not specify both a container spec and a plugin spec in the task template")
|
||||||
}
|
}
|
||||||
@@ -182,18 +172,5 @@ func validateServiceSpec(s swarm.ServiceSpec, apiVersion string) error {
|
|||||||
if s.TaskTemplate.ContainerSpec != nil && (s.TaskTemplate.Runtime != "" && s.TaskTemplate.Runtime != swarm.RuntimeContainer) {
|
if s.TaskTemplate.ContainerSpec != nil && (s.TaskTemplate.Runtime != "" && s.TaskTemplate.Runtime != swarm.RuntimeContainer) {
|
||||||
return errors.New("mismatched runtime with container spec")
|
return errors.New("mismatched runtime with container spec")
|
||||||
}
|
}
|
||||||
if s.TaskTemplate.ContainerSpec != nil && apiVersion != "" && versions.LessThan(apiVersion, "1.44") {
|
|
||||||
for _, m := range s.TaskTemplate.ContainerSpec.Mounts {
|
|
||||||
if m.BindOptions != nil {
|
|
||||||
if m.BindOptions.NonRecursive && versions.LessThan(apiVersion, "1.40") {
|
|
||||||
return errors.New("bind-recursive=disabled requires API v1.40 or later")
|
|
||||||
}
|
|
||||||
// ReadOnlyNonRecursive can be safely ignored when API < 1.44
|
|
||||||
if m.BindOptions.ReadOnlyForceRecursive && versions.LessThan(apiVersion, "1.44") {
|
|
||||||
return errors.New("bind-recursive=readonly requires API v1.44 or later")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,7 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version
|
|||||||
return swarm.ServiceUpdateResponse{}, err
|
return swarm.ServiceUpdateResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
if err := validateServiceSpec(service); err != nil {
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return swarm.ServiceUpdateResponse{}, err
|
|
||||||
}
|
|
||||||
if err := validateServiceSpec(service, cli.version); err != nil {
|
|
||||||
return swarm.ServiceUpdateResponse{}, err
|
return swarm.ServiceUpdateResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
61
vendor/github.com/moby/moby/client/container_create.go
generated
vendored
61
vendor/github.com/moby/moby/client/container_create.go
generated
vendored
@@ -3,7 +3,6 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -25,54 +24,28 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config
|
|||||||
|
|
||||||
var response container.CreateResponse
|
var response container.CreateResponse
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cli.NewVersionError(ctx, "1.25", "stop timeout"); config.StopTimeout != nil && err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
if err := cli.NewVersionError(ctx, "1.41", "specify container image platform"); platform != nil && err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
if err := cli.NewVersionError(ctx, "1.44", "specify health-check start interval"); config.Healthcheck != nil && config.Healthcheck.StartInterval != 0 && err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
if err := cli.NewVersionError(ctx, "1.44", "specify mac-address per network"); hasEndpointSpecificMacAddress(networkingConfig) && err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if hostConfig != nil {
|
if hostConfig != nil {
|
||||||
if platform != nil && platform.OS == "linux" && versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
// When using API under 1.42, the Linux daemon doesn't respect the ConsoleSize
|
|
||||||
hostConfig.ConsoleSize = [2]uint{0, 0}
|
|
||||||
}
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.44") {
|
|
||||||
for _, m := range hostConfig.Mounts {
|
|
||||||
if m.BindOptions != nil {
|
|
||||||
// ReadOnlyNonRecursive can be safely ignored when API < 1.44
|
|
||||||
if m.BindOptions.ReadOnlyForceRecursive {
|
|
||||||
return response, errors.New("bind-recursive=readonly requires API v1.44 or later")
|
|
||||||
}
|
|
||||||
if m.BindOptions.NonRecursive && versions.LessThan(cli.ClientVersion(), "1.40") {
|
|
||||||
return response, errors.New("bind-recursive=disabled requires API v1.40 or later")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hostConfig.CapAdd = normalizeCapabilities(hostConfig.CapAdd)
|
hostConfig.CapAdd = normalizeCapabilities(hostConfig.CapAdd)
|
||||||
hostConfig.CapDrop = normalizeCapabilities(hostConfig.CapDrop)
|
hostConfig.CapDrop = normalizeCapabilities(hostConfig.CapDrop)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since API 1.44, the container-wide MacAddress is deprecated and triggers a WARNING if it's specified.
|
// FIXME(thaJeztah): remove this once we updated our (integration) tests;
|
||||||
if versions.GreaterThanOrEqualTo(cli.ClientVersion(), "1.44") {
|
// some integration tests depend on this to test old API versions; see https://github.com/moby/moby/pull/51120#issuecomment-3376224865
|
||||||
config.MacAddress = "" //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
|
if config.MacAddress != "" { //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
|
||||||
|
// Make sure we negotiated (if the client is configured to do so),
|
||||||
|
// as code below contains API-version specific handling of options.
|
||||||
|
//
|
||||||
|
// Normally, version-negotiation (if enabled) would not happen until
|
||||||
|
// the API request is made.
|
||||||
|
if err := cli.checkVersion(ctx); err != nil {
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
if versions.GreaterThanOrEqualTo(cli.ClientVersion(), "1.44") {
|
||||||
|
// Since API 1.44, the container-wide MacAddress is deprecated and triggers a WARNING if it's specified.
|
||||||
|
//
|
||||||
|
// FIXME(thaJeztah): remove the field from the API
|
||||||
|
config.MacAddress = "" //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
|
|||||||
33
vendor/github.com/moby/moby/client/container_exec.go
generated
vendored
33
vendor/github.com/moby/moby/client/container_exec.go
generated
vendored
@@ -6,7 +6,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/container"
|
"github.com/moby/moby/api/types/container"
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExecCreateOptions is a small subset of the Config struct that holds the configuration
|
// ExecCreateOptions is a small subset of the Config struct that holds the configuration
|
||||||
@@ -32,22 +31,6 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string,
|
|||||||
return container.ExecCreateResponse{}, err
|
return container.ExecCreateResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return container.ExecCreateResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cli.NewVersionError(ctx, "1.25", "env"); len(options.Env) != 0 && err != nil {
|
|
||||||
return container.ExecCreateResponse{}, err
|
|
||||||
}
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
options.ConsoleSize = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
req := container.ExecCreateRequest{
|
req := container.ExecCreateRequest{
|
||||||
User: options.User,
|
User: options.User,
|
||||||
Privileged: options.Privileged,
|
Privileged: options.Privileged,
|
||||||
@@ -86,19 +69,6 @@ type ExecStartOptions struct {
|
|||||||
|
|
||||||
// ContainerExecStart starts an exec process already created in the docker host.
|
// ContainerExecStart starts an exec process already created in the docker host.
|
||||||
func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config ExecStartOptions) error {
|
func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config ExecStartOptions) error {
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
config.ConsoleSize = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
req := container.ExecStartRequest{
|
req := container.ExecStartRequest{
|
||||||
Detach: config.Detach,
|
Detach: config.Detach,
|
||||||
Tty: config.Tty,
|
Tty: config.Tty,
|
||||||
@@ -133,9 +103,6 @@ type ExecAttachOptions = ExecStartOptions
|
|||||||
//
|
//
|
||||||
// [stdcopy.StdCopy]: https://pkg.go.dev/github.com/moby/moby/api/pkg/stdcopy#StdCopy
|
// [stdcopy.StdCopy]: https://pkg.go.dev/github.com/moby/moby/api/pkg/stdcopy#StdCopy
|
||||||
func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config ExecAttachOptions) (HijackedResponse, error) {
|
func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config ExecAttachOptions) (HijackedResponse, error) {
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
config.ConsoleSize = nil
|
|
||||||
}
|
|
||||||
req := container.ExecStartRequest{
|
req := container.ExecStartRequest{
|
||||||
Detach: config.Detach,
|
Detach: config.Detach,
|
||||||
Tty: config.Tty,
|
Tty: config.Tty,
|
||||||
|
|||||||
14
vendor/github.com/moby/moby/client/container_restart.go
generated
vendored
14
vendor/github.com/moby/moby/client/container_restart.go
generated
vendored
@@ -4,8 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerRestart stops, and starts a container again.
|
// ContainerRestart stops, and starts a container again.
|
||||||
@@ -22,17 +20,7 @@ func (cli *Client) ContainerRestart(ctx context.Context, containerID string, opt
|
|||||||
query.Set("t", strconv.Itoa(*options.Timeout))
|
query.Set("t", strconv.Itoa(*options.Timeout))
|
||||||
}
|
}
|
||||||
if options.Signal != "" {
|
if options.Signal != "" {
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
query.Set("signal", options.Signal)
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if versions.GreaterThanOrEqualTo(cli.version, "1.42") {
|
|
||||||
query.Set("signal", options.Signal)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
|
resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
|
||||||
defer ensureReaderClosed(resp)
|
defer ensureReaderClosed(resp)
|
||||||
|
|||||||
14
vendor/github.com/moby/moby/client/container_stop.go
generated
vendored
14
vendor/github.com/moby/moby/client/container_stop.go
generated
vendored
@@ -4,8 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerStopOptions holds the options to stop or restart a container.
|
// ContainerStopOptions holds the options to stop or restart a container.
|
||||||
@@ -44,17 +42,7 @@ func (cli *Client) ContainerStop(ctx context.Context, containerID string, option
|
|||||||
query.Set("t", strconv.Itoa(*options.Timeout))
|
query.Set("t", strconv.Itoa(*options.Timeout))
|
||||||
}
|
}
|
||||||
if options.Signal != "" {
|
if options.Signal != "" {
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
query.Set("signal", options.Signal)
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if versions.GreaterThanOrEqualTo(cli.version, "1.42") {
|
|
||||||
query.Set("signal", options.Signal)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil)
|
resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil)
|
||||||
defer ensureReaderClosed(resp)
|
defer ensureReaderClosed(resp)
|
||||||
|
|||||||
14
vendor/github.com/moby/moby/client/container_wait.go
generated
vendored
14
vendor/github.com/moby/moby/client/container_wait.go
generated
vendored
@@ -9,7 +9,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/container"
|
"github.com/moby/moby/api/types/container"
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const containerWaitErrorMsgLimit = 2 * 1024 /* Max: 2KiB */
|
const containerWaitErrorMsgLimit = 2 * 1024 /* Max: 2KiB */
|
||||||
@@ -41,19 +40,6 @@ func (cli *Client) ContainerWait(ctx context.Context, containerID string, condit
|
|||||||
return resultC, errC
|
return resultC, errC
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
errC <- err
|
|
||||||
return resultC, errC
|
|
||||||
}
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.30") {
|
|
||||||
return cli.legacyContainerWait(ctx, containerID)
|
|
||||||
}
|
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
if condition != "" {
|
if condition != "" {
|
||||||
query.Set("condition", string(condition))
|
query.Set("condition", string(condition))
|
||||||
|
|||||||
6
vendor/github.com/moby/moby/client/hijack.go
generated
vendored
6
vendor/github.com/moby/moby/client/hijack.go
generated
vendored
@@ -9,7 +9,6 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,11 +27,6 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu
|
|||||||
return HijackedResponse{}, err
|
return HijackedResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if versions.LessThan(cli.ClientVersion(), "1.42") {
|
|
||||||
// Prior to 1.42, Content-Type is always set to raw-stream and not relevant
|
|
||||||
mediaType = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return NewHijackedResponse(conn, mediaType), nil
|
return NewHijackedResponse(conn, mediaType), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
vendor/github.com/moby/moby/client/image_build.go
generated
vendored
9
vendor/github.com/moby/moby/client/image_build.go
generated
vendored
@@ -42,7 +42,7 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBuildOptions) (url.Values, error) {
|
func (cli *Client) imageBuildOptionsToQuery(_ context.Context, options ImageBuildOptions) (url.Values, error) {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
if len(options.Tags) > 0 {
|
if len(options.Tags) > 0 {
|
||||||
query["t"] = options.Tags
|
query["t"] = options.Tags
|
||||||
@@ -79,9 +79,7 @@ func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
if options.Squash {
|
if options.Squash {
|
||||||
if err := cli.NewVersionError(ctx, "1.25", "squash"); err != nil {
|
// TODO(thaJeztah): squash is experimental, and deprecated when using BuildKit?
|
||||||
return query, err
|
|
||||||
}
|
|
||||||
query.Set("squash", "1")
|
query.Set("squash", "1")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,9 +155,6 @@ func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBu
|
|||||||
query.Set("session", options.SessionID)
|
query.Set("session", options.SessionID)
|
||||||
}
|
}
|
||||||
if options.Platform != "" {
|
if options.Platform != "" {
|
||||||
if err := cli.NewVersionError(ctx, "1.32", "platform"); err != nil {
|
|
||||||
return query, err
|
|
||||||
}
|
|
||||||
query.Set("platform", strings.ToLower(options.Platform))
|
query.Set("platform", strings.ToLower(options.Platform))
|
||||||
}
|
}
|
||||||
if options.BuildID != "" {
|
if options.BuildID != "" {
|
||||||
|
|||||||
26
vendor/github.com/moby/moby/client/image_list.go
generated
vendored
26
vendor/github.com/moby/moby/client/image_list.go
generated
vendored
@@ -18,26 +18,28 @@ import (
|
|||||||
func (cli *Client) ImageList(ctx context.Context, options ImageListOptions) ([]image.Summary, error) {
|
func (cli *Client) ImageList(ctx context.Context, options ImageListOptions) ([]image.Summary, error) {
|
||||||
var images []image.Summary
|
var images []image.Summary
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return images, err
|
|
||||||
}
|
|
||||||
|
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
|
|
||||||
options.Filters.updateURLValues(query)
|
options.Filters.updateURLValues(query)
|
||||||
if options.All {
|
if options.All {
|
||||||
query.Set("all", "1")
|
query.Set("all", "1")
|
||||||
}
|
}
|
||||||
if options.SharedSize && versions.GreaterThanOrEqualTo(cli.version, "1.42") {
|
if options.SharedSize {
|
||||||
query.Set("shared-size", "1")
|
query.Set("shared-size", "1")
|
||||||
}
|
}
|
||||||
if options.Manifests && versions.GreaterThanOrEqualTo(cli.version, "1.47") {
|
if options.Manifests {
|
||||||
query.Set("manifests", "1")
|
// Make sure we negotiated (if the client is configured to do so),
|
||||||
|
// as code below contains API-version specific handling of options.
|
||||||
|
//
|
||||||
|
// Normally, version-negotiation (if enabled) would not happen until
|
||||||
|
// the API request is made.
|
||||||
|
if err := cli.checkVersion(ctx); err != nil {
|
||||||
|
return images, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if versions.GreaterThanOrEqualTo(cli.version, "1.47") {
|
||||||
|
query.Set("manifests", "1")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := cli.get(ctx, "/images/json", query, nil)
|
resp, err := cli.get(ctx, "/images/json", query, nil)
|
||||||
|
|||||||
33
vendor/github.com/moby/moby/client/network_create.go
generated
vendored
33
vendor/github.com/moby/moby/client/network_create.go
generated
vendored
@@ -5,21 +5,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/moby/moby/api/types/network"
|
"github.com/moby/moby/api/types/network"
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NetworkCreate creates a new network in the docker host.
|
// NetworkCreate creates a new network in the docker host.
|
||||||
func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
|
func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
req := network.CreateRequest{
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return network.CreateResponse{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
networkCreateRequest := network.CreateRequest{
|
|
||||||
Name: name,
|
Name: name,
|
||||||
Driver: options.Driver,
|
Driver: options.Driver,
|
||||||
Scope: options.Scope,
|
Scope: options.Scope,
|
||||||
@@ -35,27 +25,6 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo
|
|||||||
Labels: options.Labels,
|
Labels: options.Labels,
|
||||||
}
|
}
|
||||||
|
|
||||||
var req any
|
|
||||||
if versions.LessThan(cli.version, "1.44") {
|
|
||||||
// CheckDuplicate is removed in API v1.44, and no longer used by
|
|
||||||
// daemons supporting that API version (v25.0.0-beta.1 and up)
|
|
||||||
// regardless of the API version used, but it must be set to true
|
|
||||||
// when sent to older daemons.
|
|
||||||
//
|
|
||||||
// TODO(thaJeztah) remove this once daemon versions v24.0 and lower are no
|
|
||||||
// longer expected to be used (when Mirantis Container Runtime v23
|
|
||||||
// is EOL); https://github.com/moby/moby/blob/v2.0.0-beta.0/project/BRANCHES-AND-TAGS.md
|
|
||||||
req = struct {
|
|
||||||
network.CreateRequest
|
|
||||||
CheckDuplicate bool
|
|
||||||
}{
|
|
||||||
CreateRequest: networkCreateRequest,
|
|
||||||
CheckDuplicate: true,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
req = networkCreateRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
|
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
|
||||||
defer ensureReaderClosed(resp)
|
defer ensureReaderClosed(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
27
vendor/github.com/moby/moby/client/service_create.go
generated
vendored
27
vendor/github.com/moby/moby/client/service_create.go
generated
vendored
@@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/moby/moby/api/types/registry"
|
"github.com/moby/moby/api/types/registry"
|
||||||
"github.com/moby/moby/api/types/swarm"
|
"github.com/moby/moby/api/types/swarm"
|
||||||
"github.com/moby/moby/api/types/versions"
|
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,21 +18,12 @@ import (
|
|||||||
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
|
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options ServiceCreateOptions) (swarm.ServiceCreateResponse, error) {
|
||||||
var response swarm.ServiceCreateResponse
|
var response swarm.ServiceCreateResponse
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return response, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure containerSpec is not nil when no runtime is set or the runtime is set to container
|
// Make sure containerSpec is not nil when no runtime is set or the runtime is set to container
|
||||||
if service.TaskTemplate.ContainerSpec == nil && (service.TaskTemplate.Runtime == "" || service.TaskTemplate.Runtime == swarm.RuntimeContainer) {
|
if service.TaskTemplate.ContainerSpec == nil && (service.TaskTemplate.Runtime == "" || service.TaskTemplate.Runtime == swarm.RuntimeContainer) {
|
||||||
service.TaskTemplate.ContainerSpec = &swarm.ContainerSpec{}
|
service.TaskTemplate.ContainerSpec = &swarm.ContainerSpec{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateServiceSpec(service, cli.version); err != nil {
|
if err := validateServiceSpec(service); err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +162,7 @@ func digestWarning(image string) string {
|
|||||||
return fmt.Sprintf("image %s could not be accessed on a registry to record\nits digest. Each node will access %s independently,\npossibly leading to different nodes running different\nversions of the image.\n", image, image)
|
return fmt.Sprintf("image %s could not be accessed on a registry to record\nits digest. Each node will access %s independently,\npossibly leading to different nodes running different\nversions of the image.\n", image, image)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateServiceSpec(s swarm.ServiceSpec, apiVersion string) error {
|
func validateServiceSpec(s swarm.ServiceSpec) error {
|
||||||
if s.TaskTemplate.ContainerSpec != nil && s.TaskTemplate.PluginSpec != nil {
|
if s.TaskTemplate.ContainerSpec != nil && s.TaskTemplate.PluginSpec != nil {
|
||||||
return errors.New("must not specify both a container spec and a plugin spec in the task template")
|
return errors.New("must not specify both a container spec and a plugin spec in the task template")
|
||||||
}
|
}
|
||||||
@@ -182,18 +172,5 @@ func validateServiceSpec(s swarm.ServiceSpec, apiVersion string) error {
|
|||||||
if s.TaskTemplate.ContainerSpec != nil && (s.TaskTemplate.Runtime != "" && s.TaskTemplate.Runtime != swarm.RuntimeContainer) {
|
if s.TaskTemplate.ContainerSpec != nil && (s.TaskTemplate.Runtime != "" && s.TaskTemplate.Runtime != swarm.RuntimeContainer) {
|
||||||
return errors.New("mismatched runtime with container spec")
|
return errors.New("mismatched runtime with container spec")
|
||||||
}
|
}
|
||||||
if s.TaskTemplate.ContainerSpec != nil && apiVersion != "" && versions.LessThan(apiVersion, "1.44") {
|
|
||||||
for _, m := range s.TaskTemplate.ContainerSpec.Mounts {
|
|
||||||
if m.BindOptions != nil {
|
|
||||||
if m.BindOptions.NonRecursive && versions.LessThan(apiVersion, "1.40") {
|
|
||||||
return errors.New("bind-recursive=disabled requires API v1.40 or later")
|
|
||||||
}
|
|
||||||
// ReadOnlyNonRecursive can be safely ignored when API < 1.44
|
|
||||||
if m.BindOptions.ReadOnlyForceRecursive && versions.LessThan(apiVersion, "1.44") {
|
|
||||||
return errors.New("bind-recursive=readonly requires API v1.44 or later")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
10
vendor/github.com/moby/moby/client/service_update.go
generated
vendored
10
vendor/github.com/moby/moby/client/service_update.go
generated
vendored
@@ -20,15 +20,7 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version
|
|||||||
return swarm.ServiceUpdateResponse{}, err
|
return swarm.ServiceUpdateResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we negotiated (if the client is configured to do so),
|
if err := validateServiceSpec(service); err != nil {
|
||||||
// as code below contains API-version specific handling of options.
|
|
||||||
//
|
|
||||||
// Normally, version-negotiation (if enabled) would not happen until
|
|
||||||
// the API request is made.
|
|
||||||
if err := cli.checkVersion(ctx); err != nil {
|
|
||||||
return swarm.ServiceUpdateResponse{}, err
|
|
||||||
}
|
|
||||||
if err := validateServiceSpec(service, cli.version); err != nil {
|
|
||||||
return swarm.ServiceUpdateResponse{}, err
|
return swarm.ServiceUpdateResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user