Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions control-plane/subcommand/install-cni/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (
)

// copyFile copies a file from a source directory to a destination directory.
func copyFile(srcFile, destDir string) error {
func copyFile(srcFile, destDir, filename string) error {
// If the src file does not exist then either the incorrect command line argument was used or
// the docker container we built is broken somehow.
if _, err := os.Stat(srcFile); os.IsNotExist(err) {
return err
}

filename := filepath.Base(srcFile)
if filename == "" {
filename = filepath.Base(srcFile)
}
// If the destDir does not exist then the incorrect command line argument was used or
// the CNI settings for the kubelet are not correct.
info, err := os.Stat(destDir)
Expand Down
6 changes: 3 additions & 3 deletions control-plane/subcommand/install-cni/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestCopyFile(t *testing.T) {
name: "cannot read source file",
srcFile: func() string {
tempDir := t.TempDir()
err := copyFile("testdata/10-kindnet.conflist", tempDir)
err := copyFile("testdata/10-kindnet.conflist", tempDir, "")
require.NoError(t, err)
filepath := filepath.Join(tempDir, "10-kindnet.conflist")
os.Chmod(filepath, 0111)
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestCopyFile(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
destDir := c.dir()
srcFile := c.srcFile()
actualErr := copyFile(srcFile, destDir)
actualErr := copyFile(srcFile, destDir, "")

expErr := c.expectedErr(srcFile, destDir)

Expand All @@ -133,7 +133,7 @@ func TestRemoveFile(t *testing.T) {
name: "can remove file",
srcFile: func() string {
tempDir := t.TempDir()
err := copyFile("testdata/10-kindnet.conflist", tempDir)
err := copyFile("testdata/10-kindnet.conflist", tempDir, "")
require.NoError(t, err)
filepath := filepath.Join(tempDir, "10-kindnet.conflist")
return filepath
Expand Down
2 changes: 1 addition & 1 deletion control-plane/subcommand/install-cni/cniconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func validConfig(cfg *config.CNIConfig, cfgFile string) error {
if !ok {
return fmt.Errorf("error reading plugin from plugin list")
}
if plugin["type"] == consulCNIName {
if plugin["type"] == cfg.Type {
// Populate existingCfg with the consul-cni plugin info so that we can compare it with what
// is expected.
err := mapstructure.Decode(plugin, &existingCfg)
Expand Down
25 changes: 14 additions & 11 deletions control-plane/subcommand/install-cni/cniconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestDefaultCNIConfigFile(t *testing.T) {
cfgFile: "testdata/10-kindnet.conflist",
dir: func(cfgFile string) string {
tempDir := t.TempDir()
err := copyFile(cfgFile, tempDir)
err := copyFile(cfgFile, tempDir, "")
if err != nil {
t.Fatal(err)
}
Expand All @@ -54,11 +54,11 @@ func TestDefaultCNIConfigFile(t *testing.T) {
cfgFile: "testdata/10-kindnet.conflist",
dir: func(cfgFile string) string {
tempDir := t.TempDir()
err := copyFile(cfgFile, tempDir)
err := copyFile(cfgFile, tempDir, "")
if err != nil {
t.Fatal(err)
}
err = copyFile("testdata/10-fake-cni.conf", tempDir)
err = copyFile("testdata/10-fake-cni.conf", tempDir, "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestConfListFromConfFile(t *testing.T) {
expectedCfgFile := "testdata/00-chained-plugins.conflist"

tempDir := t.TempDir()
err := copyFile(cfgFile, tempDir)
err := copyFile(cfgFile, tempDir, "")
require.NoError(t, err)

filename := filepath.Base(cfgFile)
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestAppendCNIConfig(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
// Copy the config file to a temporary location so that we can append to it.
tempDir := t.TempDir()
err := copyFile(c.cfgFile, tempDir)
err := copyFile(c.cfgFile, tempDir, "")
require.NoError(t, err)

// Get the config file name in the tempdir.
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestConfigFileToMap(t *testing.T) {
}

tempDir := t.TempDir()
err := copyFile(cfgFile, tempDir)
err := copyFile(cfgFile, tempDir, "")
require.NoError(t, err)

filename := filepath.Base(cfgFile)
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestRemoveCNIConfig(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
// copy the config file to a temporary location so that we can append to it
tempDir := t.TempDir()
err := copyFile(c.goldenFile, tempDir)
err := copyFile(c.goldenFile, tempDir, "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -336,17 +336,20 @@ func TestValidConfig(t *testing.T) {
expectedErr: fmt.Errorf("consul-cni config missing from config file"),
},
{
name: "config passed to installer does not match config in config file",
cfgFile: "testdata/10-kindnet.conflist.golden",
consulConfig: &config.CNIConfig{},
expectedErr: fmt.Errorf("consul-cni config has changed"),
name: "config passed to installer does not match config in config file",
cfgFile: "testdata/10-kindnet.conflist.golden",
consulConfig: &config.CNIConfig{
Type: consulCNIName,
},
expectedErr: fmt.Errorf("consul-cni config has changed"),
},
{
name: "config passed to installer does not match config in config file",
cfgFile: "testdata/10-kindnet.conflist.golden",
consulConfig: &config.CNIConfig{
CNIBinDir: "foo",
CNINetDir: "bar",
Type: consulCNIName,
},
expectedErr: fmt.Errorf("consul-cni config has changed"),
},
Expand Down
Loading
Loading