From 08afded4533678919cfc28cf04b14d28c70c07d5 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 7 May 2020 16:07:05 +0200 Subject: [PATCH] convert IPs to []string --- plugin/ipam/cni.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugin/ipam/cni.go b/plugin/ipam/cni.go index 3e9929c5ef..7193868b2e 100644 --- a/plugin/ipam/cni.go +++ b/plugin/ipam/cni.go @@ -39,13 +39,18 @@ func (i *Ipam) Allocate(args *skel.CmdArgs) (types.Result, error) { var ipnet *net.IPNet if len(conf.IPs) == 1 { - ip := conf.IPs[0] - if ip.Version == "4" { - ipnet = &ip.Address - err = i.weave.ClaimIP(containerID, ipnet, false) - } else { + ip := net.ParseIP(conf.IPs[0]).To4() + + if ip == nil { return nil, errors.New("allocation of ipv6 addresses is not implemented") } + + ipnet := &net.IPNet{ + IP: ip, + Mask: ip.DefaultMask(), + } + + err = i.weave.ClaimIP(containerID, ipnet, false) } else if conf.Subnet == "" { ipnet, err = i.weave.AllocateIP(containerID, false) } else { @@ -80,10 +85,10 @@ func (i *Ipam) Release(args *skel.CmdArgs) error { } type ipamConf struct { - Subnet string `json:"subnet,omitempty"` - Gateway net.IP `json:"gateway,omitempty"` - Routes []*types.Route `json:"routes"` - IPs []*current.IPConfig `json:"ips,omitempty"` + Subnet string `json:"subnet,omitempty"` + Gateway net.IP `json:"gateway,omitempty"` + Routes []*types.Route `json:"routes"` + IPs []string `json:"ips,omitempty"` } type netConf struct {