Add CNI conf based on runtime class
Signed-off-by: Michael Crosby <michael@thepasture.io>
This commit is contained in:
@@ -27,18 +27,36 @@ const windowsNetworkAttachCount = 1
|
||||
|
||||
// initPlatform handles linux specific initialization for the CRI service.
|
||||
func (c *criService) initPlatform() error {
|
||||
var err error
|
||||
// For windows, the loopback network is added as default.
|
||||
// There is no need to explicitly add one hence networkAttachCount is 1.
|
||||
// If there are more network configs the pod will be attached to all the
|
||||
// networks but we will only use the ip of the default network interface
|
||||
// as the pod IP.
|
||||
c.netPlugin, err = cni.New(cni.WithMinNetworkCount(windowsNetworkAttachCount),
|
||||
cni.WithPluginConfDir(c.config.NetworkPluginConfDir),
|
||||
cni.WithPluginMaxConfNum(c.config.NetworkPluginMaxConfNum),
|
||||
cni.WithPluginDir([]string{c.config.NetworkPluginBinDir}))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize cni")
|
||||
pluginDirs := map[string]string{
|
||||
defaultNetworkPlugin: c.config.NetworkPluginConfDir,
|
||||
}
|
||||
for name, conf := range c.config.Runtimes {
|
||||
if conf.NetworkPluginConfDir != "" {
|
||||
pluginDirs[name] = conf.NetworkPluginConfDir
|
||||
}
|
||||
}
|
||||
|
||||
c.netPlugin = make(map[string]cni.CNI)
|
||||
for name, dir := range pluginDirs {
|
||||
max := c.config.NetworkPluginMaxConfNum
|
||||
if name != defaultNetworkPlugin {
|
||||
if m := c.config.Runtimes[name].NetworkPluginMaxConfNum; m != 0 {
|
||||
max = m
|
||||
}
|
||||
}
|
||||
// For windows, the loopback network is added as default.
|
||||
// There is no need to explicitly add one hence networkAttachCount is 1.
|
||||
// If there are more network configs the pod will be attached to all the
|
||||
// networks but we will only use the ip of the default network interface
|
||||
// as the pod IP.
|
||||
i, err := cni.New(cni.WithMinNetworkCount(windowsNetworkAttachCount),
|
||||
cni.WithPluginConfDir(dir),
|
||||
cni.WithPluginMaxConfNum(max),
|
||||
cni.WithPluginDir([]string{c.config.NetworkPluginBinDir}))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize cni")
|
||||
}
|
||||
c.netPlugin[name] = i
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user