Skip to content

Commit

Permalink
Merge branch 'main' into bleggett/multi-dir-pluginconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
bleggett authored Apr 22, 2024
2 parents 2d76833 + df52e94 commit bf23ebc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

## Version

This is CNI **spec** version **1.1.0-dev**.
This is CNI **spec** version **1.1.0**.

Note that this is **independent from the version of the CNI library and plugins** in this repository (e.g. the versions of [releases](https://github.com/containernetworking/cni/releases)).

Expand Down
Binary file added cnitool/cnitool
Binary file not shown.
23 changes: 16 additions & 7 deletions cnitool/cnitool.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ const (

DefaultNetDir = "/etc/cni/net.d"

CmdAdd = "add"
CmdCheck = "check"
CmdDel = "del"
CmdAdd = "add"
CmdCheck = "check"
CmdDel = "del"
CmdGC = "gc"
CmdStatus = "status"
)

func parseArgs(args string) ([][2]string, error) {
Expand Down Expand Up @@ -125,16 +127,23 @@ func main() {
exit(err)
case CmdDel:
exit(cninet.DelNetworkList(context.TODO(), netconf, rt))
case CmdGC:
// Currently just invoke GC without args, hence all network interface should be GC'ed!
exit(cninet.GCNetworkList(context.TODO(), netconf, nil))
case CmdStatus:
exit(cninet.GetStatusNetworkList(context.TODO(), netconf))
}
}

func usage() {
exe := filepath.Base(os.Args[0])

fmt.Fprintf(os.Stderr, "%s: Add, check, or remove network interfaces from a network namespace\n", exe)
fmt.Fprintf(os.Stderr, " %s add <net> <netns>\n", exe)
fmt.Fprintf(os.Stderr, " %s check <net> <netns>\n", exe)
fmt.Fprintf(os.Stderr, " %s del <net> <netns>\n", exe)
fmt.Fprintf(os.Stderr, "%s: Add, check, remove, gc or status network interfaces from a network namespace\n", exe)
fmt.Fprintf(os.Stderr, " %s add <net> <netns>\n", exe)
fmt.Fprintf(os.Stderr, " %s check <net> <netns>\n", exe)
fmt.Fprintf(os.Stderr, " %s del <net> <netns>\n", exe)
fmt.Fprintf(os.Stderr, " %s gc <net> <netns>\n", exe)
fmt.Fprintf(os.Stderr, " %s status <net> <netns>\n", exe)
os.Exit(1)
}

Expand Down
20 changes: 14 additions & 6 deletions libcni/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ type CNI interface {
GetStatusNetworkList(ctx context.Context, net *NetworkConfigList) error

GetCachedAttachments(containerID string) ([]*NetworkAttachment, error)

GetVersionInfo(ctx context.Context, pluginType string) (version.PluginInfo, error)
}

type CNIConfig struct {
Expand Down Expand Up @@ -770,9 +772,12 @@ func (c *CNIConfig) GCNetworkList(ctx context.Context, list *NetworkConfigList,
return nil
}

validAttachments := make(map[types.GCAttachment]interface{}, len(args.ValidAttachments))
for _, a := range args.ValidAttachments {
validAttachments[a] = nil
var validAttachments map[types.GCAttachment]interface{}
if args != nil {
validAttachments = make(map[types.GCAttachment]interface{}, len(args.ValidAttachments))
for _, a := range args.ValidAttachments {
validAttachments[a] = nil
}
}

var errs []error
Expand Down Expand Up @@ -805,10 +810,13 @@ func (c *CNIConfig) GCNetworkList(ctx context.Context, list *NetworkConfigList,
// now, if the version supports it, issue a GC
if gt, _ := version.GreaterThanOrEqualTo(list.CNIVersion, "1.1.0"); gt {
inject := map[string]interface{}{
"name": list.Name,
"cniVersion": list.CNIVersion,
"cni.dev/valid-attachments": args.ValidAttachments,
"name": list.Name,
"cniVersion": list.CNIVersion,
}
if args != nil {
inject["cni.dev/valid-attachments"] = args.ValidAttachments
}

for _, plugin := range list.Plugins {
// build config here
pluginConfig, err := InjectConf(plugin, inject)
Expand Down

0 comments on commit bf23ebc

Please sign in to comment.