From 46887df240b951706fbe3bc25e41f7e4b8c79187 Mon Sep 17 00:00:00 2001 From: Tamilmani Manoharan Date: Mon, 30 Jul 2018 14:33:16 -0700 Subject: [PATCH 1/3] Write result to stdout only in successful case --- cni/network/network.go | 44 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/cni/network/network.go b/cni/network/network.go index b17ca6bded..a0b103e2f7 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -151,32 +151,34 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error { args.ContainerID, args.Netns, args.IfName, args.Args, args.Path) defer func() { - if result == nil { - result = &cniTypesCurr.Result{} - } - - // Add Interfaces to result. - if result == nil { - result = &cniTypesCurr.Result{} - } + if err == nil { + if result == nil { + result = &cniTypesCurr.Result{} + } - iface = &cniTypesCurr.Interface{ - Name: args.IfName, - } + // Add Interfaces to result. + if result == nil { + result = &cniTypesCurr.Result{} + } - result.Interfaces = append(result.Interfaces, iface) + iface = &cniTypesCurr.Interface{ + Name: args.IfName, + } - addSnatInterface(nwCfg, result) + result.Interfaces = append(result.Interfaces, iface) - // Convert result to the requested CNI version. - res, err := result.GetAsVersion(nwCfg.CNIVersion) - if err != nil { - err = plugin.Error(err) - } + addSnatInterface(nwCfg, result) - // Output the result to stdout. - res.Print() - log.Printf("[cni-net] ADD command completed with result:%+v err:%v.", result, err) + // Convert result to the requested CNI version. + res, err := result.GetAsVersion(nwCfg.CNIVersion) + if err != nil { + err = plugin.Error(err) + } + + // Output the result to stdout. + res.Print() + log.Printf("[cni-net] ADD command completed with result:%+v err:%v.", result, err) + } }() // Parse Pod arguments. From 14efabc45bf6c42992217bd66b7940ddc46d515c Mon Sep 17 00:00:00 2001 From: Tamilmani Manoharan Date: Mon, 30 Jul 2018 18:59:44 -0700 Subject: [PATCH 2/3] fixed log --- cni/network/network.go | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/cni/network/network.go b/cni/network/network.go index a0b103e2f7..2fa9ceeb49 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -151,34 +151,32 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error { args.ContainerID, args.Netns, args.IfName, args.Args, args.Path) defer func() { - if err == nil { - if result == nil { - result = &cniTypesCurr.Result{} - } - - // Add Interfaces to result. - if result == nil { - result = &cniTypesCurr.Result{} - } + // Add Interfaces to result. + if result == nil { + result = &cniTypesCurr.Result{} + } - iface = &cniTypesCurr.Interface{ - Name: args.IfName, - } + iface = &cniTypesCurr.Interface{ + Name: args.IfName, + } - result.Interfaces = append(result.Interfaces, iface) + result.Interfaces = append(result.Interfaces, iface) - addSnatInterface(nwCfg, result) + addSnatInterface(nwCfg, result) - // Convert result to the requested CNI version. - res, err := result.GetAsVersion(nwCfg.CNIVersion) - if err != nil { - err = plugin.Error(err) - } + // Convert result to the requested CNI version. + res, vererr := result.GetAsVersion(nwCfg.CNIVersion) + if vererr != nil { + log.Printf("GetAsVersion failed with error %v", vererr) + plugin.Error(vererr) + } + if err == nil { // Output the result to stdout. res.Print() - log.Printf("[cni-net] ADD command completed with result:%+v err:%v.", result, err) } + + log.Printf("[cni-net] ADD command completed with result:%+v err:%v.", result, err) }() // Parse Pod arguments. From 93cd325af79d74041fa7b570afdb22512b04fe01 Mon Sep 17 00:00:00 2001 From: Tamilmani Manoharan Date: Wed, 8 Aug 2018 10:57:07 -0700 Subject: [PATCH 3/3] addressed review comments --- cni/network/network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cni/network/network.go b/cni/network/network.go index 2fa9ceeb49..6222d85cef 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -171,7 +171,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error { plugin.Error(vererr) } - if err == nil { + if err == nil && res != nil { // Output the result to stdout. res.Print() }