mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-19 16:40:58 +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 = ""
|
||||
defaultMultusNamespaceIsolation = false
|
||||
defaultMultusReadinessIndicatorFile = ""
|
||||
defaultSocketDir = "/run/multus/"
|
||||
)
|
||||
|
||||
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")
|
||||
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.")
|
||||
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
|
||||
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")
|
||||
@@ -136,6 +138,12 @@ func main() {
|
||||
configurationOptions, config.WithReadinessFileIndicator(*readinessIndicator))
|
||||
}
|
||||
|
||||
configurationOptions = append(
|
||||
configurationOptions, config.WithCniConfigDir(*cniConfigDir))
|
||||
|
||||
configurationOptions = append(
|
||||
configurationOptions, config.WithSocketDir(*socketDir))
|
||||
|
||||
// logOptions
|
||||
|
||||
var logOptionFuncs []config.LogOptionFunc
|
||||
|
@@ -54,6 +54,8 @@ type MultusConf struct {
|
||||
ReadinessIndicatorFile string `json:"readinessindicatorfile,omitempty"`
|
||||
Type string `json:"type"`
|
||||
CniDir string `json:"cniDir,omitempty"`
|
||||
CniConfigDir string `json:"cniConfigDir,omitempty"`
|
||||
SocketDir string `json:"socketDir,omitempty"`
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return func(conf *MultusConf) error {
|
||||
conf.ClusterNetwork = clusterNetwork
|
||||
|
@@ -262,6 +262,44 @@ var _ = Describe("Configuration Generator", func() {
|
||||
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() {
|
||||
const globalNamespace = "come-along-ns"
|
||||
multusConfig, err := newMultusConfigWithDelegates(
|
||||
|
@@ -42,8 +42,8 @@ type Manager struct {
|
||||
primaryCNIConfigPath string
|
||||
}
|
||||
|
||||
// NewManager returns a config manager object, configured to persist the
|
||||
// configuration to `multusAutoconfigDir`. This constructor will auto-discover
|
||||
// NewManager returns a config manager object, configured to read the
|
||||
// primary CNI configuration in `multusAutoconfigDir`. This constructor will auto-discover
|
||||
// the primary CNI for which it will delegate.
|
||||
func NewManager(config MultusConf, multusAutoconfigDir string, forceCNIVersion bool) (*Manager, error) {
|
||||
defaultCNIPluginName, err := getPrimaryCNIPluginName(multusAutoconfigDir)
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
@@ -217,6 +217,7 @@ func (m Manager) MonitorPluginConfiguration(shutDown <-chan struct{}, done chan<
|
||||
// PersistMultusConfig persists the provided configuration to the disc, with
|
||||
// Read / Write permissions. The output file path is `<multus auto config dir>/00-multus.conf`
|
||||
func (m Manager) PersistMultusConfig(config string) error {
|
||||
logging.Debugf("Writing Multus CNI configuration @ %s", m.multusConfigFilePath)
|
||||
return os.WriteFile(m.multusConfigFilePath, []byte(config), UserRWPermission)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user