diff --git a/cli/command/network/client_test.go b/cli/command/network/client_test.go index 0834adfffe..20496e17e6 100644 --- a/cli/command/network/client_test.go +++ b/cli/command/network/client_test.go @@ -3,13 +3,12 @@ package network import ( "context" - "github.com/moby/moby/api/types/network" "github.com/moby/moby/client" ) type fakeClient struct { client.Client - networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error) + networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error) networkConnectFunc func(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error) networkDisconnectFunc func(ctx context.Context, networkID string, options client.NetworkDisconnectOptions) (client.NetworkDisconnectResult, error) networkRemoveFunc func(ctx context.Context, networkID string) error @@ -18,11 +17,11 @@ type fakeClient struct { networkInspectFunc func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (client.NetworkInspectResult, error) } -func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error) { +func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error) { if c.networkCreateFunc != nil { return c.networkCreateFunc(ctx, name, options) } - return network.CreateResponse{}, nil + return client.NetworkCreateResult{}, nil } func (c *fakeClient) NetworkConnect(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error) { diff --git a/cli/command/network/create.go b/cli/command/network/create.go index 6ef9837ad6..cf676a4cea 100644 --- a/cli/command/network/create.go +++ b/cli/command/network/create.go @@ -108,12 +108,6 @@ func runCreate(ctx context.Context, apiClient client.NetworkAPIClient, output io return err } - var configFrom *network.ConfigReference - if options.configFrom != "" { - configFrom = &network.ConfigReference{ - Network: options.configFrom, - } - } resp, err := apiClient.NetworkCreate(ctx, options.name, client.NetworkCreateOptions{ Driver: options.driver, Options: options.driverOpts.GetAll(), @@ -125,7 +119,7 @@ func runCreate(ctx context.Context, apiClient client.NetworkAPIClient, output io Ingress: options.ingress, Scope: options.scope, ConfigOnly: options.configOnly, - ConfigFrom: configFrom, + ConfigFrom: options.configFrom, Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()), }) if err != nil { diff --git a/cli/command/network/create_test.go b/cli/command/network/create_test.go index 50ae37bc56..7de25edb63 100644 --- a/cli/command/network/create_test.go +++ b/cli/command/network/create_test.go @@ -20,7 +20,7 @@ func TestNetworkCreateErrors(t *testing.T) { testCases := []struct { args []string flags map[string]string - networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error) + networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error) expectedError string }{ { @@ -28,8 +28,8 @@ func TestNetworkCreateErrors(t *testing.T) { }, { args: []string{"toto"}, - networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (network.CreateResponse, error) { - return network.CreateResponse{}, errors.New("error creating network") + networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (client.NetworkCreateResult, error) { + return client.NetworkCreateResult{}, errors.New("error creating network") }, expectedError: "error creating network", }, @@ -166,10 +166,10 @@ func TestNetworkCreateWithFlags(t *testing.T) { }, } cli := test.NewFakeCli(&fakeClient{ - networkCreateFunc: func(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error) { + networkCreateFunc: func(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error) { assert.Check(t, is.Equal(expectedDriver, options.Driver), "not expected driver error") assert.Check(t, is.DeepEqual(expectedOpts, options.IPAM.Config, cmpopts.EquateComparable(netip.Addr{}, netip.Prefix{})), "not expected driver error") - return network.CreateResponse{ + return client.NetworkCreateResult{ ID: name, }, nil }, @@ -224,9 +224,9 @@ func TestNetworkCreateIPv4(t *testing.T) { for _, tc := range tests { t.Run(tc.doc, func(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (network.CreateResponse, error) { + networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (client.NetworkCreateResult, error) { assert.Check(t, is.DeepEqual(createBody.EnableIPv4, tc.expected)) - return network.CreateResponse{ID: name}, nil + return client.NetworkCreateResult{ID: name}, nil }, }) cmd := newCreateCommand(cli) @@ -278,9 +278,9 @@ func TestNetworkCreateIPv6(t *testing.T) { for _, tc := range tests { t.Run(tc.doc, func(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (network.CreateResponse, error) { + networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (client.NetworkCreateResult, error) { assert.Check(t, is.DeepEqual(tc.expected, createBody.EnableIPv6)) - return network.CreateResponse{ID: name}, nil + return client.NetworkCreateResult{ID: name}, nil }, }) cmd := newCreateCommand(cli) diff --git a/vendor.mod b/vendor.mod index 7c2f750ca6..d4b3fb52b1 100644 --- a/vendor.mod +++ b/vendor.mod @@ -28,8 +28,8 @@ require ( github.com/google/uuid v1.6.0 github.com/mattn/go-runewidth v0.0.17 github.com/moby/go-archive v0.1.0 - github.com/moby/moby/api v1.52.0-beta.3.0.20251031021517-d96f50518f8d // master - github.com/moby/moby/client v0.1.0-beta.2.0.20251031021517-d96f50518f8d // master + github.com/moby/moby/api v1.52.0-beta.3.0.20251031153638-76ba3b6a4bb7 // master + github.com/moby/moby/client v0.1.0-beta.2.0.20251031153638-76ba3b6a4bb7 // master github.com/moby/patternmatcher v0.6.0 github.com/moby/swarmkit/v2 v2.1.0 github.com/moby/sys/atomicwriter v0.1.0 diff --git a/vendor.sum b/vendor.sum index 07408782a8..c493125184 100644 --- a/vendor.sum +++ b/vendor.sum @@ -170,10 +170,10 @@ github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3N github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ= github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo= -github.com/moby/moby/api v1.52.0-beta.3.0.20251031021517-d96f50518f8d h1:yv97052L6n+B7nwsJSms4aC8qDJcFKEuAoyNQAjJcUg= -github.com/moby/moby/api v1.52.0-beta.3.0.20251031021517-d96f50518f8d/go.mod h1:v0K/motq8oWmx+rtApG1rBTIpQ8KUONUjpf+U73gags= -github.com/moby/moby/client v0.1.0-beta.2.0.20251031021517-d96f50518f8d h1:wXNr/8nLcBwLH9RujUs3KgAxmGkpQ0AvQlTAnVaigoA= -github.com/moby/moby/client v0.1.0-beta.2.0.20251031021517-d96f50518f8d/go.mod h1:1YrJTvhL771Q4xiwwe72NSS17lgsCF67xu8fEfSd77g= +github.com/moby/moby/api v1.52.0-beta.3.0.20251031153638-76ba3b6a4bb7 h1:8zjAJN+JNF1UMPcy7MnC13B+TkpQcfMHbkLA8NuioHY= +github.com/moby/moby/api v1.52.0-beta.3.0.20251031153638-76ba3b6a4bb7/go.mod h1:v0K/motq8oWmx+rtApG1rBTIpQ8KUONUjpf+U73gags= +github.com/moby/moby/client v0.1.0-beta.2.0.20251031153638-76ba3b6a4bb7 h1:KHuqsXpsM/0PZdT+Hc+t1mrObGr1b8h9YEICaY77w14= +github.com/moby/moby/client v0.1.0-beta.2.0.20251031153638-76ba3b6a4bb7/go.mod h1:1YrJTvhL771Q4xiwwe72NSS17lgsCF67xu8fEfSd77g= github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= github.com/moby/swarmkit/v2 v2.1.0 h1:u+cJ5hSyF3HnzsyI+NtegYxdIPQIuibk7IbpXNxuISM= diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index b599b595bb..9750076f00 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -5,7 +5,6 @@ import ( "io" "net" - "github.com/moby/moby/api/types/network" "github.com/moby/moby/api/types/system" ) @@ -96,7 +95,6 @@ type ImageAPIClient interface { ImageBuild(ctx context.Context, context io.Reader, options ImageBuildOptions) (ImageBuildResult, error) BuildCachePrune(ctx context.Context, opts BuildCachePruneOptions) (BuildCachePruneResult, error) BuildCancel(ctx context.Context, id string, opts BuildCancelOptions) (BuildCancelResult, error) - ImageCreate(ctx context.Context, parentReference string, options ImageCreateOptions) (ImageCreateResult, error) ImageImport(ctx context.Context, source ImageImportSource, ref string, options ImageImportOptions) (ImageImportResult, error) ImageList(ctx context.Context, options ImageListOptions) (ImageListResult, error) @@ -116,7 +114,7 @@ type ImageAPIClient interface { // NetworkAPIClient defines API client methods for the networks type NetworkAPIClient interface { NetworkConnect(ctx context.Context, network string, options NetworkConnectOptions) (NetworkConnectResult, error) - NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) + NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (NetworkCreateResult, error) NetworkDisconnect(ctx context.Context, network string, options NetworkDisconnectOptions) (NetworkDisconnectResult, error) NetworkInspect(ctx context.Context, network string, options NetworkInspectOptions) (NetworkInspectResult, error) NetworkList(ctx context.Context, options NetworkListOptions) (NetworkListResult, error) diff --git a/vendor/github.com/moby/moby/client/image_create.go b/vendor/github.com/moby/moby/client/image_create.go deleted file mode 100644 index 4d429570c1..0000000000 --- a/vendor/github.com/moby/moby/client/image_create.go +++ /dev/null @@ -1,50 +0,0 @@ -package client - -import ( - "context" - "net/http" - "net/url" - - cerrdefs "github.com/containerd/errdefs" - "github.com/distribution/reference" - "github.com/moby/moby/api/types/registry" -) - -// ImageCreate creates a new image based on the parent options. -// It returns the JSON content in the response body. -func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options ImageCreateOptions) (ImageCreateResult, error) { - ref, err := reference.ParseNormalizedNamed(parentReference) - if err != nil { - return ImageCreateResult{}, err - } - - query := url.Values{} - query.Set("fromImage", ref.Name()) - query.Set("tag", getAPITagFromNamedRef(ref)) - if len(options.Platforms) > 0 { - if len(options.Platforms) > 1 { - // TODO(thaJeztah): update API spec and add equivalent check on the daemon. We need this still for older daemons, which would ignore it. - return ImageCreateResult{}, cerrdefs.ErrInvalidArgument.WithMessage("specifying multiple platforms is not yet supported") - } - query.Set("platform", formatPlatform(options.Platforms[0])) - } - resp, err := cli.tryImageCreate(ctx, query, staticAuth(options.RegistryAuth)) - if err != nil { - return ImageCreateResult{}, err - } - return ImageCreateResult{Body: resp.Body}, nil -} - -func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, resolveAuth registry.RequestAuthConfig) (*http.Response, error) { - hdr := http.Header{} - if resolveAuth != nil { - registryAuth, err := resolveAuth(ctx) - if err != nil { - return nil, err - } - if registryAuth != "" { - hdr.Set(registry.AuthHeader, registryAuth) - } - } - return cli.post(ctx, "/images/create", query, nil, hdr) -} diff --git a/vendor/github.com/moby/moby/client/image_create_opts.go b/vendor/github.com/moby/moby/client/image_create_opts.go deleted file mode 100644 index eb4c486c77..0000000000 --- a/vendor/github.com/moby/moby/client/image_create_opts.go +++ /dev/null @@ -1,21 +0,0 @@ -package client - -import ( - "io" - - ocispec "github.com/opencontainers/image-spec/specs-go/v1" -) - -// ImageCreateOptions holds information to create images. -type ImageCreateOptions struct { - RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry. - // Platforms specifies the platforms to platform of the image if it needs - // to be pulled from the registry. Multiple platforms can be provided - // if the daemon supports multi-platform pulls. - Platforms []ocispec.Platform -} - -// ImageCreateResult holds the response body returned by the daemon for image create. -type ImageCreateResult struct { - Body io.ReadCloser -} diff --git a/vendor/github.com/moby/moby/client/image_pull.go b/vendor/github.com/moby/moby/client/image_pull.go index e6e576a79d..11c0afa418 100644 --- a/vendor/github.com/moby/moby/client/image_pull.go +++ b/vendor/github.com/moby/moby/client/image_pull.go @@ -4,11 +4,13 @@ import ( "context" "io" "iter" + "net/http" "net/url" cerrdefs "github.com/containerd/errdefs" "github.com/distribution/reference" "github.com/moby/moby/api/types/jsonstream" + "github.com/moby/moby/api/types/registry" "github.com/moby/moby/client/internal" ) @@ -75,3 +77,17 @@ func getAPITagFromNamedRef(ref reference.Named) string { } return "" } + +func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, resolveAuth registry.RequestAuthConfig) (*http.Response, error) { + hdr := http.Header{} + if resolveAuth != nil { + registryAuth, err := resolveAuth(ctx) + if err != nil { + return nil, err + } + if registryAuth != "" { + hdr.Set(registry.AuthHeader, registryAuth) + } + } + return cli.post(ctx, "/images/create", query, nil, hdr) +} diff --git a/vendor/github.com/moby/moby/client/network_create.go b/vendor/github.com/moby/moby/client/network_create.go index c2703e6a73..25ea32af45 100644 --- a/vendor/github.com/moby/moby/client/network_create.go +++ b/vendor/github.com/moby/moby/client/network_create.go @@ -7,8 +7,31 @@ import ( "github.com/moby/moby/api/types/network" ) +// NetworkCreateOptions holds options to create a network. +type NetworkCreateOptions struct { + Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`) + Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level). + EnableIPv4 *bool // EnableIPv4 represents whether to enable IPv4. + EnableIPv6 *bool // EnableIPv6 represents whether to enable IPv6. + IPAM *network.IPAM // IPAM is the network's IP Address Management. + Internal bool // Internal represents if the network is used internal only. + Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. + Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. + ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services. + ConfigFrom string // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly]. + Options map[string]string // Options specifies the network-specific options to use for when creating the network. + Labels map[string]string // Labels holds metadata specific to the network being created. +} + +// NetworkCreateResult represents the result of a network create operation. +type NetworkCreateResult struct { + ID string + + Warning []string +} + // 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) (NetworkCreateResult, error) { req := network.CreateRequest{ Name: name, Driver: options.Driver, @@ -20,18 +43,27 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo Attachable: options.Attachable, Ingress: options.Ingress, ConfigOnly: options.ConfigOnly, - ConfigFrom: options.ConfigFrom, Options: options.Options, Labels: options.Labels, } + if options.ConfigFrom != "" { + req.ConfigFrom = &network.ConfigReference{Network: options.ConfigFrom} + } + resp, err := cli.post(ctx, "/networks/create", nil, req, nil) defer ensureReaderClosed(resp) if err != nil { - return network.CreateResponse{}, err + return NetworkCreateResult{}, err } var response network.CreateResponse err = json.NewDecoder(resp.Body).Decode(&response) - return response, err + + var warnings []string + if response.Warning != "" { + warnings = []string{response.Warning} + } + + return NetworkCreateResult{ID: response.ID, Warning: warnings}, err } diff --git a/vendor/github.com/moby/moby/client/network_create_opts.go b/vendor/github.com/moby/moby/client/network_create_opts.go deleted file mode 100644 index 5111d4a933..0000000000 --- a/vendor/github.com/moby/moby/client/network_create_opts.go +++ /dev/null @@ -1,19 +0,0 @@ -package client - -import "github.com/moby/moby/api/types/network" - -// NetworkCreateOptions holds options to create a network. -type NetworkCreateOptions struct { - Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`) - Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level). - EnableIPv4 *bool // EnableIPv4 represents whether to enable IPv4. - EnableIPv6 *bool // EnableIPv6 represents whether to enable IPv6. - IPAM *network.IPAM // IPAM is the network's IP Address Management. - Internal bool // Internal represents if the network is used internal only. - Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. - Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. - ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services. - ConfigFrom *network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly]. - Options map[string]string // Options specifies the network-specific options to use for when creating the network. - Labels map[string]string // Labels holds metadata specific to the network being created. -} diff --git a/vendor/modules.txt b/vendor/modules.txt index de6e6dbca9..3cb47efc9a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -168,7 +168,7 @@ github.com/moby/docker-image-spec/specs-go/v1 github.com/moby/go-archive github.com/moby/go-archive/compression github.com/moby/go-archive/tarheader -# github.com/moby/moby/api v1.52.0-beta.3.0.20251031021517-d96f50518f8d +# github.com/moby/moby/api v1.52.0-beta.3.0.20251031153638-76ba3b6a4bb7 ## explicit; go 1.23.0 github.com/moby/moby/api/pkg/authconfig github.com/moby/moby/api/pkg/stdcopy @@ -190,7 +190,7 @@ github.com/moby/moby/api/types/storage github.com/moby/moby/api/types/swarm github.com/moby/moby/api/types/system github.com/moby/moby/api/types/volume -# github.com/moby/moby/client v0.1.0-beta.2.0.20251031021517-d96f50518f8d +# github.com/moby/moby/client v0.1.0-beta.2.0.20251031153638-76ba3b6a4bb7 ## explicit; go 1.23.0 github.com/moby/moby/client github.com/moby/moby/client/internal