Skip to content

Commit

Permalink
fix multus config file generation to avoid self-delegation
Browse files Browse the repository at this point in the history
Add a check to make sure that we don't use an existing multus configuration file.
This avoids creating a situation where multus delegates to itself and breaks
pod networking by trying multiple times to create the same intefarce for a pod.

Signed-off-by: Thomas Ferrandiz <[email protected]>
  • Loading branch information
thomasferrandiz committed Aug 11, 2023
1 parent f037656 commit 4b973ea
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/thin_entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"regexp"
"strings"
"text/template"
"time"
Expand Down Expand Up @@ -294,7 +296,20 @@ func (o *Options) createMultusConfig() (string, error) {
return "", fmt.Errorf("cannot find master CNI config in %q: %v", o.MultusAutoconfigDir, err)
}

masterConfigPath := files[0]
var masterConfigPath string
// skip existing multus configuration file to avoid creating a situation
// where multus delegates to itself and breaks pod networking
multusRegexp, err := regexp.Compile("00-multus.conf{,list}")
if err != nil {
return "", fmt.Errorf("regexp compilation failed: %v", err)
}
for _, filename := range files {
if !multusRegexp.MatchString(path.Base(filename)) {
masterConfigPath = filename
break
}
}

masterConfigBytes, err := os.ReadFile(masterConfigPath)
if err != nil {
return "", fmt.Errorf("cannot read master CNI config file %q: %v", masterConfigPath, err)
Expand Down

0 comments on commit 4b973ea

Please sign in to comment.