diff --git a/internal/install/application_configuration.go b/internal/install/application_configuration.go index 4f852e515..8f8366e0c 100644 --- a/internal/install/application_configuration.go +++ b/internal/install/application_configuration.go @@ -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" @@ -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 @@ -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 { diff --git a/internal/install/application_configuration_test.go b/internal/install/application_configuration_test.go index d85830f86..3350a8005 100644 --- a/internal/install/application_configuration_test.go +++ b/internal/install/application_configuration_test.go @@ -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) { @@ -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) +} diff --git a/internal/testrunner/runners/system/tester.go b/internal/testrunner/runners/system/tester.go index 8ae04ed3d..6bae63935 100644 --- a/internal/testrunner/runners/system/tester.go +++ b/internal/testrunner/runners/system/tester.go @@ -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) }