mirror of
https://github.com/docker/cli.git
synced 2026-01-26 15:41:42 +03:00
Merge pull request #6685 from thaJeztah/less_nat
remove some uses of go-connections/nat package
This commit is contained in:
@@ -426,6 +426,9 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// short syntax ([ip:]public:private[/proto])
|
||||
//
|
||||
// TODO(thaJeztah): we need an equivalent that handles the "ip-address" part without depending on the nat package.
|
||||
ports, natPortBindings, err := nat.ParsePortSpecs(convertedOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -918,8 +918,9 @@ var transformStringToDuration TransformerFunc = func(value any) (any, error) {
|
||||
}
|
||||
|
||||
func toServicePortConfigs(value string) ([]any, error) {
|
||||
var portConfigs []any
|
||||
|
||||
// short syntax ([ip:]public:private[/proto])
|
||||
//
|
||||
// TODO(thaJeztah): we need an equivalent that handles the "ip-address" part without depending on the nat package.
|
||||
ports, portBindings, err := nat.ParsePortSpecs([]string{value})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -931,6 +932,7 @@ func toServicePortConfigs(value string) ([]any, error) {
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
var portConfigs []any
|
||||
for _, key := range keys {
|
||||
// Reuse ConvertPortToPortConfig so that it is consistent
|
||||
port, err := network.ParsePort(key)
|
||||
|
||||
@@ -100,7 +100,9 @@ func (p *PortOpt) Set(value string) error {
|
||||
|
||||
p.ports = append(p.ports, pConfig)
|
||||
} else {
|
||||
// short syntax
|
||||
// short syntax ([ip:]public:private[/proto])
|
||||
//
|
||||
// TODO(thaJeztah): we need an equivalent that handles the "ip-address" part without depending on the nat package.
|
||||
ports, portBindingMap, err := nat.ParsePortSpecs([]string{value})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -162,18 +164,17 @@ func ConvertPortToPortConfig(
|
||||
logrus.Warnf("ignoring IP-address (%s:%s) service will listen on '0.0.0.0'", net.JoinHostPort(binding.HostIP, binding.HostPort), portProto.String())
|
||||
}
|
||||
|
||||
startHostPort, endHostPort, err := nat.ParsePortRange(binding.HostPort)
|
||||
|
||||
pr, err := network.ParsePortRange(binding.HostPort)
|
||||
if err != nil && binding.HostPort != "" {
|
||||
return nil, fmt.Errorf("invalid hostport binding (%s) for port (%d)", binding.HostPort, portProto.Num())
|
||||
}
|
||||
|
||||
for i := startHostPort; i <= endHostPort; i++ {
|
||||
for p := range pr.All() {
|
||||
ports = append(ports, swarm.PortConfig{
|
||||
// TODO Name: ?
|
||||
Protocol: portProto.Proto(),
|
||||
TargetPort: uint32(portProto.Num()),
|
||||
PublishedPort: uint32(i),
|
||||
PublishedPort: uint32(p.Num()),
|
||||
PublishMode: swarm.PortConfigPublishModeIngress,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user