plugins/meta/flannel: If net config is missing do not return err on DEL
authorAaron Levy <aaronjlevy@gmail.com>
Fri, 17 Mar 2017 01:46:39 +0000 (18:46 -0700)
committerAaron Levy <aaronjlevy@gmail.com>
Fri, 17 Mar 2017 20:37:33 +0000 (13:37 -0700)
plugins/meta/flannel/flannel.go
plugins/meta/flannel/flannel_test.go

index e1eb278..424e01b 100644 (file)
@@ -142,6 +142,7 @@ func saveScratchNetConf(containerID, dataDir string, netconf []byte) error {
 
 func consumeScratchNetConf(containerID, dataDir string) ([]byte, error) {
        path := filepath.Join(dataDir, containerID)
+       // Ignore errors when removing - Per spec safe to continue during DEL
        defer os.Remove(path)
 
        return ioutil.ReadFile(path)
@@ -245,6 +246,10 @@ func cmdDel(args *skel.CmdArgs) error {
 
        netconfBytes, err := consumeScratchNetConf(args.ContainerID, nc.DataDir)
        if err != nil {
+               if os.IsNotExist(err) {
+                       // Per spec should ignore error if resources are missing / already removed
+                       return nil
+               }
                return err
        }
 
index 51fdc6f..a4a8bc7 100644 (file)
@@ -140,6 +140,14 @@ FLANNEL_IPMASQ=true
 
                                By("check that plugin removes net config from state dir")
                                Expect(path).ShouldNot(BeAnExistingFile())
+
+                               By("calling DEL again")
+                               err = testutils.CmdDelWithResult(targetNs.Path(), IFNAME, func() error {
+                                       return cmdDel(args)
+                               })
+                               By("check that plugin does not fail due to missing net config")
+                               Expect(err).NotTo(HaveOccurred())
+
                                return nil
                        })
                        Expect(err).NotTo(HaveOccurred())