Skip to content

Commit

Permalink
[Elastic Log Driver] magefile cleanup, fix bug on plugin uninstall (#…
Browse files Browse the repository at this point in the history
…16735)

* clean up magefile, quality of life issues

* remove commented out code

* cleanup
  • Loading branch information
fearful-symmetry authored Mar 4, 2020
1 parent 4201e36 commit d7d38f3
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions x-pack/dockerlogbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ func getPluginName() (string, error) {

// createContainer builds the plugin and creates the container that will later become the rootfs used by the plugin
func createContainer(ctx context.Context, cli *client.Client) error {
goVersion, err := mage.GoVersion()
if err != nil {
return errors.Wrap(err, "error determining go version")
}

dockerLogBeatDir, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "error getting work dir")
Expand Down Expand Up @@ -96,7 +91,6 @@ func createContainer(ctx context.Context, cli *client.Client) error {
defer buildContext.Close()

buildOpts := types.ImageBuildOptions{
BuildArgs: map[string]*string{"versionString": &goVersion},
Tags: []string{rootImageName},
Dockerfile: "Dockerfile",
}
Expand Down Expand Up @@ -209,11 +203,6 @@ func cleanDockerArtifacts(ctx context.Context, containerID string, cli *client.C

// Uninstall removes working objects and containers
func Uninstall(ctx context.Context) error {
name, err := getPluginName()
if err != nil {
return err
}

cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return errors.Wrap(err, "Error creating docker client")
Expand All @@ -224,21 +213,25 @@ func Uninstall(ctx context.Context) error {
if err != nil {
return errors.Wrap(err, "error getting list of plugins")
}
oursExists := false

toRemoveName := ""
for _, plugin := range plugins {
if strings.Contains(plugin.Name, logDriverName) {
oursExists = true
toRemoveName = plugin.Name
break
}
}
if oursExists {
err = cli.PluginDisable(ctx, name, types.PluginDisableOptions{Force: true})
if err != nil {
return errors.Wrap(err, "error disabling plugin")
}
err = cli.PluginRemove(ctx, name, types.PluginRemoveOptions{Force: true})
if err != nil {
return errors.Wrap(err, "error removing plugin")
}
if toRemoveName == "" {
return nil
}

err = cli.PluginDisable(ctx, toRemoveName, types.PluginDisableOptions{Force: true})
if err != nil {
return errors.Wrap(err, "error disabling plugin")
}
err = cli.PluginRemove(ctx, toRemoveName, types.PluginRemoveOptions{Force: true})
if err != nil {
return errors.Wrap(err, "error removing plugin")
}

return nil
Expand Down

0 comments on commit d7d38f3

Please sign in to comment.