Add CNI conf based on runtime class
Signed-off-by: Michael Crosby <michael@thepasture.io>
This commit is contained in:
@@ -30,9 +30,7 @@ import (
|
||||
const networkAttachCount = 2
|
||||
|
||||
// initPlatform handles linux specific initialization for the CRI service.
|
||||
func (c *criService) initPlatform() error {
|
||||
var err error
|
||||
|
||||
func (c *criService) initPlatform() (err error) {
|
||||
if userns.RunningInUserNS() {
|
||||
if !(c.config.DisableCgroup && !c.apparmorEnabled() && c.config.RestrictOOMScoreAdj) {
|
||||
logrus.Warn("Running containerd in a user namespace typically requires disable_cgroup, disable_apparmor, restrict_oom_score_adj set to be true")
|
||||
@@ -50,16 +48,35 @@ func (c *criService) initPlatform() error {
|
||||
selinux.SetDisabled()
|
||||
}
|
||||
|
||||
// Pod needs to attach to at least loopback network and a non host network,
|
||||
// hence networkAttachCount is 2. 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(networkAttachCount),
|
||||
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
|
||||
}
|
||||
}
|
||||
// Pod needs to attach to at least loopback network and a non host network,
|
||||
// hence networkAttachCount is 2. 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(networkAttachCount),
|
||||
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
|
||||
}
|
||||
|
||||
if c.allCaps == nil {
|
||||
|
||||
Reference in New Issue
Block a user