Set interface name to the network_interface name for macvlan and ipvlan networks

When interface_name attribute in containers.conf file is set to "device", then set interface names inside containers same as the network_interface names of the respective network.

The change applies to macvlan and ipvlan networks only. The interface_name attribute value has no impact on any other types of networks.

If the interface name is set in the user request, then that takes precedence.

Fixes: #21313

Signed-off-by: Vikas Goel <vikas.goel@gmail.com>
This commit is contained in:
Vikas Goel
2024-01-30 12:40:39 -08:00
parent 855a7cf0f4
commit a8b2256cc1
3 changed files with 313 additions and 8 deletions

View File

@ -264,11 +264,18 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
}
i := 0
for nameOrID, opts := range ctr.config.Networks {
netName, err := r.normalizeNetworkName(nameOrID)
netName, nicName, err := r.normalizeNetworkName(nameOrID)
if err != nil {
return nil, err
}
// assign interface name if empty
// check whether interface is to be named as the network_interface
// when name left unspecified
if opts.InterfaceName == "" {
opts.InterfaceName = nicName
}
// assign default interface name if empty
if opts.InterfaceName == "" {
for i < 100000 {
ifName := fmt.Sprintf("eth%d", i)