Skip to content

Commit 62b1808

Browse files
author
Skyler Clark
committed
fixes log level, and adds a few tests
Signed-off-by: Skyler Clark <[email protected]>
1 parent 5243a9f commit 62b1808

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

pkg/ocicni/ocicni.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (plugin *cniNetworkPlugin) podUnlock(podNetwork PodNetwork) {
102102
fullPodName := buildFullPodName(podNetwork)
103103
lock, ok := plugin.pods[fullPodName]
104104
if !ok {
105-
logrus.Warningf("Unbalanced pod lock unref for %s", fullPodName)
105+
logrus.Errorf("Cannot find reference in refcount map for %s. Refcount cannot be determined.", fullPodName)
106106
return
107107
} else if lock.refcount == 0 {
108108
// This should never ever happen, but handle it anyway
@@ -121,12 +121,12 @@ func newWatcher(confDir string) (*fsnotify.Watcher, error) {
121121
// Ensure plugin directory exists, because the following monitoring logic
122122
// relies on that.
123123
if err := os.MkdirAll(confDir, 0755); err != nil {
124-
return nil, fmt.Errorf("failed to create %q: %v", confDir, err)
124+
return nil, fmt.Errorf("failed to create directory %q: %v", confDir, err)
125125
}
126126

127127
watcher, err := fsnotify.NewWatcher()
128128
if err != nil {
129-
return nil, fmt.Errorf("could not create new watcher %v", err)
129+
return nil, fmt.Errorf("failed to create new watcher %v", err)
130130
}
131131
defer func() {
132132
// Close watcher on error
@@ -275,13 +275,13 @@ func loadNetworks(confDir string, cni *libcni.CNIConfig) (map[string]*cniNetwork
275275
if strings.HasSuffix(confFile, ".conflist") {
276276
confList, err = libcni.ConfListFromFile(confFile)
277277
if err != nil {
278-
logrus.Warningf("Error loading CNI config list file %s: %v", confFile, err)
278+
logrus.Errorf("Error loading CNI config list file %s: %v", confFile, err)
279279
continue
280280
}
281281
} else {
282282
conf, err := libcni.ConfFromFile(confFile)
283283
if err != nil {
284-
logrus.Warningf("Error loading CNI config file %s: %v", confFile, err)
284+
logrus.Errorf("Error loading CNI config file %s: %v", confFile, err)
285285
continue
286286
}
287287
if conf.Network.Type == "" {
@@ -290,7 +290,7 @@ func loadNetworks(confDir string, cni *libcni.CNIConfig) (map[string]*cniNetwork
290290
}
291291
confList, err = libcni.ConfListFromConf(conf)
292292
if err != nil {
293-
logrus.Warningf("Error converting CNI config file %s to list: %v", confFile, err)
293+
logrus.Errorf("Error converting CNI config file %s to list: %v", confFile, err)
294294
continue
295295
}
296296
}
@@ -321,7 +321,7 @@ func loadNetworks(confDir string, cni *libcni.CNIConfig) (map[string]*cniNetwork
321321
if _, ok := networks[confList.Name]; !ok {
322322
networks[confList.Name] = cniNet
323323
} else {
324-
logrus.Infof("Ignore CNI network %s (type=%v) at %s because already exists", confList.Name, confList.Plugins[0].Network.Type, confFile)
324+
logrus.Infof("Ignored CNI network %s (type=%v) at %s because already exists", confList.Name, confList.Plugins[0].Network.Type, confFile)
325325
}
326326

327327
if defaultNetName == "" {
@@ -348,7 +348,7 @@ func (plugin *cniNetworkPlugin) syncNetworkConfig() error {
348348
// Update defaultNetName if it is changeable
349349
if plugin.defaultNetName.changeable {
350350
plugin.defaultNetName.name = defaultNetName
351-
logrus.Infof("Update default CNI network name to %s", defaultNetName)
351+
logrus.Infof("Updated default CNI network name to %s", defaultNetName)
352352
} else {
353353
logrus.Debugf("Default CNI network name %s is unchangeable", plugin.defaultNetName.name)
354354
}
@@ -479,8 +479,8 @@ func (plugin *cniNetworkPlugin) forEachNetwork(podNetwork *PodNetwork, fromCache
479479
var newRt *libcni.RuntimeConf
480480
cniNet, newRt, err = plugin.loadNetworkFromCache(network.Name, rt)
481481
if err != nil {
482-
logrus.Debugf("error loading cached network config: %v", err)
483-
logrus.Debugf("falling back to loading from existing plugins on disk")
482+
logrus.Errorf("error loading cached network config: %v", err)
483+
logrus.Warningf("falling back to loading from existing plugins on disk")
484484
} else {
485485
// Use the updated RuntimeConf
486486
rt = newRt
@@ -570,7 +570,7 @@ func (plugin *cniNetworkPlugin) getCachedNetworkInfo(containerID string) ([]NetA
570570
cacheFile := filepath.Join(dirPath, fname)
571571
bytes, err := ioutil.ReadFile(cacheFile)
572572
if err != nil {
573-
logrus.Warningf("failed to read CNI cache file %s: %v", cacheFile, err)
573+
logrus.Errorf("failed to read CNI cache file %s: %v", cacheFile, err)
574574
continue
575575
}
576576

@@ -582,7 +582,7 @@ func (plugin *cniNetworkPlugin) getCachedNetworkInfo(containerID string) ([]NetA
582582
}{}
583583

584584
if err := json.Unmarshal(bytes, &cachedInfo); err != nil {
585-
logrus.Warningf("failed to unmarshal CNI cache file %s: %v", cacheFile, err)
585+
logrus.Errorf("failed to unmarshal CNI cache file %s: %v", cacheFile, err)
586586
continue
587587
}
588588
if cachedInfo.Kind != libcni.CNICacheV1 {
@@ -632,7 +632,7 @@ func (plugin *cniNetworkPlugin) TearDownPodWithContext(ctx context.Context, podN
632632

633633
if err := tearDownLoopback(podNetwork.NetNS); err != nil {
634634
// ignore error
635-
logrus.Errorf("Ignoring error tearing down loopback interface: %v", err)
635+
logrus.Warningf("Ignoring error tearing down loopback interface: %v", err)
636636
}
637637

638638
return plugin.forEachNetwork(&podNetwork, true, func(network *cniNetwork, podNetwork *PodNetwork, rt *libcni.RuntimeConf) error {
@@ -718,7 +718,7 @@ func (network *cniNetwork) checkNetwork(ctx context.Context, rt *libcni.RuntimeC
718718

719719
result, err = cni.GetNetworkListCachedResult(network.config, rt)
720720
if err != nil {
721-
logrus.Errorf("Error GetNetworkListCachedResult: %v", err)
721+
logrus.Errorf("Error getting network list cached result: %v", err)
722722
return nil, err
723723
} else if result != nil {
724724
return result, nil
@@ -771,7 +771,7 @@ func (network *cniNetwork) checkNetwork(ctx context.Context, rt *libcni.RuntimeC
771771
func (network *cniNetwork) deleteFromNetwork(ctx context.Context, rt *libcni.RuntimeConf, cni *libcni.CNIConfig) error {
772772
logrus.Infof("About to del CNI network %s (type=%v)", network.name, network.config.Plugins[0].Network.Type)
773773
if err := cni.DelNetworkList(ctx, network.config, rt); err != nil {
774-
logrus.Errorf("Error deleting network: %v", err)
774+
logrus.Errorf("Error deleting network %s: %v", network.name, err)
775775
return err
776776
}
777777
return nil

pkg/ocicni/ocicni_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,19 @@ var _ = Describe("ocicni operations", func() {
758758
Expect(err).NotTo(HaveOccurred())
759759
Expect(fake.delIndex).To(Equal(len(fake.plugins)))
760760
})
761+
It("verifies that network operations can be locked for a pod using cached networks", func() {
762+
podNet.Networks = []NetAttachment{}
763+
tmp := ocicni.(*cniNetworkPlugin)
764+
Expect(len(tmp.pods)).To(Equal(0))
765+
tmp.podLock(podNet)
766+
Expect(len(tmp.pods)).To(Equal(1))
767+
})
768+
It("verifies that network operations can be unlocked for a pod using cached networks", func() {
769+
podNet.Networks = []NetAttachment{}
770+
tmp := ocicni.(*cniNetworkPlugin)
771+
tmp.podUnlock(podNet)
772+
Expect(len(tmp.pods)).To(Equal(0))
773+
})
761774
})
762775

763776
It("tears down a pod using specified networks when cached info is missing", func() {

0 commit comments

Comments
 (0)