Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[system tests] Add support for systemd option in agent.base_image setting #2066

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 := false
Expand All @@ -167,15 +168,36 @@ func selectElasticAgentImageName(version, agentBaseImage string) string {
disableWolfiImages = true
}
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)
}
Comment on lines +179 to +181
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the same behaviour as it was previously. It means using the complete image whenever it is possible.

}
}

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_WolfiImage(t *testing.T) {
version := "8.16.0-SNAPSHOT"
version := stackVersion8160
selected := selectElasticAgentImageName(version, "")
assert.Equal(t, selected, elasticAgentWolfiImageName)
}

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, elasticAgentWolfiImageName)
}

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