mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-19 16:40:58 +00:00
thick, config regen, test: fix test
The test was just checking that a READ/WRITE fsnotify.Event for the multus configuration was being seen; this patch changes this behavior, and assures that the delegateCNI configuration update results in turn on the update of the multus configuration file. Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
This commit is contained in:
@@ -35,7 +35,7 @@ const (
|
|||||||
// Manager monitors the configuration of the primary CNI plugin, and
|
// Manager monitors the configuration of the primary CNI plugin, and
|
||||||
// regenerates multus configuration whenever it gets updated.
|
// regenerates multus configuration whenever it gets updated.
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
cniConfigData map[string]interface{}
|
cniConfigData map[string]interface{}
|
||||||
configWatcher *fsnotify.Watcher
|
configWatcher *fsnotify.Watcher
|
||||||
multusConfig *MultusConf
|
multusConfig *MultusConf
|
||||||
multusConfigDir string
|
multusConfigDir string
|
||||||
@@ -155,6 +155,9 @@ func (m Manager) MonitorDelegatedPluginConfiguration(shutDown chan struct{}, don
|
|||||||
if err := m.PersistMultusConfig(updatedConfig); err != nil {
|
if err := m.PersistMultusConfig(updatedConfig); err != nil {
|
||||||
_ = logging.Errorf("failed to persist the multus configuration: %v", err)
|
_ = logging.Errorf("failed to persist the multus configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
if err := m.loadPrimaryCNIConfigFromFile(); err != nil {
|
||||||
|
_ = logging.Errorf("failed to reload the updated config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
case err := <-m.configWatcher.Errors:
|
case err := <-m.configWatcher.Errors:
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@@ -16,18 +16,13 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/onsi/gomega/format"
|
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const suiteName = "Configuration Manager"
|
const suiteName = "Configuration Manager"
|
||||||
@@ -53,7 +48,7 @@ var _ = Describe(suiteName, func() {
|
|||||||
|
|
||||||
var configManager *Manager
|
var configManager *Manager
|
||||||
var multusConfigDir string
|
var multusConfigDir string
|
||||||
var multusConfigFilePath string
|
var defaultCniConfig string
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
var err error
|
var err error
|
||||||
@@ -63,9 +58,8 @@ var _ = Describe(suiteName, func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
format.TruncatedDiff = false
|
defaultCniConfig = fmt.Sprintf("%s/%s", multusConfigDir, primaryCNIPluginName)
|
||||||
multusConfigFilePath = fmt.Sprintf("%s/%s", multusConfigDir, primaryCNIPluginName)
|
Expect(ioutil.WriteFile(defaultCniConfig, []byte(primaryCNIPluginTemplate), userRWPermission)).To(Succeed())
|
||||||
Expect(ioutil.WriteFile(multusConfigFilePath, []byte(primaryCNIPluginTemplate), userRWPermission)).To(Succeed())
|
|
||||||
|
|
||||||
multusConf := NewMultusConfig(
|
multusConf := NewMultusConfig(
|
||||||
primaryCNIName,
|
primaryCNIName,
|
||||||
@@ -87,28 +81,37 @@ var _ = Describe(suiteName, func() {
|
|||||||
Expect(config).To(Equal(expectedResult))
|
Expect(config).To(Equal(expectedResult))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("Reacts to updates of the delegated CNI configuration", func() {
|
Context("Updates to the delegate CNI configuration", func() {
|
||||||
stopChan := make(chan struct{})
|
var (
|
||||||
doneChan := make(chan struct{})
|
doneChannel chan struct{}
|
||||||
go func(stopChannel, doneChan chan struct{}) {
|
stopChannel chan struct{}
|
||||||
Expect(configManager.MonitorDelegatedPluginConfiguration(stopChannel, doneChan)).To(Succeed())
|
)
|
||||||
}(stopChan, doneChan)
|
|
||||||
|
|
||||||
newCNIConfig := "{\"cniVersion\":\"0.4.0\",\"dns\":{},\"ipam\":{},\"name\":\"mycni-name\",\"type\":\"mycni\"}"
|
BeforeEach(func() {
|
||||||
Expect(ioutil.WriteFile(multusConfigFilePath, []byte(newCNIConfig), userRWPermission)).To(Succeed())
|
doneChannel = make(chan struct{})
|
||||||
Eventually(<-configManager.configWatcher.Events, time.Second).Should(Equal(
|
stopChannel = make(chan struct{})
|
||||||
fsnotify.Event{
|
go func() {
|
||||||
Name: multusConfigFilePath,
|
Expect(configManager.MonitorDelegatedPluginConfiguration(stopChannel, doneChannel)).To(Succeed())
|
||||||
Op: fsnotify.Write,
|
}()
|
||||||
}))
|
})
|
||||||
|
|
||||||
bytes, err := json.Marshal(configManager.cniConfigData)
|
AfterEach(func() {
|
||||||
Expect(err).NotTo(HaveOccurred())
|
go func() { stopChannel <- struct{}{} }()
|
||||||
Expect(string(bytes)).To(Equal(newCNIConfig))
|
Eventually(<-doneChannel).Should(Equal(struct{}{}))
|
||||||
|
close(doneChannel)
|
||||||
|
close(stopChannel)
|
||||||
|
})
|
||||||
|
|
||||||
// cleanup the watcher
|
It("Trigger the re-generation of the Multus CNI configuration", func() {
|
||||||
go func() { stopChan <- struct{}{} }()
|
newCNIConfig := "{\"cniVersion\":\"0.4.0\",\"dns\":{},\"ipam\":{},\"name\":\"yoyo-newnet\",\"type\":\"mycni\"}"
|
||||||
Eventually(<-doneChan, time.Second).Should(Equal(struct{}{}))
|
Expect(ioutil.WriteFile(defaultCniConfig, []byte(newCNIConfig), userRWPermission)).To(Succeed())
|
||||||
|
|
||||||
|
multusCniConfigFile := fmt.Sprintf("%s/%s", multusConfigDir, multusConfigFileName)
|
||||||
|
Eventually(func() (string, error) {
|
||||||
|
multusCniData, err := ioutil.ReadFile(multusCniConfigFile)
|
||||||
|
return string(multusCniData), err
|
||||||
|
}).Should(Equal(multusConfigFromDelegate(newCNIConfig)))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
When("the user requests the name of the multus configuration to be overridden", func() {
|
When("the user requests the name of the multus configuration to be overridden", func() {
|
||||||
@@ -124,3 +127,7 @@ var _ = Describe(suiteName, func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
func multusConfigFromDelegate(delegateConfig string) string {
|
||||||
|
return fmt.Sprintf("{\"cniVersion\":\"0.4.0\",\"delegates\":[%s],\"kubeconfig\":\"/a/b/c/kubeconfig.kubeconfig\",\"name\":\"multus-cni-network\",\"type\":\"myCNI\"}", delegateConfig)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user