-
Notifications
You must be signed in to change notification settings - Fork 802
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,12 +107,35 @@ func loadConf(args *skel.CmdArgs, envArgs string) (*NetConf, string, error) { | |
if err := json.Unmarshal(args.StdinData, n); err != nil { | ||
return nil, "", fmt.Errorf("failed to load netconf: %v", err) | ||
} | ||
if n.Master == "" { | ||
defaultRouteInterface, err := getNamespacedDefaultRouteInterfaceName(args.Netns, n.LinkContNs) | ||
|
||
var result *current.Result | ||
var err error | ||
// Parse previous result | ||
if n.NetConf.RawPrevResult != nil { | ||
if err = version.ParsePrevResult(&n.NetConf); err != nil { | ||
return nil, "", fmt.Errorf("could not parse prevResult: %v", err) | ||
} | ||
|
||
result, err = current.NewResultFromResult(n.PrevResult) | ||
if err != nil { | ||
return nil, "", err | ||
return nil, "", fmt.Errorf("could not convert result to current version: %v", err) | ||
} | ||
} | ||
if n.Master == "" { | ||
if result == nil { | ||
var defaultRouteInterface string | ||
defaultRouteInterface, err = getNamespacedDefaultRouteInterfaceName(args.Netns, n.LinkContNs) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
n.Master = defaultRouteInterface | ||
} else { | ||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
n.Master = defaultRouteInterface | ||
} | ||
|
||
// check existing and MTU of master interface | ||
|
There was a problem hiding this comment.
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 inprevResult
wheresandbox == true
. Even better would be to pick the first result with routes or an IP address. Likewise, ifn.LinkContNS
is false, then do the same but for host-side interfaces.Makes sense?
There was a problem hiding this comment.
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 matchesCNI_IFNAME
, then we should rename that out and create our interface toCNI_IFNAME
. Make sense?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmirecki any thoughts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.