Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for driver-specific options during container creation #24535

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/source/markdown/options/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Valid _mode_ values are:
- **ip6=**_IPv6_: Specify a static IPv6 address for this container.
- **mac=**_MAC_: Specify a static MAC address for this container.
- **interface_name=**_name_: Specify a name for the created network interface inside the container.
- **host_interface_name=**_name_: Specify a name for the created network interface outside the container.

Any other options will be passed through to netavark without validation. This can be useful to pass arguments to netavark plugins.

For example, to set a static ipv4 address and a static mac address, use `--network bridge:ip=10.88.0.10,mac=44:33:22:11:00:99`.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/checkpoint-restore/go-criu/v7 v7.2.0
github.com/containernetworking/plugins v1.5.1
github.com/containers/buildah v1.38.0
github.com/containers/common v0.61.0
github.com/containers/common v0.61.1-0.20241112152446-305e9ce69b0f
github.com/containers/conmon v2.0.20+incompatible
github.com/containers/gvisor-tap-vsock v0.8.0
github.com/containers/image/v5 v5.33.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ github.com/containernetworking/plugins v1.5.1 h1:T5ji+LPYjjgW0QM+KyrigZbLsZ8jaX+
github.com/containernetworking/plugins v1.5.1/go.mod h1:MIQfgMayGuHYs0XdNudf31cLLAC+i242hNm6KuDGqCM=
github.com/containers/buildah v1.38.0 h1:FmciZMwzhdcvtWj+8IE+61+lfTG2JfgrbZ2DUnEMnTE=
github.com/containers/buildah v1.38.0/go.mod h1:tUsHC2bcgR5Q/R76qZUn7x0FRglqPFry2g5KhWfH4LI=
github.com/containers/common v0.61.0 h1:j/84PTqZIKKYy42OEJsZmjZ4g4Kq2ERuC3tqp2yWdh4=
github.com/containers/common v0.61.0/go.mod h1:NGRISq2vTFPSbhNqj6MLwyes4tWSlCnqbJg7R77B8xc=
github.com/containers/common v0.61.1-0.20241112152446-305e9ce69b0f h1:K3jmJrkDJJhLnRdVFI7Gb5mv4/jb2ue9StZ2F1y2rsE=
github.com/containers/common v0.61.1-0.20241112152446-305e9ce69b0f/go.mod h1:NGRISq2vTFPSbhNqj6MLwyes4tWSlCnqbJg7R77B8xc=
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
github.com/containers/gvisor-tap-vsock v0.8.0 h1:Z8ZEWb+Lio0d+lXexONdUWT4rm9lF91vH0g3ARnMy7o=
Expand Down
5 changes: 4 additions & 1 deletion pkg/specgen/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,10 @@ func parseBridgeNetworkOptions(opts string) (types.PerNetworkOptions, error) {
netOpts.InterfaceName = value

default:
return netOpts, fmt.Errorf("unknown bridge network option: %s", name)
if netOpts.Options == nil {
netOpts.Options = make(map[string]string)
}
netOpts.Options[name] = value
}
}
return netOpts, nil
Expand Down
39 changes: 37 additions & 2 deletions pkg/specgen/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,32 @@ func TestParseNetworkFlag(t *testing.T) {
},
},
{
name: "bridge mode with invalid option",
name: "bridge mode with unknown option",
args: []string{"bridge:abc=123"},
nsmode: Namespace{NSMode: Bridge},
err: "unknown bridge network option: abc",
networks: map[string]types.PerNetworkOptions{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename the test to not say invalid but rather unknown.

Also maybe add another case where add 2+ options to make sure it is working for multiple keys. I know it does as the code is simple enough but better to validate that

defaultNetName: {
InterfaceName: "",
Options: map[string]string{
"abc": "123",
},
},
},
},
{
name: "bridge mode with multiple unknown options",
args: []string{"bridge:abc=123,xyz=789,other=a-much-longer-value"},
nsmode: Namespace{NSMode: Bridge},
networks: map[string]types.PerNetworkOptions{
defaultNetName: {
InterfaceName: "",
Options: map[string]string{
"abc": "123",
"xyz": "789",
"other": "a-much-longer-value",
},
},
},
},
{
name: "bridge mode with invalid ip",
Expand All @@ -175,6 +197,19 @@ func TestParseNetworkFlag(t *testing.T) {
nsmode: Namespace{NSMode: Bridge},
err: "address 123: invalid MAC address",
},
{
name: "bridge mode with host interface name",
args: []string{"bridge:host_interface_name=my-veth"},
nsmode: Namespace{NSMode: Bridge},
networks: map[string]types.PerNetworkOptions{
defaultNetName: {
InterfaceName: "",
Options: map[string]string{
"host_interface_name": "my-veth",
},
},
},
},
{
name: "network name",
args: []string{"someName"},
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package integration
import (
"encoding/json"
"fmt"
"net"
"path/filepath"
"time"

Expand Down Expand Up @@ -297,6 +298,27 @@ var _ = Describe("Podman network", func() {
Expect(rmAll).Should(ExitCleanly())
})

It("podman run container host interface name", func() {
Skip("FIXME: We need netavark >= v1.14 for host interface support")

ctrName := "testCtr"
vethName := "my_veth" + stringid.GenerateRandomID()[:8]
container := podmanTest.Podman([]string{"run", "-dt", "--network", "bridge:host_interface_name=" + vethName, "--name", ctrName, ALPINE, "top"})
container.WaitWithDefaultTimeout()
Expect(container).Should(ExitCleanly())

if !isRootless() {
veth, err := net.InterfaceByName(vethName)
Expect(err).ToNot(HaveOccurred())
Expect(veth.Name).To(Equal(vethName))
} else {
session := podmanTest.Podman([]string{"unshare", "--rootless-netns", "ip", "link", "show", vethName})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToString()).To(ContainSubstring(vethName))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/test/e2e/network_test.go b/test/e2e/network_test.go
index 018b7eb97..3d3f1d393 100644
--- a/test/e2e/network_test.go
+++ b/test/e2e/network_test.go
@@ -312,6 +312,11 @@ var _ = Describe("Podman network", func() {
                        veth, err := net.InterfaceByName(vethName)
                        Expect(err).ToNot(HaveOccurred())
                        Expect(veth.Name).To(Equal(vethName))
+               } else {
+                       session := podmanTest.Podman([]string{"unshare", "--rootless-netns", "ip", "link", "show", vethName})
+                       session.WaitWithDefaultTimeout()
+                       Expect(session).Should(ExitCleanly())
+                       Expect(session.OutputToString()).To(ContainSubstring(vethName))
                }
        })
we can test rootless as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, thanks.

})

It("podman inspect container two CNI networks (container not running)", func() {
netName1 := "net1-" + stringid.GenerateRandomID()
network1 := podmanTest.Podman([]string{"network", "create", netName1})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/containers/common/version/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ github.com/containers/buildah/pkg/sshagent
github.com/containers/buildah/pkg/util
github.com/containers/buildah/pkg/volumes
github.com/containers/buildah/util
# github.com/containers/common v0.61.0
# github.com/containers/common v0.61.1-0.20241112152446-305e9ce69b0f
## explicit; go 1.22.6
github.com/containers/common/internal
github.com/containers/common/internal/attributedstring
Expand Down