Merge pull request #12611 from Luap99/ipv6
add --ip6 flag to podman create/run
This commit is contained in:
commit
aaf90c5596
|
|
@ -53,6 +53,13 @@ func DefineNetFlags(cmd *cobra.Command) {
|
||||||
)
|
)
|
||||||
_ = cmd.RegisterFlagCompletionFunc(ipFlagName, completion.AutocompleteNone)
|
_ = cmd.RegisterFlagCompletionFunc(ipFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
|
ip6FlagName := "ip6"
|
||||||
|
netFlags.String(
|
||||||
|
ip6FlagName, "",
|
||||||
|
"Specify a static IPv6 address for the container",
|
||||||
|
)
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc(ip6FlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
macAddressFlagName := "mac-address"
|
macAddressFlagName := "mac-address"
|
||||||
netFlags.String(
|
netFlags.String(
|
||||||
macAddressFlagName, "",
|
macAddressFlagName, "",
|
||||||
|
|
@ -185,7 +192,7 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
|
||||||
opts.Networks = networks
|
opts.Networks = networks
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.Changed("ip") || flags.Changed("mac-address") || flags.Changed("network-alias") {
|
if flags.Changed("ip") || flags.Changed("ip6") || flags.Changed("mac-address") || flags.Changed("network-alias") {
|
||||||
// if there is no network we add the default
|
// if there is no network we add the default
|
||||||
if len(opts.Networks) == 0 {
|
if len(opts.Networks) == 0 {
|
||||||
opts.Networks = map[string]types.PerNetworkOptions{
|
opts.Networks = map[string]types.PerNetworkOptions{
|
||||||
|
|
@ -193,29 +200,31 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, err := flags.GetString("ip")
|
for _, ipFlagName := range []string{"ip", "ip6"} {
|
||||||
if err != nil {
|
ip, err := flags.GetString(ipFlagName)
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
if ip != "" {
|
|
||||||
// if pod create --infra=false
|
|
||||||
if infra, err := flags.GetBool("infra"); err == nil && !infra {
|
|
||||||
return nil, errors.Wrap(define.ErrInvalidArg, "cannot set --ip without infra container")
|
|
||||||
}
|
}
|
||||||
|
if ip != "" {
|
||||||
|
// if pod create --infra=false
|
||||||
|
if infra, err := flags.GetBool("infra"); err == nil && !infra {
|
||||||
|
return nil, errors.Wrapf(define.ErrInvalidArg, "cannot set --%s without infra container", ipFlagName)
|
||||||
|
}
|
||||||
|
|
||||||
staticIP := net.ParseIP(ip)
|
staticIP := net.ParseIP(ip)
|
||||||
if staticIP == nil {
|
if staticIP == nil {
|
||||||
return nil, errors.Errorf("%s is not an ip address", ip)
|
return nil, errors.Errorf("%q is not an ip address", ip)
|
||||||
}
|
}
|
||||||
if !opts.Network.IsBridge() && !opts.Network.IsDefault() {
|
if !opts.Network.IsBridge() && !opts.Network.IsDefault() {
|
||||||
return nil, errors.Wrap(define.ErrInvalidArg, "--ip can only be set when the network mode is bridge")
|
return nil, errors.Wrapf(define.ErrInvalidArg, "--%s can only be set when the network mode is bridge", ipFlagName)
|
||||||
}
|
}
|
||||||
if len(opts.Networks) != 1 {
|
if len(opts.Networks) != 1 {
|
||||||
return nil, errors.Wrap(define.ErrInvalidArg, "--ip can only be set for a single network")
|
return nil, errors.Wrapf(define.ErrInvalidArg, "--%s can only be set for a single network", ipFlagName)
|
||||||
}
|
}
|
||||||
for name, netOpts := range opts.Networks {
|
for name, netOpts := range opts.Networks {
|
||||||
netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
|
netOpts.StaticIPs = append(netOpts.StaticIPs, staticIP)
|
||||||
opts.Networks[name] = netOpts
|
opts.Networks[name] = netOpts
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -474,19 +474,24 @@ Path to the container-init binary.
|
||||||
|
|
||||||
Keep STDIN open even if not attached. The default is *false*.
|
Keep STDIN open even if not attached. The default is *false*.
|
||||||
|
|
||||||
#### **--ip6**=*ip*
|
#### **--ip**=*ipv4*
|
||||||
|
|
||||||
Not implemented
|
Specify a static IPv4 address for the container, for example **10.88.64.128**.
|
||||||
|
|
||||||
#### **--ip**=*ip*
|
|
||||||
|
|
||||||
Specify a static IP address for the container, for example **10.88.64.128**.
|
|
||||||
This option can only be used if the container is joined to only a single network - i.e., **--network=network-name** is used at most once -
|
This option can only be used if the container is joined to only a single network - i.e., **--network=network-name** is used at most once -
|
||||||
and if the container is not joining another container's network namespace via **--network=container:_id_**.
|
and if the container is not joining another container's network namespace via **--network=container:_id_**.
|
||||||
The address must be within the network's IP address pool (default **10.88.0.0/16**).
|
The address must be within the network's IP address pool (default **10.88.0.0/16**).
|
||||||
|
|
||||||
To specify multiple static IP addresses per container, set multiple networks using the **--network** option with a static IP address specified for each using the `ip` mode for that option.
|
To specify multiple static IP addresses per container, set multiple networks using the **--network** option with a static IP address specified for each using the `ip` mode for that option.
|
||||||
|
|
||||||
|
#### **--ip6**=*ipv6*
|
||||||
|
|
||||||
|
Specify a static IPv6 address for the container, for example **fd46:db93:aa76:ac37::10**.
|
||||||
|
This option can only be used if the container is joined to only a single network - i.e., **--network=network-name** is used at most once -
|
||||||
|
and if the container is not joining another container's network namespace via **--network=container:_id_**.
|
||||||
|
The address must be within the network's IPv6 address pool.
|
||||||
|
|
||||||
|
To specify multiple static IPv6 addresses per container, set multiple networks using the **--network** option with a static IPv6 address specified for each using the `ip6` mode for that option.
|
||||||
|
|
||||||
|
|
||||||
#### **--ipc**=*ipc*
|
#### **--ipc**=*ipc*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,15 @@ The address must be within the network's IP address pool (default **10.88.0.0/16
|
||||||
|
|
||||||
To specify multiple static IP addresses per pod, set multiple networks using the **--network** option with a static IP address specified for each using the `ip` mode for that option.
|
To specify multiple static IP addresses per pod, set multiple networks using the **--network** option with a static IP address specified for each using the `ip` mode for that option.
|
||||||
|
|
||||||
|
#### **--ip6**=*ipv6*
|
||||||
|
|
||||||
|
Specify a static IPv6 address for the pod, for example **fd46:db93:aa76:ac37::10**.
|
||||||
|
This option can only be used if the pod is joined to only a single network - i.e., **--network=network-name** is used at most once -
|
||||||
|
and if the pod is not joining another container's network namespace via **--network=container:_id_**.
|
||||||
|
The address must be within the network's IPv6 address pool.
|
||||||
|
|
||||||
|
To specify multiple static IPv6 addresses per pod, set multiple networks using the **--network** option with a static IPv6 address specified for each using the `ip6` mode for that option.
|
||||||
|
|
||||||
#### **--label**=*label*, **-l**
|
#### **--label**=*label*, **-l**
|
||||||
|
|
||||||
Add metadata to a pod (e.g., --label com.example.key=value).
|
Add metadata to a pod (e.g., --label com.example.key=value).
|
||||||
|
|
|
||||||
|
|
@ -497,19 +497,24 @@ Path to the container-init binary.
|
||||||
|
|
||||||
When set to **true**, keep stdin open even if not attached. The default is **false**.
|
When set to **true**, keep stdin open even if not attached. The default is **false**.
|
||||||
|
|
||||||
#### **--ip6**=*ip*
|
#### **--ip**=*ipv4*
|
||||||
|
|
||||||
Not implemented.
|
Specify a static IPv4 address for the container, for example **10.88.64.128**.
|
||||||
|
|
||||||
#### **--ip**=*ip*
|
|
||||||
|
|
||||||
Specify a static IP address for the container, for example **10.88.64.128**.
|
|
||||||
This option can only be used if the container is joined to only a single network - i.e., **--network=network-name** is used at most once -
|
This option can only be used if the container is joined to only a single network - i.e., **--network=network-name** is used at most once -
|
||||||
and if the container is not joining another container's network namespace via **--network=container:_id_**.
|
and if the container is not joining another container's network namespace via **--network=container:_id_**.
|
||||||
The address must be within the network's IP address pool (default **10.88.0.0/16**).
|
The address must be within the network's IP address pool (default **10.88.0.0/16**).
|
||||||
|
|
||||||
To specify multiple static IP addresses per container, set multiple networks using the **--network** option with a static IP address specified for each using the `ip` mode for that option.
|
To specify multiple static IP addresses per container, set multiple networks using the **--network** option with a static IP address specified for each using the `ip` mode for that option.
|
||||||
|
|
||||||
|
#### **--ip6**=*ipv6*
|
||||||
|
|
||||||
|
Specify a static IPv6 address for the container, for example **fd46:db93:aa76:ac37::10**.
|
||||||
|
This option can only be used if the container is joined to only a single network - i.e., **--network=network-name** is used at most once -
|
||||||
|
and if the container is not joining another container's network namespace via **--network=container:_id_**.
|
||||||
|
The address must be within the network's IPv6 address pool.
|
||||||
|
|
||||||
|
To specify multiple static IPv6 addresses per container, set multiple networks using the **--network** option with a static IPv6 address specified for each using the `ip6` mode for that option.
|
||||||
|
|
||||||
#### **--ipc**=*mode*
|
#### **--ipc**=*mode*
|
||||||
|
|
||||||
Set the IPC namespace mode for a container. The default is to create
|
Set the IPC namespace mode for a container. The default is to create
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/containers/podman/v3/test/utils"
|
. "github.com/containers/podman/v3/test/utils"
|
||||||
|
"github.com/containers/storage/pkg/stringid"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
. "github.com/onsi/gomega/gexec"
|
. "github.com/onsi/gomega/gexec"
|
||||||
|
|
@ -65,6 +66,20 @@ var _ = Describe("Podman run with --ip flag", func() {
|
||||||
Expect(result.OutputToString()).To(ContainSubstring(ip + "/16"))
|
Expect(result.OutputToString()).To(ContainSubstring(ip + "/16"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("Podman run with specified static IPv6 has correct IP", func() {
|
||||||
|
netName := "ipv6-" + stringid.GenerateNonCryptoID()
|
||||||
|
ipv6 := "fd46:db93:aa76:ac37::10"
|
||||||
|
net := podmanTest.Podman([]string{"network", "create", "--subnet", "fd46:db93:aa76:ac37::/64", netName})
|
||||||
|
net.WaitWithDefaultTimeout()
|
||||||
|
defer podmanTest.removeCNINetwork(netName)
|
||||||
|
Expect(net).To(Exit(0))
|
||||||
|
|
||||||
|
result := podmanTest.Podman([]string{"run", "-ti", "--network", netName, "--ip6", ipv6, ALPINE, "ip", "addr"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
Expect(result).Should(Exit(0))
|
||||||
|
Expect(result.OutputToString()).To(ContainSubstring(ipv6 + "/64"))
|
||||||
|
})
|
||||||
|
|
||||||
It("Podman run with --network bridge:ip=", func() {
|
It("Podman run with --network bridge:ip=", func() {
|
||||||
ip := GetRandomIPAddress()
|
ip := GetRandomIPAddress()
|
||||||
result := podmanTest.Podman([]string{"run", "-ti", "--network", "bridge:ip=" + ip, ALPINE, "ip", "addr"})
|
result := podmanTest.Podman([]string{"run", "-ti", "--network", "bridge:ip=" + ip, ALPINE, "ip", "addr"})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue