mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-08-31 16:38:43 +00:00
Merge pull request #1125 from s1061123/refine-options
Refine and fix parameters
This commit is contained in:
@@ -80,8 +80,6 @@ func main() {
|
||||
_ = logging.Errorf("the CNI version is a mandatory parameter when the '-multus-config-file=auto' option is used")
|
||||
}
|
||||
|
||||
multusConf.SocketDir = daemonConf.SocketDir
|
||||
|
||||
var configManager *config.Manager
|
||||
if multusConf.MultusMasterCni == "" {
|
||||
configManager, err = config.NewManager(*multusConf, multusConf.MultusAutoconfigDir, multusConf.ForceCNIVersion)
|
||||
|
@@ -41,6 +41,7 @@ type Options struct {
|
||||
CNIVersion string
|
||||
MultusConfFile string
|
||||
MultusBinFile string // may be hidden or remove?
|
||||
MultusCNIConfDir string
|
||||
SkipMultusBinaryCopy bool
|
||||
MultusKubeConfigFileHost string
|
||||
MultusMasterCNIFileName string
|
||||
@@ -72,6 +73,7 @@ func (o *Options) addFlags() {
|
||||
fs.StringVar(&o.CNIVersion, "cni-version", "", "CNI version for multus CNI config (e.g. '0.3.1')")
|
||||
fs.StringVar(&o.MultusConfFile, "multus-conf-file", "auto", "multus CNI config file")
|
||||
fs.StringVar(&o.MultusBinFile, "multus-bin-file", "/usr/src/multus-cni/bin/multus", "multus binary file path")
|
||||
fs.StringVar(&o.MultusCNIConfDir, "multus-cni-conf-dir", "/host/etc/cni/multus/net.d", "multus specific CNI config directory")
|
||||
fs.BoolVar(&o.SkipMultusBinaryCopy, "skip-multus-binary-copy", false, "skip multus binary file copy")
|
||||
|
||||
fs.StringVar(&o.MultusKubeConfigFileHost, "multus-kubeconfig-file-host", "/etc/cni/net.d/multus.d/multus.kubeconfig", "kubeconfig for multus (used only with --multus-conf-file=auto)")
|
||||
@@ -152,6 +154,11 @@ func (o *Options) createKubeConfig(currentFileHash []byte) ([]byte, error) {
|
||||
return nil, fmt.Errorf("cannot create multus.d directory: %v", err)
|
||||
}
|
||||
|
||||
// create multus cni conf directory
|
||||
if err := os.MkdirAll(o.MultusCNIConfDir, 0755); err != nil {
|
||||
return nil, fmt.Errorf("cannot create multus-cni-conf-dir(%s) directory: %v", o.MultusCNIConfDir, err)
|
||||
}
|
||||
|
||||
// get Kubernetes service protocol/host/port
|
||||
kubeProtocol := os.Getenv("KUBERNETES_SERVICE_PROTOCOL")
|
||||
if kubeProtocol == "" {
|
||||
@@ -249,6 +256,8 @@ const multusConflistTemplate = `{
|
||||
.LogFileConfig
|
||||
}}{{
|
||||
.AdditionalBinDirConfig
|
||||
}}{{
|
||||
.MultusCNIConfDirConfig
|
||||
}}{{
|
||||
.ReadinessIndicatorFileConfig
|
||||
}}
|
||||
@@ -277,6 +286,8 @@ const multusConfTemplate = `{
|
||||
.LogFileConfig
|
||||
}}{{
|
||||
.AdditionalBinDirConfig
|
||||
}}{{
|
||||
.MultusCNIConfDirConfig
|
||||
}}{{
|
||||
.ReadinessIndicatorFileConfig
|
||||
}}
|
||||
@@ -415,6 +426,12 @@ func (o *Options) createMultusConfig() (string, error) {
|
||||
additionalBinDirConfig = fmt.Sprintf("\n \"binDir\": %q,", o.AdditionalBinDir)
|
||||
}
|
||||
|
||||
// check MultusCNIConfDir
|
||||
multusCNIConfDirConfig := ""
|
||||
if o.MultusCNIConfDir != "" {
|
||||
multusCNIConfDirConfig = fmt.Sprintf("\n \"cniConf\": %q,", o.MultusCNIConfDir)
|
||||
}
|
||||
|
||||
// check ReadinessIndicatorFile
|
||||
readinessIndicatorFileConfig := ""
|
||||
if o.ReadinessIndicatorFile != "" {
|
||||
@@ -459,6 +476,7 @@ func (o *Options) createMultusConfig() (string, error) {
|
||||
"LogLevelConfig": logLevelConfig,
|
||||
"LogFileConfig": logFileConfig,
|
||||
"AdditionalBinDirConfig": additionalBinDirConfig,
|
||||
"MultusCNIConfDirConfig": multusCNIConfDirConfig,
|
||||
"ReadinessIndicatorFileConfig": readinessIndicatorFileConfig,
|
||||
"MultusKubeConfigFileHost": o.MultusKubeConfigFileHost, // be fixed?
|
||||
"MasterPluginJSON": string(masterPluginByte),
|
||||
|
@@ -210,6 +210,7 @@ var _ = Describe("thin entrypoint testing", func() {
|
||||
MultusLogLevel: "DEBUG",
|
||||
MultusLogFile: "/tmp/foobar.log",
|
||||
AdditionalBinDir: "/tmp/add_bin_dir",
|
||||
MultusCNIConfDir: "/tmp/multus/net.d",
|
||||
ReadinessIndicatorFile: "/var/lib/foobar_indicator",
|
||||
}).createMultusConfig()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@@ -225,6 +226,7 @@ var _ = Describe("thin entrypoint testing", func() {
|
||||
"logLevel": "debug",
|
||||
"logFile": "/tmp/foobar.log",
|
||||
"binDir": "/tmp/add_bin_dir",
|
||||
"cniConf": "/tmp/multus/net.d",
|
||||
"readinessindicatorfile": "/var/lib/foobar_indicator",
|
||||
"kubeconfig": "/etc/foobar_kubeconfig",
|
||||
"delegates": [
|
||||
@@ -368,6 +370,7 @@ var _ = Describe("thin entrypoint testing", func() {
|
||||
MultusLogLevel: "DEBUG",
|
||||
MultusLogFile: "/tmp/foobar.log",
|
||||
AdditionalBinDir: "/tmp/add_bin_dir",
|
||||
MultusCNIConfDir: "/tmp/multus/net.d",
|
||||
ReadinessIndicatorFile: "/var/lib/foobar_indicator",
|
||||
}).createMultusConfig()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@@ -385,6 +388,7 @@ var _ = Describe("thin entrypoint testing", func() {
|
||||
"logLevel": "debug",
|
||||
"logFile": "/tmp/foobar.log",
|
||||
"binDir": "/tmp/add_bin_dir",
|
||||
"cniConf": "/tmp/multus/net.d",
|
||||
"readinessindicatorfile": "/var/lib/foobar_indicator",
|
||||
"kubeconfig": "/etc/foobar_kubeconfig",
|
||||
"delegates": [
|
||||
|
@@ -111,13 +111,12 @@ data:
|
||||
daemon-config.json: |
|
||||
{
|
||||
"chrootDir": "/hostroot",
|
||||
"confDir": "/host/etc/cni/net.d",
|
||||
"logLevel": "verbose",
|
||||
"socketDir": "/host/run/multus/",
|
||||
"cniVersion": "0.3.1",
|
||||
"cniConfigDir": "/host/etc/cni/net.d",
|
||||
"logLevel": "verbose",
|
||||
"logToStderr": true,
|
||||
"multusAutoconfigDir": "/host/etc/cni/net.d",
|
||||
"multusConfigFile": "auto",
|
||||
"multusAutoconfigDir": "/host/etc/cni/net.d"
|
||||
"socketDir": "/host/run/multus/"
|
||||
}
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
|
@@ -651,7 +651,7 @@ func CmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (c
|
||||
|
||||
// check Interfaces and IPs because some CNI plugin does not create any interface
|
||||
// and just returns empty result
|
||||
if res != nil && (res.Interfaces != nil || res.IPs != nil) {
|
||||
if res != nil && (res.Interfaces != nil || res.IPs != nil) {
|
||||
// Remove gateway from routing table if the gateway is not used
|
||||
deleteV4gateway := false
|
||||
deleteV6gateway := false
|
||||
|
@@ -55,7 +55,7 @@ type MultusConf struct {
|
||||
Type string `json:"type"`
|
||||
CniDir string `json:"cniDir,omitempty"`
|
||||
CniConfigDir string `json:"cniConfigDir,omitempty"`
|
||||
SocketDir string `json:"socketDir,omitempty"`
|
||||
DaemonSocketDir string `json:"daemonSocketDir,omitempty"`
|
||||
MultusConfigFile string `json:"multusConfigFile,omitempty"`
|
||||
MultusMasterCni string `json:"multusMasterCNI,omitempty"`
|
||||
MultusAutoconfigDir string `json:"multusAutoconfigDir,omitempty"`
|
||||
|
@@ -108,7 +108,7 @@ func newManager(config MultusConf, multusConfigDir, defaultCNIPluginName string,
|
||||
configWatcher: watcher,
|
||||
multusConfig: &config,
|
||||
multusConfigDir: multusConfigDir,
|
||||
multusConfigFilePath: cniPluginConfigFilePath(multusConfigDir, multusConfigFileName),
|
||||
multusConfigFilePath: cniPluginConfigFilePath(config.CniConfigDir, multusConfigFileName),
|
||||
primaryCNIConfigPath: cniPluginConfigFilePath(multusConfigDir, defaultCNIPluginName),
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user