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 macvtap device plugin #2

Merged
merged 1 commit into from
Feb 7, 2020
Merged

Add macvtap device plugin #2

merged 1 commit into from
Feb 7, 2020

Conversation

jcaamano
Copy link
Contributor

This commit adds the initial implementation of the macvtap device
plugin. Includes manifests & templates for deployment, as well as
some basic tests.

Further changes are expected as the macvtap cni is integrated.
RBAC and more thorough testing pending for a later patch.

What this PR does / why we need it:

Special notes for your reviewer:

@kubevirt-bot kubevirt-bot added the dco-signoff: no Indicates the PR's author has not DCO signed all their commits. label Jan 31, 2020
@kubevirt-bot kubevirt-bot added dco-signoff: yes Indicates the PR's author has DCO signed all their commits. and removed dco-signoff: no Indicates the PR's author has not DCO signed all their commits. labels Jan 31, 2020
Copy link
Collaborator

@maiqueb maiqueb left a comment

Choose a reason for hiding this comment

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

Let me try this locally before merging, but, right now can't nit-pick.

@maiqueb
Copy link
Collaborator

maiqueb commented Feb 4, 2020

Let me try this locally before merging, but, right now can't nit-pick.

Actually, I'm missing CI to run :)

That could possibly be done on a PR to be merged before this one; I can work on that later this week.

@jcaamano
Copy link
Contributor Author

jcaamano commented Feb 4, 2020

Let me try this locally before merging, but, right now can't nit-pick.

Actually, I'm missing CI to run :)

That could possibly be done on a PR to be merged before this one; I can work on that later this week.

You can still do cluster-up and a manual test with your code on top if you like but I actually think that it is better to get this PR and the CNI (with ut) in first and then we can both work on the e2e tests.

@maiqueb
Copy link
Collaborator

maiqueb commented Feb 4, 2020

Let me try this locally before merging, but, right now can't nit-pick.

Actually, I'm missing CI to run :)
That could possibly be done on a PR to be merged before this one; I can work on that later this week.

You can still do cluster-up and a manual test with your code on top if you like but I actually think that it is better to get this PR and the CNI (with ut) in first and then we can both work on the e2e tests.

Of course; I just mean triggering the unit tests you've added as a result of this PR.

@phoracek
Copy link
Member

phoracek commented Feb 4, 2020

WIP CI PR: kubevirt/project-infra#308

cmd/Dockerfile Outdated

FROM registry.access.redhat.com/ubi8/ubi-minimal
COPY --from=builder /macvtap /macvtap
ENTRYPOINT [ "./macvtap", "-v", "3", "-logtostderr"]
Copy link
Member

Choose a reason for hiding this comment

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

Please insert a new line at the end of the file.

func CreateMacvtap(name string, master string, mode string) (int, error) {
// attempt to delete any previously existing link
if l, _ := netlink.LinkByName(name); l != nil {
_ = netlink.LinkDel(l)
Copy link
Member

Choose a reason for hiding this comment

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

You can drop _ = if you don't care about the returned value

}

func CreateMacvtap(name string, master string, mode string) (int, error) {
// attempt to delete any previously existing link
Copy link
Member

Choose a reason for hiding this comment

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

To make it clear what is the int you are returning representing, would you please initialize the variable here with a proper name and default value 0?

return CreateMacvtap(name, master, mode)
}

func LinkExists(link string) error {
Copy link
Member

Choose a reason for hiding this comment

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

This should return bool. If it fails, it does not necessarily mean the link does not exist. Could you check the returned value? As you do in the following function.

}

func (ml MacvtapLister) Discover(pluginListCh chan dpm.PluginNameList) {
var plugins = make(dpm.PluginNameList, 0)
Copy link
Member

Choose a reason for hiding this comment

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

So to apply new config, all DaemonSets need to be restarted? Could you document it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, ideally deleting the config map and creating a new one would take care of it. I was waiting for the cni to wire an encompassing readme to include this information.


const (
tapPath = "/dev/tap"
suffix = "Mvp"
Copy link
Member

Choose a reason for hiding this comment

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

what's that?

}

func (mdp *MacvtapDevicePlugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error {
masterDevs := mdp.generateMacvtapDevices()
Copy link
Member

Choose a reason for hiding this comment

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

These are not master devs though, these are slaves connected to the master.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jcaamano I understand what you're doing, it's easier to follow now. Despite that, the name 'masterDevs' is extremely misleading.

Do you think allocatedMacvtaps & emptyMacvtapList is an acceptable compromise ?

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 see. I tried to improve these variable names on the latest push.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for listening; it's now OK for me.

}
}

didMasterExist := false
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add an inline comment documenting what are you doing in the following block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

return true
}

func (mdp *MacvtapDevicePlugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment describing which interfaces are offered here. I don't get why it requires so much code, you just need to create bunch of fake Devices, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not only that but also keeping up with the master device. If there is no master, there is no point in offering devices for allocation as it will fail.

var devices []*pluginapi.DeviceSpec
for _, name := range req.DevicesIDs {
dev := new(pluginapi.DeviceSpec)
index, err := util.RecreateMacvtap(name, mdp.Master, mdp.Mode)
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment explaining why do you need to recreate

@jcaamano
Copy link
Contributor Author

jcaamano commented Feb 4, 2020

@phoracek hopefully addressed your requests. Thanks!

This commit adds the initial implementation of the macvtap device
plugin. Includes manifests & templates for deployment, as well as
some basic tests.

Further changes are expected as the macvtap cni is integrated.
RBAC and more thorough testing pending for a later patch.

Signed-off-by: Jaime Caamaño Ruiz <[email protected]>
@maiqueb
Copy link
Collaborator

maiqueb commented Feb 5, 2020

LGTM

@phoracek phoracek merged commit 7601bd6 into kubevirt:master Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants