Merge pull request #1155 from kuramal/cni_plugin_conf_file_max_num

add cni plugin config file max num config
This commit is contained in:
Lantao Liu 2019-06-10 10:14:35 -07:00 committed by GitHub
commit 53c71e2b10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 15 deletions

View File

@ -149,6 +149,12 @@ The explanation and default value of each configuration item are as follows:
# conf_dir is the directory in which the admin places a CNI conf. # conf_dir is the directory in which the admin places a CNI conf.
conf_dir = "/etc/cni/net.d" conf_dir = "/etc/cni/net.d"
# max_conf_num is the max number of CNI plugin config file will load
# By default, the containerd will load only 1 CRI plugin. If you want load multiple CRI plugins,
# set max_conf_num > 1. You should know exactly each CRI plugin do, whether they are compatible.
# max i<= 0 means no limit.
max_conf_num = 1
# conf_template is the file path of golang template used to generate # conf_template is the file path of golang template used to generate
# cni config. # cni config.
# If this is set, containerd will generate a cni config file from the # If this is set, containerd will generate a cni config file from the

View File

@ -71,6 +71,8 @@ type CniConfig struct {
NetworkPluginBinDir string `toml:"bin_dir" json:"binDir"` NetworkPluginBinDir string `toml:"bin_dir" json:"binDir"`
// NetworkPluginConfDir is the directory in which the admin places a CNI conf. // NetworkPluginConfDir is the directory in which the admin places a CNI conf.
NetworkPluginConfDir string `toml:"conf_dir" json:"confDir"` NetworkPluginConfDir string `toml:"conf_dir" json:"confDir"`
// NetworkPluginMaxConfNum is the max number of plugin config file will load
NetworkPluginMaxConfNum int `toml:"max_conf_num" json:"maxConfNum"`
// NetworkPluginConfTemplate is the file path of golang template used to generate // NetworkPluginConfTemplate is the file path of golang template used to generate
// cni config. // cni config.
// When it is set, containerd will get cidr from kubelet to replace {{.PodCIDR}} in // When it is set, containerd will get cidr from kubelet to replace {{.PodCIDR}} in
@ -202,6 +204,7 @@ func DefaultConfig() PluginConfig {
CniConfig: CniConfig{ CniConfig: CniConfig{
NetworkPluginBinDir: "/opt/cni/bin", NetworkPluginBinDir: "/opt/cni/bin",
NetworkPluginConfDir: "/etc/cni/net.d", NetworkPluginConfDir: "/etc/cni/net.d",
NetworkPluginMaxConfNum: 1,
NetworkPluginConfTemplate: "", NetworkPluginConfTemplate: "",
}, },
ContainerdConfig: ContainerdConfig{ ContainerdConfig: ContainerdConfig{

View File

@ -148,6 +148,7 @@ func NewCRIService(config criconfig.Config, client *containerd.Client) (CRIServi
// of the default network interface as the pod IP. // of the default network interface as the pod IP.
c.netPlugin, err = cni.New(cni.WithMinNetworkCount(networkAttachCount), c.netPlugin, err = cni.New(cni.WithMinNetworkCount(networkAttachCount),
cni.WithPluginConfDir(config.NetworkPluginConfDir), cni.WithPluginConfDir(config.NetworkPluginConfDir),
cni.WithPluginMaxConfNum(config.NetworkPluginMaxConfNum),
cni.WithPluginDir([]string{config.NetworkPluginBinDir})) cni.WithPluginDir([]string{config.NetworkPluginBinDir}))
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to initialize cni") return nil, errors.Wrap(err, "failed to initialize cni")

View File

@ -5,7 +5,7 @@ github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23
github.com/containerd/containerd 32e788a8be3ab4418265693d9e742c30495fdd4c github.com/containerd/containerd 32e788a8be3ab4418265693d9e742c30495fdd4c
github.com/containerd/continuity bd77b46c8352f74eb12c85bdc01f4b90f69d66b4 github.com/containerd/continuity bd77b46c8352f74eb12c85bdc01f4b90f69d66b4
github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c
github.com/containerd/go-cni e1dc76fa62e1665cf5d85fd617c6191d66f0e72d github.com/containerd/go-cni 22460c018b64cf8bf4151b3ff9c4d077e6a88cbf
github.com/containerd/go-runc 5a6d9f37cfa36b15efba46dc7ea349fa9b7143c3 github.com/containerd/go-runc 5a6d9f37cfa36b15efba46dc7ea349fa9b7143c3
github.com/containerd/ttrpc f02858b1457c5ca3aaec3a0803eb0d59f96e41d6 github.com/containerd/ttrpc f02858b1457c5ca3aaec3a0803eb0d59f96e41d6
github.com/containerd/typeurl a93fcdb778cd272c6e9b3028b2f42d813e785d40 github.com/containerd/typeurl a93fcdb778cd272c6e9b3028b2f42d813e785d40

View File

@ -43,6 +43,7 @@ type CNI interface {
type ConfigResult struct { type ConfigResult struct {
PluginDirs []string PluginDirs []string
PluginConfDir string PluginConfDir string
PluginMaxConfNum int
Prefix string Prefix string
Networks []*ConfNetwork Networks []*ConfNetwork
} }
@ -80,6 +81,7 @@ func defaultCNIConfig() *libcni {
config: config{ config: config{
pluginDirs: []string{DefaultCNIDir}, pluginDirs: []string{DefaultCNIDir},
pluginConfDir: DefaultNetDir, pluginConfDir: DefaultNetDir,
pluginMaxConfNum: DefaultMaxConfNum,
prefix: DefaultPrefix, prefix: DefaultPrefix,
}, },
cniConfig: &cnilibrary.CNIConfig{ cniConfig: &cnilibrary.CNIConfig{
@ -189,6 +191,7 @@ func (c *libcni) GetConfig() *ConfigResult {
r := &ConfigResult{ r := &ConfigResult{
PluginDirs: c.config.pluginDirs, PluginDirs: c.config.pluginDirs,
PluginConfDir: c.config.pluginConfDir, PluginConfDir: c.config.pluginConfDir,
PluginMaxConfNum: c.config.pluginMaxConfNum,
Prefix: c.config.prefix, Prefix: c.config.prefix,
} }
for _, network := range c.networks { for _, network := range c.networks {

View File

@ -54,6 +54,15 @@ func WithPluginConfDir(dir string) CNIOpt {
} }
} }
// WithPluginMaxConfNum can be used to configure the
// max cni plugin config file num.
func WithPluginMaxConfNum(max int) CNIOpt {
return func(c *libcni) error {
c.pluginMaxConfNum = max
return nil
}
}
// WithMinNetworkCount can be used to configure the // WithMinNetworkCount can be used to configure the
// minimum networks to be configured and initialized // minimum networks to be configured and initialized
// for the status to report success. By default its 1. // for the status to report success. By default its 1.
@ -159,7 +168,7 @@ func WithConfListFile(fileName string) CNIOpt {
// the convention chosen is - the first network configuration in the sorted // the convention chosen is - the first network configuration in the sorted
// list of network conf files as the default network. // list of network conf files as the default network.
func WithDefaultConf(c *libcni) error { func WithDefaultConf(c *libcni) error {
return loadFromConfDir(c, 1) return loadFromConfDir(c, c.pluginMaxConfNum)
} }
// WithAllConf can be used to detect all network config // WithAllConf can be used to detect all network config

View File

@ -20,6 +20,7 @@ const (
CNIPluginName = "cni" CNIPluginName = "cni"
DefaultNetDir = "/etc/cni/net.d" DefaultNetDir = "/etc/cni/net.d"
DefaultCNIDir = "/opt/cni/bin" DefaultCNIDir = "/opt/cni/bin"
DefaultMaxConfNum = 1
VendorCNIDirTemplate = "%s/opt/%s/bin" VendorCNIDirTemplate = "%s/opt/%s/bin"
DefaultPrefix = "eth" DefaultPrefix = "eth"
) )
@ -27,6 +28,7 @@ const (
type config struct { type config struct {
pluginDirs []string pluginDirs []string
pluginConfDir string pluginConfDir string
pluginMaxConfNum int
prefix string prefix string
} }