浏览代码

Cleanup after plugin install.

During error cases, we dont cleanup correctly. This commit takes care
of removing the plugin, if there are errors after the pull passed. It
also shuts down the plugin, if there are errors after the plugin in the
enable path.

Signed-off-by: Anusha Ragunathan <anusha@docker.com>
(cherry picked from commit 1144f8f1d4b1fd2bbf1f41bf5dad8d929d0dc06e)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
Anusha Ragunathan 8 年之前
父节点
当前提交
3f6e6b3f2d
共有 2 个文件被更改,包括 10 次插入3 次删除
  1. 9 3
      client/plugin_install.go
  2. 1 0
      plugin/manager_linux.go

+ 9 - 3
client/plugin_install.go

@@ -10,7 +10,7 @@ import (
 )
 
 // PluginInstall installs a plugin
-func (cli *Client) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) error {
+func (cli *Client) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (err error) {
 	// FIXME(vdemeester) name is a ref, we might want to parse/validate it here.
 	query := url.Values{}
 	query.Set("name", name)
@@ -27,6 +27,14 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types
 		ensureReaderClosed(resp)
 		return err
 	}
+
+	defer func() {
+		if err != nil {
+			delResp, _ := cli.delete(ctx, "/plugins/"+name, nil, nil)
+			ensureReaderClosed(delResp)
+		}
+	}()
+
 	var privileges types.PluginPrivileges
 	if err := json.NewDecoder(resp.body).Decode(&privileges); err != nil {
 		ensureReaderClosed(resp)
@@ -40,8 +48,6 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types
 			return err
 		}
 		if !accept {
-			resp, _ := cli.delete(ctx, "/plugins/"+name, nil, nil)
-			ensureReaderClosed(resp)
 			return pluginPermissionDenied{name}
 		}
 	}

+ 1 - 0
plugin/manager_linux.go

@@ -36,6 +36,7 @@ func (pm *Manager) enable(p *v2.Plugin, force bool) error {
 		p.Lock()
 		p.Restart = false
 		p.Unlock()
+		shutdownPlugin(p, pm.containerdClient)
 		return err
 	}