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

macvlan: support chaining for master interface #903

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

firemiles
Copy link

@firemiles firemiles commented Jun 4, 2023

this patch support macvlan get master from previous Result

Closes: #901

@firemiles firemiles force-pushed the macvlan-support-chain branch 2 times, most recently from 2c8a3d7 to 468e2f3 Compare June 4, 2023 14:08
If "master" is omitted from the macvlan configuration, then macvlan can
get master from previous Result which contain a single interface name.

Signed-off-by: firemiles <miles.dev@outlook.com>
}
n.Master = defaultRouteInterface
} else {
if len(result.Interfaces) == 1 && result.Interfaces[0].Name != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Rather than just picking the first interface, what if we were a bit cleverer?

Right now, the macvlan plugin has the option to pick from the host namespace or container namespace. Let's preserve that when it is chained. Specifically, if n.LinkContNS is true, then pick the first value in prevResult where sandbox == true. Even better would be to pick the first result with routes or an IP address. Likewise, if n.LinkContNS is false, then do the same but for host-side interfaces.

Makes sense?

Copy link
Member

Choose a reason for hiding this comment

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

Likewise, this brings up the interesting idea that, if n.LinkContNS is true, we should just use whatever interface name matches CNI_IFNAME, then we should rename that out and create our interface to CNI_IFNAME. Make sense?

Copy link
Member

Choose a reason for hiding this comment

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

@mmirecki any thoughts here?

Copy link
Author

@firemiles firemiles Jul 7, 2023

Choose a reason for hiding this comment

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

Rather than just picking the first interface, what if we were a bit cleverer?

Right now, the macvlan plugin has the option to pick from the host namespace or container namespace. Let's preserve that when it is chained. Specifically, if n.LinkContNS is true, then pick the first value in prevResult where sandbox == true. Even better would be to pick the first result with routes or an IP address. Likewise, if n.LinkContNS is false, then do the same but for host-side interfaces.

Makes sense?

We have a scenario where we need to dynamically select the host master to create macvlan, and I don't know much about the scenario where we need to select master in the container.

@s1061123
Copy link
Contributor

Thank you for the contribution. I agreed your concepts.

I suppose we need to clarify how macvlan selects master interface from all combination of the options.
Currently macvlan uses 'master' and 'linkInContainer' parameters in CNI conf. Your PR introduces anther way to inject options, prevResults and it may conflicts with 'master' and 'linkInContainer' parameters.

We also need to describe somewhere in code otherwise we may get confused later.

if len(result.Interfaces) == 1 && result.Interfaces[0].Name != "" {
n.Master = result.Interfaces[0].Name
} else {
return nil, "", fmt.Errorf("chained master failure. PrevResult lacks a single named interface")
Copy link
Contributor

Choose a reason for hiding this comment

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

I am thinking that we could provide a way to pick interface from prevResult by 'master' option.
I'm just wondering how about to pick interface by 'master' option name if prevResult != nil and multiple interfaces in result.

Copy link
Author

Choose a reason for hiding this comment

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

master option is a static option in cni config. how to dynamic config for different master? Give a special master option value to tell maclvan plugin to get master from prevResult ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macvlan: support enslaving an interface by chainning
3 participants