Skip to content

Commit

Permalink
Merge pull request #407 from aaronlevy/del-err
Browse files Browse the repository at this point in the history
plugins/meta/flannel: If net config is missing do not return err on DEL
  • Loading branch information
tomdee authored Mar 21, 2017
2 parents b871263 + 74d4cbe commit 699380d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/meta/flannel/flannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions plugins/meta/flannel/flannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 699380d

Please sign in to comment.