Skip to content

Commit ea62b6d

Browse files
authored
Merge pull request #106 from sunya-ch/v1.0.4
Make sure execPlugin execute regardless of ipam return
2 parents 18ff99b + ca7fdd8 commit ea62b6d

File tree

2 files changed

+49
-24
lines changed

2 files changed

+49
-24
lines changed

cni/plugins/main/multi-nic/multi-nic.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func cmdDel(args *skel.CmdArgs) error {
181181
}
182182

183183
n, deviceType, err := loadConf(args)
184-
if err != nil {
184+
if err != nil && n == nil {
185185
utils.Logger.Debug(fmt.Sprintf("fail to load conf: %v", err))
186186
return nil
187187
}
@@ -192,7 +192,6 @@ func cmdDel(args *skel.CmdArgs) error {
192192
err = ipam.ExecDel(n.IPAM.Type, injectedStdIn)
193193
if err != nil {
194194
utils.Logger.Debug(fmt.Sprintf("Failed ipam.ExecDel %s: %v", err, string(injectedStdIn)))
195-
return nil
196195
}
197196
}
198197

@@ -201,14 +200,14 @@ func cmdDel(args *skel.CmdArgs) error {
201200
if n.NetConf.RawPrevResult != nil {
202201
if err = version.ParsePrevResult(&n.NetConf); err != nil {
203202
utils.Logger.Debug(fmt.Sprintf("could not parse prevResult: %v", err))
204-
return nil
205-
}
206-
result, err = current.NewResultFromResult(n.NetConf.PrevResult)
207-
if err != nil {
208-
utils.Logger.Debug(fmt.Sprintf("could not convert result to current version: %v", err))
209-
return nil
203+
} else {
204+
result, err = current.NewResultFromResult(n.NetConf.PrevResult)
205+
if err != nil {
206+
utils.Logger.Debug(fmt.Sprintf("could not convert result to current version: %v", err))
207+
}
210208
}
211-
} else {
209+
}
210+
if result == nil {
212211
result = &current.Result{CNIVersion: current.ImplementedSpecVersion}
213212
}
214213

@@ -224,7 +223,6 @@ func cmdDel(args *skel.CmdArgs) error {
224223
}
225224
if err != nil {
226225
utils.Logger.Debug(fmt.Sprintf("Fail loading %v: %v", string(args.StdinData), err))
227-
return nil
228226
}
229227
if len(confBytesArray) == 0 {
230228
utils.Logger.Debug(fmt.Sprintf("zero config on cmdDel: %v (%d)", string(args.StdinData), len(n.Masters)))
@@ -237,7 +235,6 @@ func cmdDel(args *skel.CmdArgs) error {
237235
_, err := execPlugin(deviceType, command, confBytes, args, ifName, false)
238236
if err != nil {
239237
utils.Logger.Debug(fmt.Sprintf("Fail execPlugin %v: %v", string(confBytes), err))
240-
return nil
241238
}
242239
}
243240
return nil
@@ -249,7 +246,7 @@ func cmdCheck(args *skel.CmdArgs) error {
249246
}
250247

251248
n, deviceType, err := loadConf(args)
252-
if err != nil {
249+
if err != nil && n == nil {
253250
utils.Logger.Debug(fmt.Sprintf("fail to load conf: %v", err))
254251
return nil
255252
}
@@ -259,14 +256,14 @@ func cmdCheck(args *skel.CmdArgs) error {
259256
if n.NetConf.RawPrevResult != nil {
260257
if err = version.ParsePrevResult(&n.NetConf); err != nil {
261258
utils.Logger.Debug(fmt.Sprintf("could not parse prevResult: %v", err))
262-
return nil
263-
}
264-
result, err = current.NewResultFromResult(n.NetConf.PrevResult)
265-
if err != nil {
266-
utils.Logger.Debug(fmt.Sprintf("could not convert result to current version: %v", err))
267-
return nil
259+
} else {
260+
result, err = current.NewResultFromResult(n.NetConf.PrevResult)
261+
if err != nil {
262+
utils.Logger.Debug(fmt.Sprintf("could not convert result to current version: %v", err))
263+
}
268264
}
269-
} else {
265+
}
266+
if result == nil {
270267
result = &current.Result{CNIVersion: current.ImplementedSpecVersion}
271268
}
272269

@@ -282,7 +279,6 @@ func cmdCheck(args *skel.CmdArgs) error {
282279
}
283280
if err != nil {
284281
utils.Logger.Debug(fmt.Sprintf("Fail loading %v: %v", string(args.StdinData), err))
285-
return nil
286282
}
287283
if len(confBytesArray) == 0 {
288284
utils.Logger.Debug(fmt.Sprintf("zero config on cmdCheck: %v (%d)", string(args.StdinData), len(n.Masters)))
@@ -295,7 +291,6 @@ func cmdCheck(args *skel.CmdArgs) error {
295291
_, err := execPlugin(deviceType, command, confBytes, args, ifName, false)
296292
if err != nil {
297293
utils.Logger.Debug(fmt.Sprintf("Fail execPlugin %v: %v", string(confBytes), err))
298-
return nil
299294
}
300295
}
301296
return nil

cni/plugins/main/multi-nic/multi-nic_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ func buildOneConfig(cniVersion string, orig *NetConf, prevResult types.Result) (
125125

126126
}
127127

128-
func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
129-
log.Printf("multinicAddCheckDelTest")
130-
log.Printf("%s", conf)
128+
func multinicAddTest(conf, masterName string, originalNS, targetNS ns.NetNS) types.Result {
129+
log.Printf("Add %s", conf)
131130
// Unmarshal to pull out CNI spec version
132131
rawConfig := make(map[string]interface{})
133132
err := json.Unmarshal([]byte(conf), &rawConfig)
@@ -176,6 +175,23 @@ func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.Ne
176175
return nil
177176
})
178177
Expect(err).NotTo(HaveOccurred())
178+
return result
179+
}
180+
181+
func multinicCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS, result types.Result) {
182+
log.Printf("CheckDel %s", conf)
183+
// Unmarshal to pull out CNI spec version
184+
rawConfig := make(map[string]interface{})
185+
err := json.Unmarshal([]byte(conf), &rawConfig)
186+
Expect(err).NotTo(HaveOccurred())
187+
cniVersion := rawConfig["cniVersion"].(string)
188+
189+
args := &skel.CmdArgs{
190+
ContainerID: "dummy",
191+
Netns: targetNS.Path(),
192+
IfName: "net1",
193+
StdinData: []byte(conf),
194+
}
179195

180196
n := &NetConf{}
181197
err = json.Unmarshal([]byte(conf), &n)
@@ -228,6 +244,19 @@ func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.Ne
228244
Expect(err).NotTo(HaveOccurred())
229245
}
230246

247+
func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
248+
log.Printf("multinicAddCheckDelTest")
249+
result := multinicAddTest(conf, masterName, originalNS, targetNS)
250+
multinicCheckDelTest(conf, masterName, originalNS, targetNS, result)
251+
}
252+
253+
func multinicDelWithoutDaemonTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
254+
log.Printf("multinicDelWithoutDaemonTest")
255+
result := multinicAddTest(conf, masterName, originalNS, targetNS)
256+
confWithoutDaemon := strings.ReplaceAll(conf, BRIDGE_HOST_IP, "")
257+
multinicCheckDelTest(confWithoutDaemon, masterName, originalNS, targetNS, result)
258+
}
259+
231260
type tester interface {
232261
// verifyResult minimally verifies the Result and returns the interface's MAC address
233262
verifyResult(result types.Result, name string) string
@@ -405,6 +434,7 @@ var _ = Describe("Operations", func() {
405434
`, BRIDGE_HOST_IP, daemonPort)
406435
conf := getConfig(ver, multiNICIPAM, masterNets)
407436
multinicAddCheckDelTest(conf, "", originalNS, targetNS)
437+
multinicDelWithoutDaemonTest(conf, "", originalNS, targetNS)
408438
})
409439
It(fmt.Sprintf("[%s] configures and deconfigures link with ADD/DEL (single-nic IPAM)", ver), func() {
410440
conf := getConfig(ver, singleNICIPAM, masterNets)

0 commit comments

Comments
 (0)