
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.
40 lines
841 B
Go
40 lines
841 B
Go
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())
|
|
}
|