Merge pull request #301 from mars1024/bugfix/ipam_revert

fix bug on ip revert if cmdAdd fails on macvlan and host-device
This commit is contained in:
Dan Williams 2019-04-24 10:36:40 -05:00 committed by GitHub
commit 827a4bd843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
"runtime"
"strings"
@ -96,7 +97,9 @@ func cmdAdd(args *skel.CmdArgs) error {
// Invoke ipam del if err to avoid ip leak
defer func() {
if err != nil {
os.Setenv("CNI_COMMAND", "DEL")
ipam.ExecDel(cfg.IPAM.Type, args.StdinData)
os.Setenv("CNI_COMMAND", "ADD")
}
}()

View File

@ -19,6 +19,7 @@ import (
"errors"
"fmt"
"net"
"os"
"runtime"
"github.com/j-keck/arping"
@ -197,7 +198,9 @@ func cmdAdd(args *skel.CmdArgs) error {
// Invoke ipam del if err to avoid ip leak
defer func() {
if err != nil {
os.Setenv("CNI_COMMAND", "DEL")
ipam.ExecDel(n.IPAM.Type, args.StdinData)
os.Setenv("CNI_COMMAND", "ADD")
}
}()