Add invoke.Delegate{Add,Del} for use by meta-plugins
The 'flannel' meta plugin delegates to other plugins to do the actual OS-level work. It used the ipam.Exec{Add,Del} procedures for this delegation, since those do precisely what's needed. However this is a bit misleading, since the flannel plugin _isn't_ doing this for IPAM, and the ipam.Exec* procedures aren't doing something specific to IPAM plugins. So: anticipating that there may be more meta plugins that want to delegate in the same way, this commit moves generic delegation procedures to `pkg/invoke`, and makes the `pkg/ipam` procedures (still used, accurately, in the non-meta plugins) shims.
This commit is contained in:
parent
36c6bcd106
commit
719a1db54b
39
pkg/invoke/delegate.go
Normal file
39
pkg/invoke/delegate.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package invoke
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/appc/cni/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DelegateAdd(delegatePlugin string, netconf []byte) (*types.Result, error) {
|
||||||
|
if os.Getenv("CNI_COMMAND") != "ADD" {
|
||||||
|
return nil, fmt.Errorf("CNI_COMMAND is not ADD")
|
||||||
|
}
|
||||||
|
|
||||||
|
paths := strings.Split(os.Getenv("CNI_PATH"), ":")
|
||||||
|
|
||||||
|
pluginPath, err := FindInPath(delegatePlugin, paths)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ExecPluginWithResult(pluginPath, netconf, ArgsFromEnv())
|
||||||
|
}
|
||||||
|
|
||||||
|
func DelegateDel(delegatePlugin string, netconf []byte) error {
|
||||||
|
if os.Getenv("CNI_COMMAND") != "DEL" {
|
||||||
|
return fmt.Errorf("CNI_COMMAND is not DEL")
|
||||||
|
}
|
||||||
|
|
||||||
|
paths := strings.Split(os.Getenv("CNI_PATH"), ":")
|
||||||
|
|
||||||
|
pluginPath, err := FindInPath(delegatePlugin, paths)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ExecPluginWithoutResult(pluginPath, netconf, ArgsFromEnv())
|
||||||
|
}
|
@ -17,7 +17,6 @@ package ipam
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/appc/cni/pkg/invoke"
|
"github.com/appc/cni/pkg/invoke"
|
||||||
"github.com/appc/cni/pkg/ip"
|
"github.com/appc/cni/pkg/ip"
|
||||||
@ -27,33 +26,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ExecAdd(plugin string, netconf []byte) (*types.Result, error) {
|
func ExecAdd(plugin string, netconf []byte) (*types.Result, error) {
|
||||||
if os.Getenv("CNI_COMMAND") != "ADD" {
|
return invoke.DelegateAdd(plugin, netconf)
|
||||||
return nil, fmt.Errorf("CNI_COMMAND is not ADD")
|
|
||||||
}
|
|
||||||
|
|
||||||
paths := strings.Split(os.Getenv("CNI_PATH"), ":")
|
|
||||||
|
|
||||||
pluginPath, err := invoke.FindInPath(plugin, paths)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return invoke.ExecPluginWithResult(pluginPath, netconf, invoke.ArgsFromEnv())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExecDel(plugin string, netconf []byte) error {
|
func ExecDel(plugin string, netconf []byte) error {
|
||||||
if os.Getenv("CNI_COMMAND") != "DEL" {
|
return invoke.DelegateDel(plugin, netconf)
|
||||||
return fmt.Errorf("CNI_COMMAND is not DEL")
|
|
||||||
}
|
|
||||||
|
|
||||||
paths := strings.Split(os.Getenv("CNI_PATH"), ":")
|
|
||||||
|
|
||||||
pluginPath, err := invoke.FindInPath(plugin, paths)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return invoke.ExecPluginWithoutResult(pluginPath, netconf, invoke.ArgsFromEnv())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigureIface takes the result of IPAM plugin and
|
// ConfigureIface takes the result of IPAM plugin and
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/appc/cni/pkg/ipam"
|
"github.com/appc/cni/pkg/invoke"
|
||||||
"github.com/appc/cni/pkg/skel"
|
"github.com/appc/cni/pkg/skel"
|
||||||
"github.com/appc/cni/pkg/types"
|
"github.com/appc/cni/pkg/types"
|
||||||
)
|
)
|
||||||
@ -155,7 +155,7 @@ func delegateAdd(cid string, netconf map[string]interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := ipam.ExecAdd(netconf["type"].(string), netconfBytes)
|
result, err := invoke.DelegateAdd(netconf["type"].(string), netconfBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ func cmdDel(args *skel.CmdArgs) error {
|
|||||||
return fmt.Errorf("failed to parse netconf: %v", err)
|
return fmt.Errorf("failed to parse netconf: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ipam.ExecDel(n.Type, netconfBytes)
|
return invoke.DelegateDel(n.Type, netconfBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user