Have ipam.ExecDel set CNI_COMMAND to DEL
This commit is contained in:
parent
a03e6b505e
commit
02ccf1ef9b
@ -16,8 +16,10 @@ package ipam
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/containernetworking/cni/pkg/invoke"
|
"github.com/containernetworking/cni/pkg/invoke"
|
||||||
"github.com/containernetworking/cni/pkg/types"
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExecAdd(plugin string, netconf []byte) (types.Result, error) {
|
func ExecAdd(plugin string, netconf []byte) (types.Result, error) {
|
||||||
@ -29,5 +31,13 @@ func ExecCheck(plugin string, netconf []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ExecDel(plugin string, netconf []byte) error {
|
func ExecDel(plugin string, netconf []byte) error {
|
||||||
|
cmd := os.Getenv("CNI_COMMAND")
|
||||||
|
if cmd == "" {
|
||||||
|
return fmt.Errorf("environment variable CNI_COMMAND must be specified.")
|
||||||
|
}
|
||||||
|
// Set CNI_COMMAND to DEL explicity. We might be deleting due to an ADD gone wrong.
|
||||||
|
// restore CNI_COMMAND to original value upon return.
|
||||||
|
os.Setenv("CNI_COMMAND", "DEL")
|
||||||
|
defer os.Setenv("CNI_COMMAND", cmd)
|
||||||
return invoke.DelegateDel(context.TODO(), plugin, netconf, nil)
|
return invoke.DelegateDel(context.TODO(), plugin, netconf, nil)
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -415,9 +414,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
// release IP in case of failure
|
// release IP in case of failure
|
||||||
defer func() {
|
defer func() {
|
||||||
if !success {
|
if !success {
|
||||||
os.Setenv("CNI_COMMAND", "DEL")
|
|
||||||
ipam.ExecDel(n.IPAM.Type, args.StdinData)
|
ipam.ExecDel(n.IPAM.Type, args.StdinData)
|
||||||
os.Setenv("CNI_COMMAND", "ADD")
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -97,9 +96,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
// Invoke ipam del if err to avoid ip leak
|
// Invoke ipam del if err to avoid ip leak
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Setenv("CNI_COMMAND", "DEL")
|
|
||||||
ipam.ExecDel(cfg.IPAM.Type, args.StdinData)
|
ipam.ExecDel(cfg.IPAM.Type, args.StdinData)
|
||||||
os.Setenv("CNI_COMMAND", "ADD")
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -203,6 +203,14 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoke ipam del if err to avoid ip leak
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
ipam.ExecDel(n.IPAM.Type, args.StdinData)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Convert whatever the IPAM result was into the current Result type
|
// Convert whatever the IPAM result was into the current Result type
|
||||||
result, err = current.NewResultFromResult(r)
|
result, err = current.NewResultFromResult(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/j-keck/arping"
|
"github.com/j-keck/arping"
|
||||||
@ -227,9 +226,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
// Invoke ipam del if err to avoid ip leak
|
// Invoke ipam del if err to avoid ip leak
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Setenv("CNI_COMMAND", "DEL")
|
|
||||||
ipam.ExecDel(n.IPAM.Type, args.StdinData)
|
ipam.ExecDel(n.IPAM.Type, args.StdinData)
|
||||||
os.Setenv("CNI_COMMAND", "ADD")
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -200,6 +200,14 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoke ipam del if err to avoid ip leak
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
ipam.ExecDel(conf.IPAM.Type, args.StdinData)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Convert whatever the IPAM result was into the current Result type
|
// Convert whatever the IPAM result was into the current Result type
|
||||||
result, err := current.NewResultFromResult(r)
|
result, err := current.NewResultFromResult(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -140,6 +140,14 @@ func cmdAdd(args *skel.CmdArgs) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invoke ipam del if err to avoid ip leak
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
ipam.ExecDel(n.IPAM.Type, args.StdinData)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Convert whatever the IPAM result was into the current Result type
|
// Convert whatever the IPAM result was into the current Result type
|
||||||
result, err := current.NewResultFromResult(r)
|
result, err := current.NewResultFromResult(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user