summaryrefslogtreecommitdiff
path: root/vendor/github.com/containernetworking/cni/pkg/invoke/delegate.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/containernetworking/cni/pkg/invoke/delegate.go')
-rw-r--r--vendor/github.com/containernetworking/cni/pkg/invoke/delegate.go48
1 files changed, 24 insertions, 24 deletions
diff --git a/vendor/github.com/containernetworking/cni/pkg/invoke/delegate.go b/vendor/github.com/containernetworking/cni/pkg/invoke/delegate.go
index 21efdf802..30b4672f1 100644
--- a/vendor/github.com/containernetworking/cni/pkg/invoke/delegate.go
+++ b/vendor/github.com/containernetworking/cni/pkg/invoke/delegate.go
@@ -15,6 +15,7 @@
package invoke
import (
+ "context"
"fmt"
"os"
"path/filepath"
@@ -22,54 +23,53 @@ import (
"github.com/containernetworking/cni/pkg/types"
)
-func delegateAddOrGet(command, delegatePlugin string, netconf []byte, exec Exec) (types.Result, error) {
+func delegateCommon(expectedCommand, delegatePlugin string, exec Exec) (string, Exec, error) {
if exec == nil {
exec = defaultExec
}
+ if os.Getenv("CNI_COMMAND") != expectedCommand {
+ return "", nil, fmt.Errorf("CNI_COMMAND is not " + expectedCommand)
+ }
+
paths := filepath.SplitList(os.Getenv("CNI_PATH"))
pluginPath, err := exec.FindInPath(delegatePlugin, paths)
if err != nil {
- return nil, err
+ return "", nil, err
}
- return ExecPluginWithResult(pluginPath, netconf, ArgsFromEnv(), exec)
+ return pluginPath, exec, nil
}
// DelegateAdd calls the given delegate plugin with the CNI ADD action and
// JSON configuration
-func DelegateAdd(delegatePlugin string, netconf []byte, exec Exec) (types.Result, error) {
- if os.Getenv("CNI_COMMAND") != "ADD" {
- return nil, fmt.Errorf("CNI_COMMAND is not ADD")
+func DelegateAdd(ctx context.Context, delegatePlugin string, netconf []byte, exec Exec) (types.Result, error) {
+ pluginPath, realExec, err := delegateCommon("ADD", delegatePlugin, exec)
+ if err != nil {
+ return nil, err
}
- return delegateAddOrGet("ADD", delegatePlugin, netconf, exec)
+
+ return ExecPluginWithResult(ctx, pluginPath, netconf, ArgsFromEnv(), realExec)
}
-// DelegateGet calls the given delegate plugin with the CNI GET action and
+// DelegateCheck calls the given delegate plugin with the CNI CHECK action and
// JSON configuration
-func DelegateGet(delegatePlugin string, netconf []byte, exec Exec) (types.Result, error) {
- if os.Getenv("CNI_COMMAND") != "GET" {
- return nil, fmt.Errorf("CNI_COMMAND is not GET")
+func DelegateCheck(ctx context.Context, delegatePlugin string, netconf []byte, exec Exec) error {
+ pluginPath, realExec, err := delegateCommon("CHECK", delegatePlugin, exec)
+ if err != nil {
+ return err
}
- return delegateAddOrGet("GET", delegatePlugin, netconf, exec)
+
+ return ExecPluginWithoutResult(ctx, pluginPath, netconf, ArgsFromEnv(), realExec)
}
// DelegateDel calls the given delegate plugin with the CNI DEL action and
// JSON configuration
-func DelegateDel(delegatePlugin string, netconf []byte, exec Exec) error {
- if exec == nil {
- exec = defaultExec
- }
-
- if os.Getenv("CNI_COMMAND") != "DEL" {
- return fmt.Errorf("CNI_COMMAND is not DEL")
- }
-
- paths := filepath.SplitList(os.Getenv("CNI_PATH"))
- pluginPath, err := exec.FindInPath(delegatePlugin, paths)
+func DelegateDel(ctx context.Context, delegatePlugin string, netconf []byte, exec Exec) error {
+ pluginPath, realExec, err := delegateCommon("DEL", delegatePlugin, exec)
if err != nil {
return err
}
- return ExecPluginWithoutResult(pluginPath, netconf, ArgsFromEnv(), exec)
+ return ExecPluginWithoutResult(ctx, pluginPath, netconf, ArgsFromEnv(), realExec)
}