Skip to content

Commit d0d9a4f

Browse files
tamilmani1989sharmasushant
authored andcommitted
Fix for unparseable error returned by Azure CNI (#212)
* Write result to stdout only in successful case
1 parent 27e10e8 commit d0d9a4f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cni/network/network.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
151151
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path)
152152

153153
defer func() {
154-
if result == nil {
155-
result = &cniTypesCurr.Result{}
156-
}
157-
158154
// Add Interfaces to result.
159155
if result == nil {
160156
result = &cniTypesCurr.Result{}
@@ -169,13 +165,17 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
169165
addSnatInterface(nwCfg, result)
170166

171167
// Convert result to the requested CNI version.
172-
res, err := result.GetAsVersion(nwCfg.CNIVersion)
173-
if err != nil {
174-
err = plugin.Error(err)
168+
res, vererr := result.GetAsVersion(nwCfg.CNIVersion)
169+
if vererr != nil {
170+
log.Printf("GetAsVersion failed with error %v", vererr)
171+
plugin.Error(vererr)
172+
}
173+
174+
if err == nil && res != nil {
175+
// Output the result to stdout.
176+
res.Print()
175177
}
176178

177-
// Output the result to stdout.
178-
res.Print()
179179
log.Printf("[cni-net] ADD command completed with result:%+v err:%v.", result, err)
180180
}()
181181

0 commit comments

Comments
 (0)