Skip to content

Commit 32f8b84

Browse files
[Elastic Log Driver] magefile cleanup, fix bug on plugin uninstall (elastic#16735)
* clean up magefile, quality of life issues * remove commented out code * cleanup
1 parent 5d08a23 commit 32f8b84

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

x-pack/dockerlogbeat/magefile.go

+15-22
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ func getPluginName() (string, error) {
6262

6363
// createContainer builds the plugin and creates the container that will later become the rootfs used by the plugin
6464
func createContainer(ctx context.Context, cli *client.Client) error {
65-
goVersion, err := mage.GoVersion()
66-
if err != nil {
67-
return errors.Wrap(err, "error determining go version")
68-
}
69-
7065
dockerLogBeatDir, err := os.Getwd()
7166
if err != nil {
7267
return errors.Wrap(err, "error getting work dir")
@@ -96,7 +91,6 @@ func createContainer(ctx context.Context, cli *client.Client) error {
9691
defer buildContext.Close()
9792

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

210204
// Uninstall removes working objects and containers
211205
func Uninstall(ctx context.Context) error {
212-
name, err := getPluginName()
213-
if err != nil {
214-
return err
215-
}
216-
217206
cli, err := client.NewClientWithOpts(client.FromEnv)
218207
if err != nil {
219208
return errors.Wrap(err, "Error creating docker client")
@@ -224,21 +213,25 @@ func Uninstall(ctx context.Context) error {
224213
if err != nil {
225214
return errors.Wrap(err, "error getting list of plugins")
226215
}
227-
oursExists := false
216+
217+
toRemoveName := ""
228218
for _, plugin := range plugins {
229219
if strings.Contains(plugin.Name, logDriverName) {
230-
oursExists = true
220+
toRemoveName = plugin.Name
221+
break
231222
}
232223
}
233-
if oursExists {
234-
err = cli.PluginDisable(ctx, name, types.PluginDisableOptions{Force: true})
235-
if err != nil {
236-
return errors.Wrap(err, "error disabling plugin")
237-
}
238-
err = cli.PluginRemove(ctx, name, types.PluginRemoveOptions{Force: true})
239-
if err != nil {
240-
return errors.Wrap(err, "error removing plugin")
241-
}
224+
if toRemoveName == "" {
225+
return nil
226+
}
227+
228+
err = cli.PluginDisable(ctx, toRemoveName, types.PluginDisableOptions{Force: true})
229+
if err != nil {
230+
return errors.Wrap(err, "error disabling plugin")
231+
}
232+
err = cli.PluginRemove(ctx, toRemoveName, types.PluginRemoveOptions{Force: true})
233+
if err != nil {
234+
return errors.Wrap(err, "error removing plugin")
242235
}
243236

244237
return nil

0 commit comments

Comments
 (0)