Skip to content

Commit

Permalink
(fleet) fix the OCI agent run_path (#27275)
Browse files Browse the repository at this point in the history
  • Loading branch information
arbll authored Jul 3, 2024
1 parent 92e0c66 commit 1253c7b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/config/setup/config_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ var (
// It might be overridden at build time
InstallPath = "/opt/datadog-agent"

// defaultRunPath is the default path for the agent's runtime files
// It might be overridden at build time
defaultRunPath = "/opt/datadog-agent/run"
// defaultRunPath is the default run path
// It is set in osinit to take into account InstallPath overrides
defaultRunPath = ""
)

var (
Expand Down Expand Up @@ -48,4 +48,7 @@ const (
// called by init in config.go, to ensure any os-specific config is done
// in time
func osinit() {
if defaultRunPath == "" {
defaultRunPath = filepath.Join(InstallPath, "run")
}
}
5 changes: 5 additions & 0 deletions test/new-e2e/tests/installer/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func (h *Host) AssertPackageInstalledByInstaller(pkgs ...string) {
}
}

// AgentRuntimeConfig returns the runtime agent config on the host.
func (h *Host) AgentRuntimeConfig() (string, error) {
return h.remote.Execute("sudo -u dd-agent datadog-agent config")
}

// AssertPackageVersion checks if a package is installed with the correct version
func (h *Host) AssertPackageVersion(pkg string, version string) {
state := h.State()
Expand Down
23 changes: 23 additions & 0 deletions test/new-e2e/tests/installer/package_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ package installer
import (
"fmt"
"path/filepath"
"strings"
"time"

awshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/environments/aws/host"
"github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/host"
e2eos "github.com/DataDog/test-infra-definitions/components/os"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)

const (
Expand Down Expand Up @@ -372,6 +376,25 @@ func (s *packageAgentSuite) TestExperimentStopped() {
}
}

func (s *packageAgentSuite) TestRunPath() {
s.RunInstallScript(envForceInstall("datadog-agent"))
defer s.Purge()
s.host.WaitForUnitActive("datadog-agent.service", "datadog-agent-trace.service", "datadog-agent-process.service")

var rawConfig string
var err error
assert.Eventually(s.T(), func() bool {
rawConfig, err = s.host.AgentRuntimeConfig()
return err == nil
}, 30*time.Second, 5*time.Second, "failed to get agent runtime config: %v", err)
var config map[string]interface{}
err = yaml.Unmarshal([]byte(rawConfig), &config)
assert.NoError(s.T(), err)
runPath, ok := config["run_path"].(string)
assert.True(s.T(), ok, "run_path not found in runtime config")
assert.True(s.T(), strings.HasPrefix(runPath, "/opt/datadog-packages/datadog-agent/"), "run_path is not in the expected location: %s", runPath)
}

func (s *packageAgentSuite) purgeAgentDebInstall() {
pkgManager := s.host.GetPkgManager()
switch pkgManager {
Expand Down

0 comments on commit 1253c7b

Please sign in to comment.