Skip to content

Commit

Permalink
Allow plugins to read CNI 1.0.0 configs.
Browse files Browse the repository at this point in the history
Signed-off-by: Nashwan Azhari <nazhari@cloudbasesolutions.com>
  • Loading branch information
aznashwan committed Dec 12, 2023
1 parent a84e202 commit e37ce88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (

const (
// CNI commands.
CmdAdd = "ADD"
CmdDel = "DEL"
CmdAdd = "ADD"
CmdDel = "DEL"
CmdCheck = "CHECK"

Internal = "internal"
)

// Supported CNI versions.
var VersionsSupported = []string{"0.2.0", "0.3.0"}
var VersionsSupported = []string{"0.2.0", "0.3.0", "1.0.0"}

type KVP struct {
Name string `json:"name"`
Expand Down Expand Up @@ -126,21 +127,26 @@ func (r *Result) String() string {
type PluginApi interface {
Add(args *cniSkel.CmdArgs) error
Delete(args *cniSkel.CmdArgs) error
Check(args *cniSkel.CmdArgs) error
}

// CallPlugin calls the given CNI plugin through the internal interface.
func CallPlugin(plugin PluginApi, cmd string, args *cniSkel.CmdArgs, config *NetworkConfig) (*cniTypes.Result, error) {
var err error

savedType := config.Ipam.Type
config.Ipam.Type = Internal
args.StdinData = config.Serialize()

// Call the plugin's internal interface.
if cmd == CmdAdd {
var err error
switch cmd {
case CmdAdd:
err = plugin.Add(args)
} else {
case CmdDel:
err = plugin.Delete(args)
case CmdCheck:
err = plugin.Check(args)
default:
err = fmt.Errorf("Called with unknown CNI verb %q", cmd)
}

config.Ipam.Type = savedType
Expand Down
10 changes: 10 additions & 0 deletions common/core/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,13 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {
logrus.Debugf("[cni-net] DEL succeeded.")
return nil
}

// Check handles CNI CHECK commands.
// args.ContainerID - ID of the container for which network endpoint is to be checked.
// args.Netns - Network Namespace Id (required).
// args.IfName - Interface Name specifies the interface the network should bind to (ex: Ethernet).
// args.Path - Location of the config file.
func (plugin *netPlugin) Check(args *cniSkel.CmdArgs) error {
logrus.Warnf("[cni-net] CHECK is currently NOT implemented! Called with args: %v", args)
return nil
}

0 comments on commit e37ce88

Please sign in to comment.