Skip to content

Commit f806f7b

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

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

pkg/ocicni/ocicni.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ func loadNetworks(confDir string, cni *libcni.CNIConfig) (map[string]*cniNetwork
278278
if strings.HasSuffix(confFile, ".conflist") {
279279
confList, err = libcni.ConfListFromFile(confFile)
280280
if err != nil {
281-
logrus.Warningf("Error loading CNI config list file %s: %v", confFile, err)
281+
logrus.Errorf("Error loading CNI config list file %s: %v", confFile, err)
282282
continue
283283
}
284284
} else {
285285
conf, err := libcni.ConfFromFile(confFile)
286286
if err != nil {
287-
logrus.Warningf("Error loading CNI config file %s: %v", confFile, err)
287+
logrus.Errorf("Error loading CNI config file %s: %v", confFile, err)
288288
continue
289289
}
290290
if conf.Network.Type == "" {
@@ -293,7 +293,7 @@ func loadNetworks(confDir string, cni *libcni.CNIConfig) (map[string]*cniNetwork
293293
}
294294
confList, err = libcni.ConfListFromConf(conf)
295295
if err != nil {
296-
logrus.Warningf("Error converting CNI config file %s to list: %v", confFile, err)
296+
logrus.Errorf("Error converting CNI config file %s to list: %v", confFile, err)
297297
continue
298298
}
299299
}
@@ -482,8 +482,8 @@ func (plugin *cniNetworkPlugin) forEachNetwork(podNetwork *PodNetwork, fromCache
482482
var newRt *libcni.RuntimeConf
483483
cniNet, newRt, err = plugin.loadNetworkFromCache(network.Name, rt)
484484
if err != nil {
485-
logrus.Debugf("error loading cached network config: %v", err)
486-
logrus.Debugf("falling back to loading from existing plugins on disk")
485+
logrus.Errorf("error loading cached network config: %v", err)
486+
logrus.Warnf("falling back to loading from existing plugins on disk")
487487
} else {
488488
// Use the updated RuntimeConf
489489
rt = newRt
@@ -519,7 +519,7 @@ func bringUpLoopback(netns string) error {
519519
return err
520520
}
521521
if len(v4Addrs) != 0 {
522-
// sanity check that this is a loopback address
522+
// check that this is a loopback address
523523
for _, addr := range v4Addrs {
524524
if !addr.IP.IsLoopback() {
525525
return fmt.Errorf("loopback interface found with non-loopback address %q", addr.IP)
@@ -532,7 +532,7 @@ func bringUpLoopback(netns string) error {
532532
return err
533533
}
534534
if len(v6Addrs) != 0 {
535-
// sanity check that this is a loopback address
535+
// check that this is a loopback address
536536
for _, addr := range v6Addrs {
537537
if !addr.IP.IsLoopback() {
538538
return fmt.Errorf("loopback interface found with non-loopback address %q", addr.IP)
@@ -616,7 +616,7 @@ func (plugin *cniNetworkPlugin) getCachedNetworkInfo(containerID string) ([]NetA
616616
cacheFile := filepath.Join(dirPath, fname)
617617
bytes, err := ioutil.ReadFile(cacheFile)
618618
if err != nil {
619-
logrus.Warningf("failed to read CNI cache file %s: %v", cacheFile, err)
619+
logrus.Errorf("failed to read CNI cache file %s: %v", cacheFile, err)
620620
continue
621621
}
622622

@@ -628,7 +628,7 @@ func (plugin *cniNetworkPlugin) getCachedNetworkInfo(containerID string) ([]NetA
628628
}{}
629629

630630
if err := json.Unmarshal(bytes, &cachedInfo); err != nil {
631-
logrus.Warningf("failed to unmarshal CNI cache file %s: %v", cacheFile, err)
631+
logrus.Errorf("failed to unmarshal CNI cache file %s: %v", cacheFile, err)
632632
continue
633633
}
634634
if cachedInfo.Kind != libcni.CNICacheV1 {

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)