Skip to content

Commit

Permalink
[system tests] Add support for systemd option in agent.base_image (#2066
Browse files Browse the repository at this point in the history
)

Added support to run system tests using the regular Elastic Agent docker image
(e.g. docker.elastic.co/elastic-agent/elastic-agent), if "agent.base_image" setting
is set as "systemd".
  • Loading branch information
mrodm authored Sep 3, 2024
1 parent a4e1303 commit ed0a6dd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
36 changes: 29 additions & 7 deletions internal/install/application_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const (
// like 8.16.0-21bba6f5-SNAPSHOT
stackVersion8160 = "8.16.0-00000000-SNAPSHOT"

elasticAgentImageName = "docker.elastic.co/beats/elastic-agent"
elasticAgentLegacyImageName = "docker.elastic.co/beats/elastic-agent"
elasticAgentImageName = "docker.elastic.co/elastic-agent/elastic-agent"
elasticAgentCompleteLegacyImageName = "docker.elastic.co/beats/elastic-agent-complete"
elasticAgentCompleteImageName = "docker.elastic.co/elastic-agent/elastic-agent-complete"
elasticAgentWolfiImageName = "docker.elastic.co/elastic-agent/elastic-agent-wolfi"
Expand Down Expand Up @@ -152,13 +153,13 @@ func (ac *ApplicationConfiguration) SetCurrentProfile(name string) {
// This is mandatory as "elastic-agent-complete" is available since 7.15.0-SNAPSHOT.
func selectElasticAgentImageName(version, agentBaseImage string) string {
if version == "" { // as version is optional and can be empty
return elasticAgentImageName
return elasticAgentLegacyImageName
}

v, err := semver.NewVersion(version)
if err != nil {
logger.Errorf("stack version not in semver format (value: %s): %v", v, err)
return elasticAgentImageName
return elasticAgentLegacyImageName
}

disableWolfiImages := true
Expand All @@ -167,15 +168,36 @@ func selectElasticAgentImageName(version, agentBaseImage string) string {
disableWolfiImages = false
}
switch {
case !disableWolfiImages && !v.LessThan(elasticAgentWolfiVersion) && agentBaseImage != "complete":
return elasticAgentWolfiImageName
case !v.LessThan(elasticAgentCompleteOwnNamespaceVersion):
case agentBaseImage == "complete":
return selectElasticAgentCompleteImageName(v)
case agentBaseImage == "systemd":
return selectElasticAgentSystemDImageName(v)
default:
switch {
case !disableWolfiImages && !v.LessThan(elasticAgentWolfiVersion):
return elasticAgentWolfiImageName
default:
return selectElasticAgentCompleteImageName(v)
}
}
}

func selectElasticAgentCompleteImageName(version *semver.Version) string {
switch {
case !version.LessThan(elasticAgentCompleteOwnNamespaceVersion):
return elasticAgentCompleteImageName
case !v.LessThan(elasticAgentCompleteFirstSupportedVersion):
case !version.LessThan(elasticAgentCompleteFirstSupportedVersion):
return elasticAgentCompleteLegacyImageName
default:
return elasticAgentLegacyImageName
}
}

func selectElasticAgentSystemDImageName(version *semver.Version) string {
if !version.LessThan(elasticAgentCompleteOwnNamespaceVersion) {
return elasticAgentImageName
}
return elasticAgentLegacyImageName
}

type configurationOptions struct {
Expand Down
32 changes: 25 additions & 7 deletions internal/install/application_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
func TestSelectElasticAgentImageName_NoVersion(t *testing.T) {
var version string
selected := selectElasticAgentImageName(version, "")
assert.Equal(t, selected, elasticAgentImageName)
assert.Equal(t, selected, elasticAgentLegacyImageName)
}

func TestSelectElasticAgentImageName_OlderStack(t *testing.T) {
version := "7.14.99-SNAPSHOT"
selected := selectElasticAgentImageName(version, "")
assert.Equal(t, selected, elasticAgentImageName)
assert.Equal(t, selected, elasticAgentLegacyImageName)
}

func TestSelectElasticAgentImageName_FirstStackWithCompleteAgent(t *testing.T) {
Expand Down Expand Up @@ -53,31 +53,49 @@ func TestSelectElasticAgentImageName_NextStackInOwnNamespace(t *testing.T) {
}

func TestSelectElasticAgentImageName_DefaultImage816(t *testing.T) {
version := "8.16.0-SNAPSHOT"
version := stackVersion8160
selected := selectElasticAgentImageName(version, "")
assert.Equal(t, selected, elasticAgentCompleteImageName)
}

func TestSelectElasticAgentImageName_DisableWolfiImageEnvVar(t *testing.T) {
version := "8.16.0-SNAPSHOT"
version := stackVersion8160
t.Setenv(disableElasticAgentWolfiEnvVar, "true")
selected := selectElasticAgentImageName(version, "")
assert.Equal(t, selected, elasticAgentCompleteImageName)
}
func TestSelectElasticAgentImageName_EnableWolfiImageEnvVar(t *testing.T) {
version := "8.16.0-SNAPSHOT"
version := stackVersion8160
t.Setenv(disableElasticAgentWolfiEnvVar, "false")
selected := selectElasticAgentImageName(version, "")
assert.Equal(t, selected, elasticAgentWolfiImageName)
}

func TestSelectCompleteElasticAgentImageName_ForceCompleteImage(t *testing.T) {
version := "8.16.0-SNAPSHOT"
version := stackVersion8160
selected := selectElasticAgentImageName(version, "complete")
assert.Equal(t, selected, elasticAgentCompleteImageName)
}
func TestSelectCompleteElasticAgentImageName_ForceDefaultImage(t *testing.T) {
version := "8.16.0-SNAPSHOT"
version := stackVersion8160
selected := selectElasticAgentImageName(version, "default")
assert.Equal(t, selected, elasticAgentCompleteImageName)
}

func TestSelectCompleteElasticAgentImageName_ForceDefaultImageOldStack(t *testing.T) {
version := "8.15.0-SNAPSHOT"
selected := selectElasticAgentImageName(version, "default")
assert.Equal(t, selected, elasticAgentCompleteImageName)
}

func TestSelectCompleteElasticAgentImageName_ForceSystemDImage(t *testing.T) {
version := stackVersion8160
selected := selectElasticAgentImageName(version, "systemd")
assert.Equal(t, selected, elasticAgentImageName)
}

func TestSelectCompleteElasticAgentImageName_ForceSystemDImageOldStack(t *testing.T) {
version := stackVersion715
selected := selectElasticAgentImageName(version, "systemd")
assert.Equal(t, selected, elasticAgentLegacyImageName)
}
2 changes: 1 addition & 1 deletion internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (r *tester) createAgentInfo(policy *kibana.Policy, config *testConfig, runI
}

// This could be removed once package-spec adds this new field
if !slices.Contains([]string{"", "default", "complete"}, info.Agent.BaseImage) {
if !slices.Contains([]string{"", "default", "complete", "systemd"}, info.Agent.BaseImage) {
return agentdeployer.AgentInfo{}, fmt.Errorf("invalid value for agent.base_image: %q", info.Agent.BaseImage)
}

Expand Down

0 comments on commit ed0a6dd

Please sign in to comment.