Skip to content

Commit

Permalink
fix(installer): Only override agent environment when installing the i…
Browse files Browse the repository at this point in the history
…njector for Docker (#31110)
  • Loading branch information
BaptisteFoy authored Nov 15, 2024
1 parent e415c48 commit c3cdb22
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
36 changes: 4 additions & 32 deletions pkg/fleet/installer/service/apm_inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,38 +121,6 @@ func (a *apmInjectorInstaller) Finish(err error) {
func (a *apmInjectorInstaller) Setup(ctx context.Context) error {
var err error

// Set up defaults for agent sockets
if err := a.configureSocketsEnv(ctx); err != nil {
return err
}
// Symlinks for sysvinit
if err := os.Symlink(envFilePath, "/etc/default/datadog-agent-trace"); err != nil && !os.IsExist(err) {
return fmt.Errorf("failed to symlink %s to /etc/default/datadog-agent-trace: %w", envFilePath, err)
}
if err := os.Symlink(envFilePath, "/etc/default/datadog-agent"); err != nil && !os.IsExist(err) {
return fmt.Errorf("failed to symlink %s to /etc/default/datadog-agent: %w", envFilePath, err)
}
systemdRunning, err := isSystemdRunning()
if err != nil {
return fmt.Errorf("failed to check if systemd is running: %w", err)
}
if systemdRunning {
if err := addSystemDEnvOverrides(ctx, agentUnit); err != nil {
return err
}
if err := addSystemDEnvOverrides(ctx, agentExp); err != nil {
return err
}
if err := addSystemDEnvOverrides(ctx, traceAgentUnit); err != nil {
return err
}
if err := addSystemDEnvOverrides(ctx, traceAgentExp); err != nil {
return err
}
if err := systemdReload(ctx); err != nil {
return err
}
}
if err := setupAppArmor(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -213,6 +181,10 @@ func (a *apmInjectorInstaller) Instrument(ctx context.Context) (retErr error) {
return fmt.Errorf("DD_APM_INSTRUMENTATION_ENABLED is set to docker but docker is not installed")
}
if shouldInstrumentDocker(a.envs) && dockerIsInstalled {
// Set up defaults for agent sockets -- requires an agent restart
if err := a.configureSocketsEnv(ctx); err != nil {
return err
}
a.cleanups = append(a.cleanups, a.dockerConfigInstrument.cleanup)
rollbackDocker, err := a.instrumentDocker(ctx)
if err != nil {
Expand Down
30 changes: 30 additions & 0 deletions pkg/fleet/installer/service/apm_sockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,36 @@ func (a *apmInjectorInstaller) configureSocketsEnv(ctx context.Context) (retErr
if err := os.Chmod(envFilePath, 0644); err != nil {
return fmt.Errorf("error changing permissions of %s: %w", envFilePath, err)
}

// Symlinks for sysvinit
if err := os.Symlink(envFilePath, "/etc/default/datadog-agent-trace"); err != nil && !os.IsExist(err) {
return fmt.Errorf("failed to symlink %s to /etc/default/datadog-agent-trace: %w", envFilePath, err)
}
if err := os.Symlink(envFilePath, "/etc/default/datadog-agent"); err != nil && !os.IsExist(err) {
return fmt.Errorf("failed to symlink %s to /etc/default/datadog-agent: %w", envFilePath, err)
}
systemdRunning, err := isSystemdRunning()
if err != nil {
return fmt.Errorf("failed to check if systemd is running: %w", err)
}
if systemdRunning {
if err := addSystemDEnvOverrides(ctx, agentUnit); err != nil {
return err
}
if err := addSystemDEnvOverrides(ctx, agentExp); err != nil {
return err
}
if err := addSystemDEnvOverrides(ctx, traceAgentUnit); err != nil {
return err
}
if err := addSystemDEnvOverrides(ctx, traceAgentExp); err != nil {
return err
}
if err := systemdReload(ctx); err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit c3cdb22

Please sign in to comment.