Skip to content

Commit a836d4f

Browse files
Add pre-hook to load paths overrides in container (#1875)
1 parent c3f216c commit a836d4f

File tree

4 files changed

+4
-22
lines changed

4 files changed

+4
-22
lines changed

internal/pkg/agent/cmd/common.go

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func NewCommand() *cobra.Command {
3535
func NewCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
3636
cmd := &cobra.Command{
3737
Use: "elastic-agent [subcommand]",
38+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
39+
return tryContainerLoadPaths()
40+
},
3841
}
3942

4043
// path flags

internal/pkg/agent/cmd/diagnostics.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,10 @@ func diagnosticCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
5050
fileName = "elastic-agent-diagnostics-" + ts.Format("2006-01-02T15-04-05Z07-00") + ".zip" // RFC3339 format that replaces : with -, so it will work on Windows
5151
}
5252

53-
err := tryContainerLoadPaths()
54-
if err != nil {
55-
return err
56-
}
57-
5853
ctx := handleSignal(context.Background())
5954

6055
daemon := client.New()
61-
err = daemon.Connect(ctx)
56+
err := daemon.Connect(ctx)
6257
if err != nil {
6358
return fmt.Errorf("failed to connect to daemon: %w", err)
6459
}

internal/pkg/agent/cmd/inspect.go

-11
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ type inspectConfigOpts struct {
126126
}
127127

128128
func inspectConfig(ctx context.Context, cfgPath string, opts inspectConfigOpts, streams *cli.IOStreams) error {
129-
err := tryContainerLoadPaths()
130-
if err != nil {
131-
return err
132-
}
133-
134129
l, err := newErrorLogger()
135130
if err != nil {
136131
return err
@@ -236,12 +231,6 @@ func inspectComponents(ctx context.Context, cfgPath string, opts inspectComponen
236231
return err
237232
}
238233

239-
// Ensure that when running inside a container that the correct paths are used.
240-
err = tryContainerLoadPaths()
241-
if err != nil {
242-
return err
243-
}
244-
245234
// Load the requirements before trying to load the configuration. These should always load
246235
// even if the configuration is wrong.
247236
platform, err := component.LoadPlatformDetail()

internal/pkg/agent/cmd/status.go

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ func newStatusCommand(_ []string, streams *cli.IOStreams) *cobra.Command {
4949
}
5050

5151
func statusCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error {
52-
err := tryContainerLoadPaths()
53-
if err != nil {
54-
return err
55-
}
56-
5752
output, _ := cmd.Flags().GetString("output")
5853
outputFunc, ok := statusOutputs[output]
5954
if !ok {

0 commit comments

Comments
 (0)