Browse code

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 authored on 2016/11/17 07:42:46
Showing 2 changed files
... ...
@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 // PluginInstall installs a plugin
13
-func (cli *Client) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) error {
13
+func (cli *Client) PluginInstall(ctx context.Context, name string, options types.PluginInstallOptions) (err error) {
14 14
 	// FIXME(vdemeester) name is a ref, we might want to parse/validate it here.
15 15
 	query := url.Values{}
16 16
 	query.Set("name", name)
... ...
@@ -27,6 +27,14 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types
27 27
 		ensureReaderClosed(resp)
28 28
 		return err
29 29
 	}
30
+
31
+	defer func() {
32
+		if err != nil {
33
+			delResp, _ := cli.delete(ctx, "/plugins/"+name, nil, nil)
34
+			ensureReaderClosed(delResp)
35
+		}
36
+	}()
37
+
30 38
 	var privileges types.PluginPrivileges
31 39
 	if err := json.NewDecoder(resp.body).Decode(&privileges); err != nil {
32 40
 		ensureReaderClosed(resp)
... ...
@@ -40,8 +48,6 @@ func (cli *Client) PluginInstall(ctx context.Context, name string, options types
40 40
 			return err
41 41
 		}
42 42
 		if !accept {
43
-			resp, _ := cli.delete(ctx, "/plugins/"+name, nil, nil)
44
-			ensureReaderClosed(resp)
45 43
 			return pluginPermissionDenied{name}
46 44
 		}
47 45
 	}
... ...
@@ -36,6 +36,7 @@ func (pm *Manager) enable(p *v2.Plugin, force bool) error {
36 36
 		p.Lock()
37 37
 		p.Restart = false
38 38
 		p.Unlock()
39
+		shutdownPlugin(p, pm.containerdClient)
39 40
 		return err
40 41
 	}
41 42