Merge pull request #7685 from sofat1989/mainrunserially
can set up the network serially by CNI plugins
This commit is contained in:
commit
8e787543de
@ -143,6 +143,9 @@ type CniConfig struct {
|
|||||||
// be loaded from the cni config directory by go-cni. Set the value to 0 to
|
// be loaded from the cni config directory by go-cni. Set the value to 0 to
|
||||||
// load all config files (no arbitrary limit). The legacy default value is 1.
|
// load all config files (no arbitrary limit). The legacy default value is 1.
|
||||||
NetworkPluginMaxConfNum int `toml:"max_conf_num" json:"maxConfNum"`
|
NetworkPluginMaxConfNum int `toml:"max_conf_num" json:"maxConfNum"`
|
||||||
|
// NetworkPluginSetupSerially is a boolean flag to specify whether containerd sets up networks serially
|
||||||
|
// if there are multiple CNI plugin config files existing and NetworkPluginMaxConfNum is larger than 1.
|
||||||
|
NetworkPluginSetupSerially bool `toml:"setup_serially" json:"setupSerially"`
|
||||||
// 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(s) from kubelet to replace {{.PodCIDR}},
|
// When it is set, containerd will get cidr(s) from kubelet to replace {{.PodCIDR}},
|
||||||
|
@ -66,10 +66,11 @@ func DefaultConfig() PluginConfig {
|
|||||||
tree, _ := toml.Load(defaultRuncV2Opts)
|
tree, _ := toml.Load(defaultRuncV2Opts)
|
||||||
return PluginConfig{
|
return 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, // only one CNI plugin config file will be loaded
|
NetworkPluginMaxConfNum: 1, // only one CNI plugin config file will be loaded
|
||||||
NetworkPluginConfTemplate: "",
|
NetworkPluginSetupSerially: false,
|
||||||
|
NetworkPluginConfTemplate: "",
|
||||||
},
|
},
|
||||||
ContainerdConfig: ContainerdConfig{
|
ContainerdConfig: ContainerdConfig{
|
||||||
Snapshotter: containerd.DefaultSnapshotter,
|
Snapshotter: containerd.DefaultSnapshotter,
|
||||||
|
@ -29,10 +29,11 @@ import (
|
|||||||
func DefaultConfig() PluginConfig {
|
func DefaultConfig() PluginConfig {
|
||||||
return PluginConfig{
|
return PluginConfig{
|
||||||
CniConfig: CniConfig{
|
CniConfig: CniConfig{
|
||||||
NetworkPluginBinDir: filepath.Join(os.Getenv("ProgramFiles"), "containerd", "cni", "bin"),
|
NetworkPluginBinDir: filepath.Join(os.Getenv("ProgramFiles"), "containerd", "cni", "bin"),
|
||||||
NetworkPluginConfDir: filepath.Join(os.Getenv("ProgramFiles"), "containerd", "cni", "conf"),
|
NetworkPluginConfDir: filepath.Join(os.Getenv("ProgramFiles"), "containerd", "cni", "conf"),
|
||||||
NetworkPluginMaxConfNum: 1,
|
NetworkPluginMaxConfNum: 1,
|
||||||
NetworkPluginConfTemplate: "",
|
NetworkPluginSetupSerially: false,
|
||||||
|
NetworkPluginConfTemplate: "",
|
||||||
},
|
},
|
||||||
ContainerdConfig: ContainerdConfig{
|
ContainerdConfig: ContainerdConfig{
|
||||||
Snapshotter: containerd.DefaultSnapshotter,
|
Snapshotter: containerd.DefaultSnapshotter,
|
||||||
|
@ -425,6 +425,8 @@ func (c *criService) setupPodNetwork(ctx context.Context, sandbox *sandboxstore.
|
|||||||
config = sandbox.Config
|
config = sandbox.Config
|
||||||
path = sandbox.NetNSPath
|
path = sandbox.NetNSPath
|
||||||
netPlugin = c.getNetworkPlugin(sandbox.RuntimeHandler)
|
netPlugin = c.getNetworkPlugin(sandbox.RuntimeHandler)
|
||||||
|
err error
|
||||||
|
result *cni.Result
|
||||||
)
|
)
|
||||||
if netPlugin == nil {
|
if netPlugin == nil {
|
||||||
return errors.New("cni config not initialized")
|
return errors.New("cni config not initialized")
|
||||||
@ -435,7 +437,11 @@ func (c *criService) setupPodNetwork(ctx context.Context, sandbox *sandboxstore.
|
|||||||
return fmt.Errorf("get cni namespace options: %w", err)
|
return fmt.Errorf("get cni namespace options: %w", err)
|
||||||
}
|
}
|
||||||
log.G(ctx).WithField("podsandboxid", id).Debugf("begin cni setup")
|
log.G(ctx).WithField("podsandboxid", id).Debugf("begin cni setup")
|
||||||
result, err := netPlugin.Setup(ctx, id, path, opts...)
|
if c.config.CniConfig.NetworkPluginSetupSerially {
|
||||||
|
result, err = netPlugin.SetupSerially(ctx, id, path, opts...)
|
||||||
|
} else {
|
||||||
|
result, err = netPlugin.Setup(ctx, id, path, opts...)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user