mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-20 09:01:15 +00:00
Updates config options and tests for socketfile and cniconfdir between thin/thick (#1002)
This commit is contained in:
@@ -56,6 +56,7 @@ const (
|
|||||||
defaultMultusMasterCNIFile = ""
|
defaultMultusMasterCNIFile = ""
|
||||||
defaultMultusNamespaceIsolation = false
|
defaultMultusNamespaceIsolation = false
|
||||||
defaultMultusReadinessIndicatorFile = ""
|
defaultMultusReadinessIndicatorFile = ""
|
||||||
|
defaultSocketDir = "/run/multus/"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -75,6 +76,7 @@ func main() {
|
|||||||
logMaxBackups := flag.Int("multus-log-max-backups", defaultMultusLogMaxBackups, "The maximum number of old log files to retain")
|
logMaxBackups := flag.Int("multus-log-max-backups", defaultMultusLogMaxBackups, "The maximum number of old log files to retain")
|
||||||
logCompress := flag.Bool("multus-log-compress", defaultMultusLogCompress, "Compress determines if the rotated log files should be compressed using gzip")
|
logCompress := flag.Bool("multus-log-compress", defaultMultusLogCompress, "Compress determines if the rotated log files should be compressed using gzip")
|
||||||
cniVersion := flag.String("cni-version", "", "Allows you to specify CNI spec version. Used only with --multus-conf-file=auto.")
|
cniVersion := flag.String("cni-version", "", "Allows you to specify CNI spec version. Used only with --multus-conf-file=auto.")
|
||||||
|
socketDir := flag.String("socket-dir", defaultSocketDir, "Specifies the directory where the socket file resides.")
|
||||||
forceCNIVersion := flag.Bool("force-cni-version", false, "Force to use given CNI version. only for kind-e2e testing") // this is only for kind-e2e
|
forceCNIVersion := flag.Bool("force-cni-version", false, "Force to use given CNI version. only for kind-e2e testing") // this is only for kind-e2e
|
||||||
readinessIndicator := flag.String("readiness-indicator-file", "", "Which file should be used as the readiness indicator. Used only with --multus-conf-file=auto.")
|
readinessIndicator := flag.String("readiness-indicator-file", "", "Which file should be used as the readiness indicator. Used only with --multus-conf-file=auto.")
|
||||||
overrideNetworkName := flag.Bool("override-network-name", false, "Used when we need overrides the name of the multus configuration with the name of the delegated primary CNI")
|
overrideNetworkName := flag.Bool("override-network-name", false, "Used when we need overrides the name of the multus configuration with the name of the delegated primary CNI")
|
||||||
@@ -136,6 +138,12 @@ func main() {
|
|||||||
configurationOptions, config.WithReadinessFileIndicator(*readinessIndicator))
|
configurationOptions, config.WithReadinessFileIndicator(*readinessIndicator))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configurationOptions = append(
|
||||||
|
configurationOptions, config.WithCniConfigDir(*cniConfigDir))
|
||||||
|
|
||||||
|
configurationOptions = append(
|
||||||
|
configurationOptions, config.WithSocketDir(*socketDir))
|
||||||
|
|
||||||
// logOptions
|
// logOptions
|
||||||
|
|
||||||
var logOptionFuncs []config.LogOptionFunc
|
var logOptionFuncs []config.LogOptionFunc
|
||||||
|
@@ -54,6 +54,8 @@ type MultusConf struct {
|
|||||||
ReadinessIndicatorFile string `json:"readinessindicatorfile,omitempty"`
|
ReadinessIndicatorFile string `json:"readinessindicatorfile,omitempty"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
CniDir string `json:"cniDir,omitempty"`
|
CniDir string `json:"cniDir,omitempty"`
|
||||||
|
CniConfigDir string `json:"cniConfigDir,omitempty"`
|
||||||
|
SocketDir string `json:"socketDir,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogOptions specifies the configuration of the log
|
// LogOptions specifies the configuration of the log
|
||||||
@@ -222,6 +224,23 @@ func WithCniDir(cniDir string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithCniConfigDir mutates the inner state to set the
|
||||||
|
// multus CNI configuration directory
|
||||||
|
func WithCniConfigDir(confDir string) Option {
|
||||||
|
return func(conf *MultusConf) error {
|
||||||
|
conf.CniConfigDir = confDir
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithSocketDir mutates the socket directory
|
||||||
|
func WithSocketDir(sockDir string) Option {
|
||||||
|
return func(conf *MultusConf) error {
|
||||||
|
conf.SocketDir = sockDir
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func withClusterNetwork(clusterNetwork string) Option {
|
func withClusterNetwork(clusterNetwork string) Option {
|
||||||
return func(conf *MultusConf) error {
|
return func(conf *MultusConf) error {
|
||||||
conf.ClusterNetwork = clusterNetwork
|
conf.ClusterNetwork = clusterNetwork
|
||||||
|
@@ -262,6 +262,44 @@ var _ = Describe("Configuration Generator", func() {
|
|||||||
Expect(multusConfig.Generate()).Should(MatchJSON(expectedResult))
|
Expect(multusConfig.Generate()).Should(MatchJSON(expectedResult))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("generates a multus config with CNI configuration directory", func() {
|
||||||
|
cniConfigDir := "/host/etc/cni/net.d"
|
||||||
|
multusConfig, err := newMultusConfigWithDelegates(
|
||||||
|
primaryCNIName,
|
||||||
|
cniVersion,
|
||||||
|
primaryCNIFile,
|
||||||
|
WithCniConfigDir(cniConfigDir))
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
expectedResult := fmt.Sprintf(`
|
||||||
|
{
|
||||||
|
"cniVersion":"0.4.0",
|
||||||
|
"clusterNetwork":"%s",
|
||||||
|
"name":"multus-cni-network",
|
||||||
|
"cniConfigDir":"/host/etc/cni/net.d",
|
||||||
|
"type":"myCNI"
|
||||||
|
}`, primaryCNIFile)
|
||||||
|
Expect(multusConfig.Generate()).Should(MatchJSON(expectedResult))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("generates a multus config with a custom socket directory", func() {
|
||||||
|
socketDir := "/var/run/multus/multussock/"
|
||||||
|
multusConfig, err := newMultusConfigWithDelegates(
|
||||||
|
primaryCNIName,
|
||||||
|
cniVersion,
|
||||||
|
primaryCNIFile,
|
||||||
|
WithSocketDir(socketDir))
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
expectedResult := fmt.Sprintf(`
|
||||||
|
{
|
||||||
|
"cniVersion":"0.4.0",
|
||||||
|
"clusterNetwork":"%s",
|
||||||
|
"name":"multus-cni-network",
|
||||||
|
"socketDir":"/var/run/multus/multussock/",
|
||||||
|
"type":"myCNI"
|
||||||
|
}`, primaryCNIFile)
|
||||||
|
Expect(multusConfig.Generate()).Should(MatchJSON(expectedResult))
|
||||||
|
})
|
||||||
|
|
||||||
It("multus config with global namespace", func() {
|
It("multus config with global namespace", func() {
|
||||||
const globalNamespace = "come-along-ns"
|
const globalNamespace = "come-along-ns"
|
||||||
multusConfig, err := newMultusConfigWithDelegates(
|
multusConfig, err := newMultusConfigWithDelegates(
|
||||||
|
@@ -42,8 +42,8 @@ type Manager struct {
|
|||||||
primaryCNIConfigPath string
|
primaryCNIConfigPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManager returns a config manager object, configured to persist the
|
// NewManager returns a config manager object, configured to read the
|
||||||
// configuration to `multusAutoconfigDir`. This constructor will auto-discover
|
// primary CNI configuration in `multusAutoconfigDir`. This constructor will auto-discover
|
||||||
// the primary CNI for which it will delegate.
|
// the primary CNI for which it will delegate.
|
||||||
func NewManager(config MultusConf, multusAutoconfigDir string, forceCNIVersion bool) (*Manager, error) {
|
func NewManager(config MultusConf, multusAutoconfigDir string, forceCNIVersion bool) (*Manager, error) {
|
||||||
defaultCNIPluginName, err := getPrimaryCNIPluginName(multusAutoconfigDir)
|
defaultCNIPluginName, err := getPrimaryCNIPluginName(multusAutoconfigDir)
|
||||||
@@ -108,7 +108,7 @@ func newManager(config MultusConf, multusConfigDir, defaultCNIPluginName string,
|
|||||||
configWatcher: watcher,
|
configWatcher: watcher,
|
||||||
multusConfig: &config,
|
multusConfig: &config,
|
||||||
multusConfigDir: multusConfigDir,
|
multusConfigDir: multusConfigDir,
|
||||||
multusConfigFilePath: cniPluginConfigFilePath(multusConfigDir, multusConfigFileName),
|
multusConfigFilePath: cniPluginConfigFilePath(config.CniConfigDir, multusConfigFileName),
|
||||||
primaryCNIConfigPath: cniPluginConfigFilePath(multusConfigDir, defaultCNIPluginName),
|
primaryCNIConfigPath: cniPluginConfigFilePath(multusConfigDir, defaultCNIPluginName),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,6 +217,7 @@ func (m Manager) MonitorPluginConfiguration(shutDown <-chan struct{}, done chan<
|
|||||||
// PersistMultusConfig persists the provided configuration to the disc, with
|
// PersistMultusConfig persists the provided configuration to the disc, with
|
||||||
// Read / Write permissions. The output file path is `<multus auto config dir>/00-multus.conf`
|
// Read / Write permissions. The output file path is `<multus auto config dir>/00-multus.conf`
|
||||||
func (m Manager) PersistMultusConfig(config string) error {
|
func (m Manager) PersistMultusConfig(config string) error {
|
||||||
|
logging.Debugf("Writing Multus CNI configuration @ %s", m.multusConfigFilePath)
|
||||||
return os.WriteFile(m.multusConfigFilePath, []byte(config), UserRWPermission)
|
return os.WriteFile(m.multusConfigFilePath, []byte(config), UserRWPermission)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user