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 cni plugin #4

Merged
merged 4 commits into from
Feb 25, 2020
Merged

Add cni plugin #4

merged 4 commits into from
Feb 25, 2020

Conversation

maiqueb
Copy link
Collaborator

@maiqueb maiqueb commented Feb 13, 2020

What this PR does / why we need it:
This PR adds a CNI plugin that moves the macvtap interface created by the macvtap device plugin into the new pod's netns.

The macvtap CNI is built in the same image as the macvtap device plugin, and mounted in the corresponding host using the 'initContainers' functionality.

Special notes for your reviewer:

@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 13, 2020
@kubevirt-bot kubevirt-bot added size/XXL approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 13, 2020
cmd/Dockerfile Outdated Show resolved Hide resolved
templates/macvtap.yaml.in Outdated Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Show resolved Hide resolved
pkg/cni/plugin.go Show resolved Hide resolved
pkg/cni/plugin.go Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Show resolved Hide resolved
templates/macvtap.yaml.in Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin_test.go Outdated Show resolved Hide resolved
pkg/cni/plugin_test.go Outdated Show resolved Hide resolved
pkg/cni/plugin_test.go Outdated Show resolved Hide resolved
pkg/cni/plugin_test.go Outdated Show resolved Hide resolved
pkg/cni/plugin_test.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
pkg/cni/plugin.go Outdated Show resolved Hide resolved
return macvtap, err
}

func renameMacvtapIface(macvtapLink netlink.Link, macvtapIface *current.Interface, ifaceName string, netns ns.NetNS) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would argue it could also be left out of configureMacvtap. Just fetch the mac of the interface if none has been provided directly in CmdAdd.

pkg/cni/plugin.go Show resolved Hide resolved
@maiqueb maiqueb requested review from phoracek and jcaamano February 20, 2020 12:38
@maiqueb
Copy link
Collaborator Author

maiqueb commented Feb 20, 2020

/release-note-none

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 20, 2020
pkg/cni/plugin.go Outdated Show resolved Hide resolved
@maiqueb maiqueb requested a review from jcaamano February 21, 2020 11:21
@@ -115,7 +115,6 @@ var _ = Describe("Macvtap CNI", func() {
Expect(err).NotTo(HaveOccurred())

Expect(link.Attrs().HardwareAddr.String()).NotTo(BeNil())
Expect(link.Attrs().OperState.String()).To(Equal("up"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I got no clue as to why, but this works locally.

Copy link
Member

@phoracek phoracek left a comment

Choose a reason for hiding this comment

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

Just a nit, other than that it looks great. Thanks.

templates/macvtap.yaml.in Outdated Show resolved Hide resolved
pkg/cni/plugin.go Show resolved Hide resolved
@maiqueb maiqueb requested a review from phoracek February 24, 2020 16:33
@maiqueb
Copy link
Collaborator Author

maiqueb commented Feb 24, 2020

/hold

Allow me to re-write the PR's history (squash some stuff), to make it cleaner.

@kubevirt-bot kubevirt-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 24, 2020
@phoracek
Copy link
Member

/lgtm
/approve

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 24, 2020
@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maiqueb, phoracek

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

The ConfigureMacvtap interface code is located in the
`netlink` util pkg.

The following helper functions are also made available on
the `netlink` pkg.
  - configureArp
  - renameMacvtapIface

All the configuration is performed within a single netns.Do
instruction.

Interface renaming is performed in the target netns, thus
reducing the risk of interface name collision.

Signed-off-by: Miguel Duarte Barroso <[email protected]>
The init-container installs the macvtap-cni plugin into the
host, and afterwards, the macvtap container listens to device
plugin requests, and operates on them.

This way, we can achieve macvtap cni & dp co-existence within the
same container.

Signed-off-by: Miguel Duarte Barroso <[email protected]>
The -logtostderr flag is somehow preventing the cni unit tests
from running.

Can't figure this one out; this is just to show I'm not insane.

Signed-off-by: Miguel Duarte Barroso <[email protected]>
@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Feb 24, 2020
@maiqueb
Copy link
Collaborator Author

maiqueb commented Feb 24, 2020

/hold cancel

@kubevirt-bot kubevirt-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 24, 2020
@phoracek
Copy link
Member

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 25, 2020
@kubevirt-bot kubevirt-bot merged commit fde0a6f into master Feb 25, 2020
@maiqueb maiqueb deleted the add_cni_plugin branch February 25, 2020 09:41
Copy link
Contributor

@jcaamano jcaamano left a comment

Choose a reason for hiding this comment

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

/lgtm
I only have cosmetic comments with no strong opinion. Feel free to go by them or not.

Comment on lines +129 to +132
if err := ip.DelLinkByName(args.IfName); err != nil {
if err != ip.ErrLinkNotFound {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I wondered if there was any difference between ip.DelLinkByName and what we have in util/netlink.go @ LinkDelete. The only difference is that the latter would not return ErrLinkNotFound which is not meaningful here. Since we are also using the latter elsewhere, If I were me I would probably change it to that for consistency. Non binding comment.

Comment on lines +161 to +180
macvtapIface, err := netlink.LinkByName(currentIfaceName)
if err != nil {
return nil, fmt.Errorf("failed to lookup device %q: %v", currentIfaceName, err)
}

// move the macvtap interface to the pod's netns
if err = netlink.LinkSetNsFd(macvtapIface, int(netns.Fd())); err != nil {
return nil, fmt.Errorf("failed to move iface %s to the netns %d because: %v", macvtapIface, netns.Fd(), err)
}

var macvtap *current.Interface = nil

// configure the macvtap iface
err = netns.Do(func(_ ns.NetNS) error {
defer func() {
if err != nil {
LinkDelete(currentIfaceName)
LinkDelete(newIfaceName)
}
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

Another non binding cosmetic comment on my side. I would prefer the namespace business outside of the utility method. For me the namespace is too closely related to the main purpose of the cni that I would like it visible from the main CmdAdd method.

Comment on lines +216 to +220
macvtap = &current.Interface{
Name: newIfaceName,
Mac: macvtapIface.Attrs().HardwareAddr.String(),
Sandbox: netns.Path(),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, as my previous cosmetic comment, with this section. The current.Interface is directly related to the cni api and I would prefer it to be built in the main CmdAdd method than buried in an utility method. ConfigureInterface could return nothing, and we could have a specific utility method to re-fetch the mac address (only if none was specified).

return renamedMacvtapIface, nil
}

func configureArp(ifaceName string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto again with this method. I would probably call this from CmdAdd to give it more visibility/awareness as it would be diffcult to guess it from ConfigureInterface name or parameters and wends up pretty well hidden.

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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants