Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

CNI v0.5.2 #3668

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ func SupportsUserNS() bool {
// NetList implements the flag.Value interface to allow specification of --net with and without values
// Example: --net="all,net1:k1=v1;k2=v2,net2:l1=w1"
type NetList struct {
mapping map[string]string
// key = netname; value = array of [k, v] pairs
mapping map[string][][2]string
}

func (l *NetList) String() string {
Expand All @@ -256,8 +257,10 @@ func (l *NetList) String() string {

func (l *NetList) Set(value string) error {
if l.mapping == nil {
l.mapping = make(map[string]string)
l.mapping = make(map[string][][2]string)
}

// List of networks
for _, s := range strings.Split(value, ",") {
netArgsPair := strings.Split(s, ":")
netName := netArgsPair[0]
Expand All @@ -270,15 +273,23 @@ func (l *NetList) Set(value string) error {
return fmt.Errorf("found duplicate netname %q", netName)
}

// Parse additional arguments
switch {
case len(netArgsPair) == 1:
l.mapping[netName] = ""
l.mapping[netName] = nil
case len(netArgsPair) == 2:
if netName == "all" ||
netName == "host" {
return fmt.Errorf("arguments are not supported by special netname %q", netName)
}
l.mapping[netName] = netArgsPair[1]
// parse out pairs
pairs := [][2]string{}
for _, arg := range strings.Split(netArgsPair[1], ";") {
var p [2]string
copy(p[:], strings.SplitN(arg, "=", 2))
pairs = append(pairs, p)
}
l.mapping[netName] = pairs
case len(netArgsPair) > 2:
return fmt.Errorf("network %q provided with invalid arguments: %v", netName, netArgsPair[1:])
default:
Expand All @@ -298,11 +309,15 @@ func (l *NetList) Strings() []string {
}

var list []string
for k, v := range l.mapping {
if v == "" {
list = append(list, k)
for netname, args := range l.mapping {
if len(args) == 0 {
list = append(list, netname)
} else {
list = append(list, fmt.Sprintf("%s:%s", k, v))
tmp := []string{}
for _, arg := range args {
tmp = append(tmp, fmt.Sprintf("%s=%s", arg[0], arg[1]))
}
list = append(list, fmt.Sprintf("%s:%s", netname, strings.Join(tmp, ";")))
}
}
return list
Expand Down Expand Up @@ -336,7 +351,7 @@ func (l *NetList) Specific(net string) bool {
return exists
}

func (l *NetList) SpecificArgs(net string) string {
func (l *NetList) SpecificArgs(net string) [][2]string {
return l.mapping[net]
}

Expand Down
17 changes: 12 additions & 5 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,25 @@ import:
- private/protocol/rest
- private/signer/v4
- package: github.com/containernetworking/cni
version: v0.3.0
version: v0.5.2
subpackages:
- libcni
- pkg/invoke
- pkg/ip
- pkg/ipam
- pkg/ns
- pkg/skel
- pkg/testutils
- pkg/types
- pkg/types/020
- pkg/types/current
- pkg/utils
- pkg/utils/sysctl
- pkg/utils/hwaddr
- plugins/ipam/dhcp
- plugins/ipam/host-local
- plugins/ipam/host-local/backend
- plugins/ipam/host-local/backend/allocator
- plugins/ipam/host-local/backend/disk
- plugins/main/bridge
- plugins/main/ipvlan
Expand Down Expand Up @@ -205,7 +209,7 @@ import:
subpackages:
- capability
- package: github.com/vishvananda/netlink
version: ecf47fd5739b3d2c3daf7c89c4b9715a2605c21b
version: fe3b5664d23a11b52ba59bece4ff29c52772a56b
subpackages:
- nl
- package: go4.org
Expand Down
Loading