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

CNI: add host-side interface info to cni.Result #26518

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions plugins/cilium-cni/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ func cmdAdd(args *skel.CmdArgs) (err error) {
ep.DatapathConfiguration.ExternalIpam = true
}

res := &cniTypesV1.Result{}

switch conf.DatapathMode {
case datapathOption.DatapathModeVeth:
var (
Expand All @@ -500,6 +502,11 @@ func cmdAdd(args *skel.CmdArgs) (err error) {
}
}()

res.Interfaces = append(res.Interfaces, &cniTypesV1.Interface{
Name: veth.Attrs().Name,
Mac: veth.Attrs().HardwareAddr.String(),
})

if err = netlink.LinkSetNsFd(peer, int(netNs.Fd())); err != nil {
return fmt.Errorf("unable to move veth pair '%v' to netns: %s", peer, err)
}
Expand All @@ -515,8 +522,6 @@ func cmdAdd(args *skel.CmdArgs) (err error) {
HostAddr: ipam.HostAddressing,
}

res := &cniTypesV1.Result{}

if !ipv6IsEnabled(ipam) && !ipv4IsEnabled(ipam) {
return fmt.Errorf("IPAM did not provide IPv4 or IPv6 address")
}
Expand All @@ -534,6 +539,8 @@ func cmdAdd(args *skel.CmdArgs) (err error) {
if err != nil {
return fmt.Errorf("unable to prepare IP addressing for '%s': %s", ep.Addressing.IPV6, err)
}
// set the addresses interface index to that of the container-side veth
ipConfig.Interface = cniTypesV1.Int(len(res.Interfaces))
tklauser marked this conversation as resolved.
Show resolved Hide resolved
res.IPs = append(res.IPs, ipConfig)
res.Routes = append(res.Routes, routes...)
}
Expand All @@ -547,6 +554,8 @@ func cmdAdd(args *skel.CmdArgs) (err error) {
if err != nil {
return fmt.Errorf("unable to prepare IP addressing for '%s': %s", ep.Addressing.IPV4, err)
}
// set the addresses interface index to that of the container-side veth
ipConfig.Interface = cniTypesV1.Int(len(res.Interfaces))
res.IPs = append(res.IPs, ipConfig)
res.Routes = append(res.Routes, routes...)
}
Expand Down Expand Up @@ -578,11 +587,6 @@ func cmdAdd(args *skel.CmdArgs) (err error) {
Sandbox: args.Netns,
})

// Add to the result the Interface as index of Interfaces
for i := range res.Interfaces {
res.IPs[i].Interface = cniTypesV1.Int(i)
}

// Specify that endpoint must be regenerated synchronously. See GH-4409.
ep.SyncBuildEndpoint = true
if err = c.EndpointCreate(ep); err != nil {
Expand Down