@@ -84,7 +84,7 @@ func (plugin *netPlugin) Stop() {
8484
8585// GetEndpointID returns a unique endpoint ID based on the CNI args.
8686func (plugin * netPlugin ) getEndpointID (args * cniSkel.CmdArgs ) string {
87- return args .ContainerID + "-" + args .IfName
87+ return args .ContainerID [: 8 ] + "-" + args .IfName
8888}
8989
9090//
@@ -115,7 +115,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
115115 nwInfo , err := plugin .nm .GetNetworkInfo (networkId )
116116 if err != nil {
117117 // Network does not exist.
118- log .Printf ("[cni-net] Creating network." )
118+ log .Printf ("[cni-net] Creating network %v." , networkId )
119119
120120 // Call into IPAM plugin to allocate an address pool for the network.
121121 result , err = cniInvoke .DelegateAdd (nwCfg .Ipam .Type , nwCfg .Serialize ())
@@ -127,21 +127,27 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
127127
128128 log .Printf ("[cni-net] IPAM plugin returned result %v." , resultImpl )
129129
130- // Derive the subnet from allocated IP address.
131- subnet := resultImpl .IP4 .IP
132- subnet .IP = subnet .IP .Mask (subnet .Mask )
130+ // Derive the subnet prefix from allocated IP address.
131+ subnetPrefix := resultImpl .IP4 .IP
132+ subnetPrefix .IP = subnetPrefix .IP .Mask (subnetPrefix .Mask )
133133
134134 // Add the master as an external interface.
135- err = plugin .nm .AddExternalInterface (nwCfg .Master , subnet .String ())
135+ err = plugin .nm .AddExternalInterface (nwCfg .Master , subnetPrefix .String ())
136136 if err != nil {
137137 return plugin .Errorf ("Failed to add external interface: %v" , err )
138138 }
139139
140140 // Create the network.
141141 nwInfo := network.NetworkInfo {
142- Id : networkId ,
143- Mode : nwCfg .Mode ,
144- Subnets : []string {subnet .String ()},
142+ Id : networkId ,
143+ Mode : nwCfg .Mode ,
144+ Subnets : []network.SubnetInfo {
145+ network.SubnetInfo {
146+ Family : platform .AfINET ,
147+ Prefix : subnetPrefix ,
148+ Gateway : resultImpl .IP4 .Gateway ,
149+ },
150+ },
145151 BridgeName : nwCfg .Bridge ,
146152 }
147153
@@ -150,13 +156,14 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
150156 return plugin .Errorf ("Failed to create network: %v" , err )
151157 }
152158
153- log .Printf ("[cni-net] Created network %v with subnet %v." , networkId , subnet .String ())
159+ log .Printf ("[cni-net] Created network %v with subnet %v." , networkId , subnetPrefix .String ())
154160 } else {
155161 // Network already exists.
156- log .Printf ("[cni-net] Found network %v with subnet %v." , networkId , nwInfo .Subnets [0 ])
162+ subnetPrefix := nwInfo .Subnets [0 ].Prefix .String ()
163+ log .Printf ("[cni-net] Found network %v with subnet %v." , networkId , subnetPrefix )
157164
158165 // Call into IPAM plugin to allocate an address for the endpoint.
159- nwCfg .Ipam .Subnet = nwInfo . Subnets [ 0 ]
166+ nwCfg .Ipam .Subnet = subnetPrefix
160167 result , err = cniInvoke .DelegateAdd (nwCfg .Ipam .Type , nwCfg .Serialize ())
161168 if err != nil {
162169 return plugin .Errorf ("Failed to allocate address: %v" , err )
@@ -185,11 +192,11 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
185192 }
186193
187194 // Populate DNS info.
188- epInfo .DNSSuffix = resultImpl .DNS .Domain
189- epInfo .DNSServers = resultImpl .DNS .Nameservers
195+ epInfo .DNS . Suffix = resultImpl .DNS .Domain
196+ epInfo .DNS . Servers = resultImpl .DNS .Nameservers
190197
191198 // Create the endpoint.
192- log .Printf ("[cni-net] Creating endpoint %+v " , epInfo )
199+ log .Printf ("[cni-net] Creating endpoint %v. " , epInfo . Id )
193200 err = plugin .nm .CreateEndpoint (networkId , epInfo )
194201 if err != nil {
195202 return plugin .Errorf ("Failed to create endpoint: %v" , err )
@@ -245,7 +252,7 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {
245252 }
246253
247254 // Call into IPAM plugin to release the endpoint's addresses.
248- nwCfg .Ipam .Subnet = nwInfo .Subnets [0 ]
255+ nwCfg .Ipam .Subnet = nwInfo .Subnets [0 ]. Prefix . String ()
249256 for _ , address := range epInfo .IPAddresses {
250257 nwCfg .Ipam .Address = address .IP .String ()
251258 err = cniInvoke .DelegateDel (nwCfg .Ipam .Type , nwCfg .Serialize ())
0 commit comments