Skip to content

Commit 71bc8ab

Browse files
authored
Merge pull request docker#6186 from thaJeztah/remove_more_aliases
opts: minor cleanup in tests, and remove some import aliases
2 parents 6cf2c02 + e95d133 commit 71bc8ab

File tree

5 files changed

+143
-134
lines changed

5 files changed

+143
-134
lines changed

cli/command/container/opts.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"github.com/docker/cli/internal/lazyregexp"
1717
"github.com/docker/cli/opts"
1818
"github.com/docker/docker/api/types/container"
19-
mounttypes "github.com/docker/docker/api/types/mount"
20-
networktypes "github.com/docker/docker/api/types/network"
19+
"github.com/docker/docker/api/types/mount"
20+
"github.com/docker/docker/api/types/network"
2121
"github.com/docker/go-connections/nat"
2222
"github.com/pkg/errors"
2323
"github.com/spf13/pflag"
@@ -323,7 +323,7 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
323323
type containerConfig struct {
324324
Config *container.Config
325325
HostConfig *container.HostConfig
326-
NetworkingConfig *networktypes.NetworkingConfig
326+
NetworkingConfig *network.NetworkingConfig
327327
}
328328

329329
// parse parses the args for the specified command and generates a Config,
@@ -372,7 +372,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
372372
if parsed.Source != "" {
373373
toBind := bind
374374

375-
if parsed.Type == string(mounttypes.TypeBind) {
375+
if parsed.Type == string(mount.TypeBind) {
376376
if hostPart, targetPath, ok := strings.Cut(bind, ":"); ok {
377377
if !filepath.IsAbs(hostPart) && strings.HasPrefix(hostPart, ".") {
378378
if absHostPart, err := filepath.Abs(hostPart); err == nil {
@@ -706,8 +706,8 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
706706
config.StdinOnce = true
707707
}
708708

709-
networkingConfig := &networktypes.NetworkingConfig{
710-
EndpointsConfig: make(map[string]*networktypes.EndpointSettings),
709+
networkingConfig := &network.NetworkingConfig{
710+
EndpointsConfig: make(map[string]*network.EndpointSettings),
711711
}
712712

713713
networkingConfig.EndpointsConfig, err = parseNetworkOpts(copts)
@@ -735,9 +735,9 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
735735
// this function may return _multiple_ endpoints, which is not currently supported
736736
// by the daemon, but may be in future; it's up to the daemon to produce an error
737737
// in case that is not supported.
738-
func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.EndpointSettings, error) {
738+
func parseNetworkOpts(copts *containerOptions) (map[string]*network.EndpointSettings, error) {
739739
var (
740-
endpoints = make(map[string]*networktypes.EndpointSettings, len(copts.netMode.Value()))
740+
endpoints = make(map[string]*network.EndpointSettings, len(copts.netMode.Value()))
741741
hasUserDefined, hasNonUserDefined bool
742742
)
743743

@@ -783,7 +783,7 @@ func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.Endpoin
783783
// and only a single network is specified, omit the endpoint-configuration
784784
// on the client (the daemon will still create it when creating the container)
785785
if i == 0 && len(copts.netMode.Value()) == 1 {
786-
if ep == nil || reflect.DeepEqual(*ep, networktypes.EndpointSettings{}) {
786+
if ep == nil || reflect.DeepEqual(*ep, network.EndpointSettings{}) {
787787
continue
788788
}
789789
}
@@ -841,7 +841,7 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
841841
return nil
842842
}
843843

844-
func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.EndpointSettings, error) {
844+
func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.EndpointSettings, error) {
845845
if strings.TrimSpace(ep.Target) == "" {
846846
return nil, errors.New("no name set for network")
847847
}
@@ -854,7 +854,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End
854854
}
855855
}
856856

857-
epConfig := &networktypes.EndpointSettings{
857+
epConfig := &network.EndpointSettings{
858858
GwPriority: ep.GwPriority,
859859
}
860860
epConfig.Aliases = append(epConfig.Aliases, ep.Aliases...)
@@ -866,7 +866,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End
866866
epConfig.Links = ep.Links
867867
}
868868
if ep.IPv4Address != "" || ep.IPv6Address != "" || len(ep.LinkLocalIPs) > 0 {
869-
epConfig.IPAMConfig = &networktypes.EndpointIPAMConfig{
869+
epConfig.IPAMConfig = &network.EndpointIPAMConfig{
870870
IPv4Address: ep.IPv4Address,
871871
IPv6Address: ep.IPv6Address,
872872
LinkLocalIPs: ep.LinkLocalIPs,

cli/command/service/formatter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/docker/cli/cli/command/formatter"
1212
"github.com/docker/cli/cli/command/inspect"
1313
"github.com/docker/docker/api/types/container"
14-
mounttypes "github.com/docker/docker/api/types/mount"
14+
"github.com/docker/docker/api/types/mount"
1515
"github.com/docker/docker/api/types/network"
1616
"github.com/docker/docker/api/types/swarm"
1717
"github.com/docker/go-units"
@@ -461,7 +461,7 @@ func (ctx *serviceInspectContext) ContainerInit() bool {
461461
return *ctx.Service.Spec.TaskTemplate.ContainerSpec.Init
462462
}
463463

464-
func (ctx *serviceInspectContext) ContainerMounts() []mounttypes.Mount {
464+
func (ctx *serviceInspectContext) ContainerMounts() []mount.Mount {
465465
return ctx.Service.Spec.TaskTemplate.ContainerSpec.Mounts
466466
}
467467

cli/command/service/update.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/docker/cli/opts"
1414
"github.com/docker/cli/opts/swarmopts"
1515
"github.com/docker/docker/api/types/container"
16-
mounttypes "github.com/docker/docker/api/types/mount"
16+
"github.com/docker/docker/api/types/mount"
1717
"github.com/docker/docker/api/types/network"
1818
"github.com/docker/docker/api/types/swarm"
1919
"github.com/docker/docker/api/types/versions"
@@ -943,33 +943,33 @@ func removeItems(
943943
return newSeq
944944
}
945945

946-
func updateMounts(flags *pflag.FlagSet, mounts *[]mounttypes.Mount) error {
947-
mountsByTarget := map[string]mounttypes.Mount{}
946+
func updateMounts(flags *pflag.FlagSet, mounts *[]mount.Mount) error {
947+
mountsByTarget := map[string]mount.Mount{}
948948

949949
if flags.Changed(flagMountAdd) {
950950
values := flags.Lookup(flagMountAdd).Value.(*opts.MountOpt).Value()
951-
for _, mount := range values {
952-
if _, ok := mountsByTarget[mount.Target]; ok {
951+
for _, mnt := range values {
952+
if _, ok := mountsByTarget[mnt.Target]; ok {
953953
return errors.Errorf("duplicate mount target")
954954
}
955-
mountsByTarget[mount.Target] = mount
955+
mountsByTarget[mnt.Target] = mnt
956956
}
957957
}
958958

959959
// Add old list of mount points minus updated one.
960-
for _, mount := range *mounts {
961-
if _, ok := mountsByTarget[mount.Target]; !ok {
962-
mountsByTarget[mount.Target] = mount
960+
for _, mnt := range *mounts {
961+
if _, ok := mountsByTarget[mnt.Target]; !ok {
962+
mountsByTarget[mnt.Target] = mnt
963963
}
964964
}
965965

966-
newMounts := []mounttypes.Mount{}
966+
newMounts := make([]mount.Mount, 0, len(mountsByTarget))
967967

968968
toRemove := buildToRemoveSet(flags, flagMountRemove)
969969

970-
for _, mount := range mountsByTarget {
971-
if _, exists := toRemove[mount.Target]; !exists {
972-
newMounts = append(newMounts, mount)
970+
for _, mnt := range mountsByTarget {
971+
if _, exists := toRemove[mnt.Target]; !exists {
972+
newMounts = append(newMounts, mnt)
973973
}
974974
}
975975
sort.Slice(newMounts, func(i, j int) bool {

cli/command/service/update_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/docker/docker/api/types/container"
12-
mounttypes "github.com/docker/docker/api/types/mount"
12+
"github.com/docker/docker/api/types/mount"
1313
"github.com/docker/docker/api/types/network"
1414
"github.com/docker/docker/api/types/swarm"
1515
"gotest.tools/v3/assert"
@@ -237,9 +237,9 @@ func TestUpdateMounts(t *testing.T) {
237237
flags.Set("mount-add", "type=volume,source=vol2,target=/toadd")
238238
flags.Set("mount-rm", "/toremove")
239239

240-
mounts := []mounttypes.Mount{
241-
{Target: "/toremove", Source: "vol1", Type: mounttypes.TypeBind},
242-
{Target: "/tokeep", Source: "vol3", Type: mounttypes.TypeBind},
240+
mounts := []mount.Mount{
241+
{Target: "/toremove", Source: "vol1", Type: mount.TypeBind},
242+
{Target: "/tokeep", Source: "vol3", Type: mount.TypeBind},
243243
}
244244

245245
updateMounts(flags, &mounts)
@@ -252,10 +252,10 @@ func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
252252
flags := newUpdateCommand(nil).Flags()
253253
flags.Set("mount-add", "type=volume,source=vol4,target=/toadd")
254254

255-
mounts := []mounttypes.Mount{
256-
{Target: "/tokeep1", Source: "vol1", Type: mounttypes.TypeBind},
257-
{Target: "/toadd", Source: "vol2", Type: mounttypes.TypeBind},
258-
{Target: "/tokeep2", Source: "vol3", Type: mounttypes.TypeBind},
255+
mounts := []mount.Mount{
256+
{Target: "/tokeep1", Source: "vol1", Type: mount.TypeBind},
257+
{Target: "/toadd", Source: "vol2", Type: mount.TypeBind},
258+
{Target: "/tokeep2", Source: "vol3", Type: mount.TypeBind},
259259
}
260260

261261
updateMounts(flags, &mounts)

0 commit comments

Comments
 (0)