Skip to content

Commit

Permalink
Merge pull request #42 from kuramal/cni_plugin_conf_file_max_num
Browse files Browse the repository at this point in the history
add cni plugin config file max num config
  • Loading branch information
crosbymichael committed Jun 4, 2019
2 parents e1dc76f + b844801 commit 22460c0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
23 changes: 13 additions & 10 deletions cni.go
Expand Up @@ -41,10 +41,11 @@ type CNI interface {
}

type ConfigResult struct {
PluginDirs []string
PluginConfDir string
Prefix string
Networks []*ConfNetwork
PluginDirs []string
PluginConfDir string
PluginMaxConfNum int
Prefix string
Networks []*ConfNetwork
}

type ConfNetwork struct {
Expand Down Expand Up @@ -78,9 +79,10 @@ type libcni struct {
func defaultCNIConfig() *libcni {
return &libcni{
config: config{
pluginDirs: []string{DefaultCNIDir},
pluginConfDir: DefaultNetDir,
prefix: DefaultPrefix,
pluginDirs: []string{DefaultCNIDir},
pluginConfDir: DefaultNetDir,
pluginMaxConfNum: DefaultMaxConfNum,
prefix: DefaultPrefix,
},
cniConfig: &cnilibrary.CNIConfig{
Path: []string{DefaultCNIDir},
Expand Down Expand Up @@ -187,9 +189,10 @@ func (c *libcni) GetConfig() *ConfigResult {
c.RLock()
defer c.RUnlock()
r := &ConfigResult{
PluginDirs: c.config.pluginDirs,
PluginConfDir: c.config.pluginConfDir,
Prefix: c.config.prefix,
PluginDirs: c.config.pluginDirs,
PluginConfDir: c.config.pluginConfDir,
PluginMaxConfNum: c.config.pluginMaxConfNum,
Prefix: c.config.prefix,
}
for _, network := range c.networks {
conf := &NetworkConfList{
Expand Down
11 changes: 10 additions & 1 deletion opts.go
Expand Up @@ -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
// minimum networks to be configured and initialized
// for the status to report success. By default its 1.
Expand Down Expand Up @@ -159,7 +168,7 @@ func WithConfListFile(fileName string) CNIOpt {
// the convention chosen is - the first network configuration in the sorted
// list of network conf files as the default network.
func WithDefaultConf(c *libcni) error {
return loadFromConfDir(c, 1)
return loadFromConfDir(c, c.pluginMaxConfNum)
}

// WithAllConf can be used to detect all network config
Expand Down
8 changes: 5 additions & 3 deletions types.go
Expand Up @@ -20,14 +20,16 @@ const (
CNIPluginName = "cni"
DefaultNetDir = "/etc/cni/net.d"
DefaultCNIDir = "/opt/cni/bin"
DefaultMaxConfNum = 1
VendorCNIDirTemplate = "%s/opt/%s/bin"
DefaultPrefix = "eth"
)

type config struct {
pluginDirs []string
pluginConfDir string
prefix string
pluginDirs []string
pluginConfDir string
pluginMaxConfNum int
prefix string
}

type PortMapping struct {
Expand Down

0 comments on commit 22460c0

Please sign in to comment.