@@ -84,7 +84,7 @@ func (plugin *netPlugin) Stop() {
84
84
85
85
// GetEndpointID returns a unique endpoint ID based on the CNI args.
86
86
func (plugin * netPlugin ) getEndpointID (args * cniSkel.CmdArgs ) string {
87
- return args .ContainerID + "-" + args .IfName
87
+ return args .ContainerID [: 8 ] + "-" + args .IfName
88
88
}
89
89
90
90
//
@@ -115,7 +115,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
115
115
nwInfo , err := plugin .nm .GetNetworkInfo (networkId )
116
116
if err != nil {
117
117
// Network does not exist.
118
- log .Printf ("[cni-net] Creating network." )
118
+ log .Printf ("[cni-net] Creating network %v." , networkId )
119
119
120
120
// Call into IPAM plugin to allocate an address pool for the network.
121
121
result , err = cniInvoke .DelegateAdd (nwCfg .Ipam .Type , nwCfg .Serialize ())
@@ -127,21 +127,27 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
127
127
128
128
log .Printf ("[cni-net] IPAM plugin returned result %v." , resultImpl )
129
129
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 )
133
133
134
134
// 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 ())
136
136
if err != nil {
137
137
return plugin .Errorf ("Failed to add external interface: %v" , err )
138
138
}
139
139
140
140
// Create the network.
141
141
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
+ },
145
151
BridgeName : nwCfg .Bridge ,
146
152
}
147
153
@@ -150,13 +156,14 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
150
156
return plugin .Errorf ("Failed to create network: %v" , err )
151
157
}
152
158
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 ())
154
160
} else {
155
161
// 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 )
157
164
158
165
// Call into IPAM plugin to allocate an address for the endpoint.
159
- nwCfg .Ipam .Subnet = nwInfo . Subnets [ 0 ]
166
+ nwCfg .Ipam .Subnet = subnetPrefix
160
167
result , err = cniInvoke .DelegateAdd (nwCfg .Ipam .Type , nwCfg .Serialize ())
161
168
if err != nil {
162
169
return plugin .Errorf ("Failed to allocate address: %v" , err )
@@ -185,11 +192,11 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
185
192
}
186
193
187
194
// 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
190
197
191
198
// Create the endpoint.
192
- log .Printf ("[cni-net] Creating endpoint %+v " , epInfo )
199
+ log .Printf ("[cni-net] Creating endpoint %v. " , epInfo . Id )
193
200
err = plugin .nm .CreateEndpoint (networkId , epInfo )
194
201
if err != nil {
195
202
return plugin .Errorf ("Failed to create endpoint: %v" , err )
@@ -245,7 +252,7 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {
245
252
}
246
253
247
254
// 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 ()
249
256
for _ , address := range epInfo .IPAddresses {
250
257
nwCfg .Ipam .Address = address .IP .String ()
251
258
err = cniInvoke .DelegateDel (nwCfg .Ipam .Type , nwCfg .Serialize ())
0 commit comments