fix bug on ipam revert if cmdAdd fails on macvlan and host-device

This commit is contained in:
Bruce Ma 2019-04-18 21:16:29 +08:00
parent 7df5acee0f
commit 214bcb8c8b
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")
}
}()