Skip to content

Commit

Permalink
Log events only related to a valid CNI configuration file.
Browse files Browse the repository at this point in the history
Logs only .conf, .json and .conflist files.

Signed-off-by: roman-kiselenko <[email protected]>
  • Loading branch information
roman-kiselenko committed Nov 9, 2024
1 parent 94d9529 commit 0cfe056
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/ocicni/ocicni.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/sirupsen/logrus"
)

var cniConfigExtensions = []string{".conf", ".conflist", ".json"}

Check failure on line 25 in pkg/ocicni/ocicni.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

cniConfigExtensions is a global variable (gochecknoglobals)

type cniNetworkPlugin struct {
cniConfig *libcni.CNIConfig

Expand Down Expand Up @@ -155,10 +157,16 @@ func (plugin *cniNetworkPlugin) monitorConfDir(ctx context.Context, start *sync.
start.Done()
plugin.done.Add(1)
defer plugin.done.Done()
exts := map[string]bool{}
for _, ext := range cniConfigExtensions {
exts[ext] = true
}
for {
select {
case event := <-plugin.watcher.Events:
logrus.Infof("CNI monitoring event %v", event)
if exts[filepath.Ext(event.Name)] {
logrus.Infof("CNI monitoring event %v", event)
}

var defaultDeleted bool
createWriteRename := event.Op&fsnotify.Create == fsnotify.Create ||
Expand Down Expand Up @@ -287,7 +295,7 @@ func (plugin *cniNetworkPlugin) Shutdown() error {
}

func loadNetworks(ctx context.Context, confDir string, cni *libcni.CNIConfig) (networks map[string]*cniNetwork, defaultNetName string, err error) {
files, err := libcni.ConfFiles(confDir, []string{".conf", ".conflist", ".json"})
files, err := libcni.ConfFiles(confDir, cniConfigExtensions)
if err != nil {
return nil, "", err
}
Expand Down

0 comments on commit 0cfe056

Please sign in to comment.