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

Conversation

M1cha
Copy link
Contributor

@M1cha M1cha commented Nov 11, 2024

This way has a huge disadvantage: The user will not see an error when he uses a non-existent option. Another disadvantage is, that if we add more options within podman, they might collide with the names chosen by plugins. Such issues might be hard to debug.
The advantage is that the usage is very nice:
--network bridge:opt1=val1,opt2=val2.

Alternatively, we could put this behind opt=, which is harder to use, but would solve all issues above:
--network bridge:opt=opt1=val1,opt=opt2=val2

Does this PR introduce a user-facing change?

A new `host_interface_name` option was added for bridge networks to specify the host side veth name, requires netavark >= 1.14.

Depends on: containers/common#2245
Required by: containers/netavark#1125

Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@Luap99
Copy link
Member

Luap99 commented Nov 12, 2024

FYI if you call go get github.com/containers/common@main && make vendor you can update c/common to the latest version so your code compiles and we can merge it. (Please do the vendor changes in a separate commit)

This will also need documentation on --network option to at least document to one new option you added.

I think putting this behind opt= may not be a bad idea to at least allow us to keep throwing errors for typos for the common options such as ip, mac, interface_name,... but I certainly could be convinced that we do not need that.

@mheon WDYT?

@mheon
Copy link
Member

mheon commented Nov 12, 2024

I want to say we should validate at create time (if necessary by calling netavark to do a dry run of setting up the container) but that is complex and will slow down container creation significantly... Which isn't worth it.

Current approach LGTM given that. I don't like it but the alternatives are worse.

@M1cha M1cha force-pushed the network-driver-options branch from 6ab15aa to da9a0c3 Compare November 12, 2024 18:15
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 12, 2024
Signed-off-by: Michael Zimmermann <[email protected]>
@M1cha M1cha force-pushed the network-driver-options branch from da9a0c3 to 9c79590 Compare November 12, 2024 18:59
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 12, 2024
@M1cha
Copy link
Contributor Author

M1cha commented Nov 12, 2024

Would a simple e2e test be the right choice for this change? Do those actually run netavark in the background? Otherwise such a test probably wouldn't be that useful.

@Luap99
Copy link
Member

Luap99 commented Nov 13, 2024

yes in test/e2e there a bunch of tests all using netavark. The problem here is though that we use the distro version so we first need to release a netavark then update it here in our CI images and only then we could test the new option.

Having a test is important to ensure the option is fully working and correct send to netavark so we know it works end to end. You can add a Skip("") to the test so it is not run in CI yet but having a test that I can enable later when we update the CI images is always a good idea.

@M1cha
Copy link
Contributor Author

M1cha commented Nov 13, 2024

The test TestParseNetworkFlag/bridge_mode_with_invalid_option fails with this change. Shall I remove it given your decision above?

@Luap99
Copy link
Member

Luap99 commented Nov 13, 2024

Yes if we go with the current version that would need to be dropped. I guess you can update the test to ensure unknown keys end up in the options map.
I am still unsure if using the opt= syntax might be better to catch the top level typos at least for ip, mac, etc... But I agree the usability goes a bit down so maybe not worth it.

@M1cha M1cha force-pushed the network-driver-options branch 2 times, most recently from 93b8978 to 828301f Compare November 13, 2024 15:31
@M1cha
Copy link
Contributor Author

M1cha commented Nov 13, 2024

I've added tests now. If you prefer the opt= variant, just tell me - it's actually very easy to do. I did not verify, that the code inside the !isRootless() guard works, since I currently don't have a setup where I can run these tests as root. Even running them rootless was a challenge already on my ostree system. If you want me test it, I'll set-up a VM and do so.

Can you help me with the test/e2e/search_test.go:380 failure? I can't reproduce that locally.

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

It("podman run container host interface name", func() {
Skip("We need to update netavark first.")
Copy link
Member

Choose a reason for hiding this comment

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

please say FIXME: We need netavark >= v1.14 for host interface support.

This is important for anyone looking at this to know when this can be dropped.

Skip("We need to update netavark first.")

ctrName := "testCtr"
vethName := "my_veth"
Copy link
Member

Choose a reason for hiding this comment

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

please do not use static names, that might cause conflicts on the host.
Append a random suffix, i.e. "my_veth" + stringid.GenerateRandomID()[:8]

veth, err := net.InterfaceByName(vethName)
Expect(err).ToNot(HaveOccurred())
Expect(veth.Name).To(Equal(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.

@@ -161,7 +161,14 @@ func TestParseNetworkFlag(t *testing.T) {
name: "bridge mode with invalid 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

@Luap99
Copy link
Member

Luap99 commented Nov 13, 2024

I run the test on my system and it worked there (having a netavark from main installed) + added a diff to make do something useful as rootless as well

Expect(container).Should(ExitCleanly())

if !isRootless() {
// make sure cni/netavark created bridge with expected name
Copy link
Member

Choose a reason for hiding this comment

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

oh and please drop cni here, we no longer support cni upstream and cni doesn't support this option

@Luap99
Copy link
Member

Luap99 commented Nov 13, 2024

You can ignore the search failures. They are just random registry flakes. We rerun tests as needed.

This way has a huge disadvantage: The user will not see an error when he
uses a non-existent option. Another disadvantage is, that if we add more
options within podman, they might collide with the names chosen by
plugins. Such issues might be hard to debug.
The advantage is that the usage is very nice:
--network bridge:opt1=val1,opt2=val2.

Alternatively, we could put this behind `opt=`, which is harder to use,
but would solve all issues above:
--network bridge:opt=opt1=val1,opt=opt2=val2

Signed-off-by: Michael Zimmermann <[email protected]>
@M1cha M1cha force-pushed the network-driver-options branch from 828301f to 315e741 Compare November 13, 2024 17:15
@M1cha
Copy link
Contributor Author

M1cha commented Nov 13, 2024

Thanks for the review. I addressed all your comments in the most recent push.

@mheon
Copy link
Member

mheon commented Nov 13, 2024

Code LGTM

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 14, 2024
Copy link
Contributor

openshift-ci bot commented Nov 14, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99, M1cha

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 14, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit fa5e3b6 into containers:main Nov 14, 2024
86 checks passed
@M1cha M1cha deleted the network-driver-options branch November 14, 2024 09:31
@M1cha M1cha mentioned this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants