bug fix: exec of DEL cmd caused JSON decode error

When plugin is executed with a DEL command, it does not
print result to stdout unless there is an error. Therefore
it stdout bytes should not be passed to json.Unmarshal.
This commit is contained in:
Eugene Yakubovich
2015-09-18 10:30:10 -07:00
parent cc918a1aea
commit 9ea56937d4
3 changed files with 26 additions and 16 deletions

View File

@ -43,20 +43,18 @@ type CNIConfig struct {
}
func (c *CNIConfig) AddNetwork(net *NetworkConfig, rt *RuntimeConf) (*types.Result, error) {
return c.execPlugin("ADD", net, rt)
pluginPath := invoke.FindInPath(net.Network.Type, c.Path)
return invoke.ExecPluginWithResult(pluginPath, net.Bytes, c.args("ADD", rt))
}
func (c *CNIConfig) DelNetwork(net *NetworkConfig, rt *RuntimeConf) error {
_, err := c.execPlugin("DEL", net, rt)
return err
pluginPath := invoke.FindInPath(net.Network.Type, c.Path)
return invoke.ExecPluginWithoutResult(pluginPath, net.Bytes, c.args("DEL", rt))
}
// =====
func (c *CNIConfig) execPlugin(action string, conf *NetworkConfig, rt *RuntimeConf) (*types.Result, error) {
pluginPath := invoke.FindInPath(conf.Network.Type, c.Path)
args := &invoke.Args{
func (c *CNIConfig) args(action string, rt *RuntimeConf) *invoke.Args {
return &invoke.Args{
Command: action,
ContainerID: rt.ContainerID,
NetNS: rt.NetNS,
@ -64,5 +62,4 @@ func (c *CNIConfig) execPlugin(action string, conf *NetworkConfig, rt *RuntimeCo
IfName: rt.IfName,
Path: strings.Join(c.Path, ":"),
}
return invoke.ExecPlugin(pluginPath, conf.Bytes, args)
}