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

Support changing host veth name #1125

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

M1cha
Copy link
Contributor

@M1cha M1cha commented Nov 11, 2024

@M1cha
Copy link
Contributor Author

M1cha commented Nov 11, 2024

I don't know why, but I can't get the issue linked properly.

Comment on lines 117 to 118
#[serde(rename = "options", default)]
pub options: HashMap<String, String>,
Copy link
Member

Choose a reason for hiding this comment

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

instead of using default I think it is cleaner to wrap this in an Option<>. While that makes accessing values a step more I think it carries the intend better that there can be empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, fixed.

Comment on lines 100 to 106
host_interface_name: self
.info
.per_network_opts
.options
.get("host_interface_name")
.cloned()
.unwrap_or_else(|| "".to_string()),
Copy link
Member

Choose a reason for hiding this comment

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

please use parse_option() as split out host_interface_name as constant like the other options

I know parsing a String cannot fail so the error handling is not needed technically but I think it better to use it consistently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Do we need to make clear which options come from the network and which from the per-network-config? With the current code, the messages and variables look the same for both kinds of options.

@Luap99
Copy link
Member

Luap99 commented Nov 12, 2024

And also this needs tests, please have a look at test/100-bridge-iptables.bats
This should have a test cases where it fails if the veth name exists on the host and one where it works fine and you check the correct interface was created.

@Luap99
Copy link
Member

Luap99 commented Nov 12, 2024

    host.create_link(host_veth).map_err(|err| match err {
        NetavarkError::Netlink(ref e) if -e.raw_code() == libc::EEXIST => NetavarkError::wrap(
            format!(
                "create veth pair: interface {} already exists on container namespace",
                data.container_interface_name
            ),
            err,
        ),
        _ => NetavarkError::wrap("create veth pair", err),
    })?;

This will likely return a wrong/misleading error now. Given both interface are created in one call it would be impossible to know which name conflicted. Maybe we can check if veth_name not empty then chnage the message to hint at both possibilities

@M1cha
Copy link
Contributor Author

M1cha commented Nov 12, 2024

Does this change cause the integration test failures? because they seem unrelated at first glance.

@Luap99
Copy link
Member

Luap99 commented Nov 12, 2024

not ok 108 nftables - check error message from netns thread
# (from function `assert' in file test/helpers.bash, line 348,
#  from function `assert_json' in file test/helpers.bash, line 382,
#  in test file test/250-bridge-nftables.bats, line 359)
#   `assert_json ".error" "create veth pair: interface eth0 already exists on container namespace: Netlink error: File exists (os error 17)" "interface exists on netns"' failed
#  nsenter -n -m -w -t 23168 ip link set lo up
#  nsenter -n -m -w -t 23170 ip link add eth0 type dummy
#  nsenter -n -m -w -t 23168 ./bin/netavark --rootless false --config /tmp/netavark_bats.zFocvy/config --file /var/tmp/netavark/test/testfiles/simplebridge.json setup /proc/23170/ns/net
# {"error":"create veth pair: interface eth0 already exists on container namespace or  exists on host namespace: Netlink error: File exists (os error 17)"}
# [ rc=1 (expected) ]
#  jq -r .error
# create veth pair: interface eth0 already exists on container namespace or  exists on host namespace: Netlink error: File exists (os error 17)
# #/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# #|     FAIL: interface exists on netns
# #| expected: 'create veth pair: interface eth0 already exists on container namespace: Netlink error: File exists (os error 17)'
# #|   actual: 'create veth pair: interface eth0 already exists on container namespace or  exists on host namespace: Netlink error: File exists (os error 17)'
# #\^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Yes it is your new error message, it seems your condition in the code is inverted.

Comment on lines 666 to 676
if data.host_interface_name.is_empty() {
format!(
"create veth pair: interface {} already exists on container namespace or {} exists on host namespace",
data.container_interface_name, data.host_interface_name,
)
} else {
format!(
"create veth pair: interface {} already exists on container namespace",
data.container_interface_name
)
},
Copy link
Member

Choose a reason for hiding this comment

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

need to use !is_empty() or better swap both branches around

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree, fixed

}

@test bridge - existing veth name {
expected_rc=1 run_netavark --file ${TESTSDIR}/testfiles/bridge-vethname-exists.json setup $(get_container_netns_path)
Copy link
Member

Choose a reason for hiding this comment

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

please assert your exact expected error message here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I gotta say, it's pretty cool that the tests can do this. done.

Fixes containers/netavark#24523

Signed-off-by: Michael Zimmermann <[email protected]>
@mheon
Copy link
Member

mheon commented Nov 12, 2024

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

Copy link
Contributor

openshift-ci bot commented Nov 12, 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-merge-bot openshift-merge-bot bot merged commit d6aa37a into containers:main Nov 12, 2024
28 checks passed
@M1cha M1cha deleted the host-veth-name branch November 12, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants