From 3c876c0617f13dd9b9d7ecb9dd34c1df9cc6c205 Mon Sep 17 00:00:00 2001 From: Mario Rodriguez Molins Date: Thu, 26 Sep 2024 12:23:41 +0200 Subject: [PATCH] Support Elastic Agent complete wolfi image (#2115) Update the Elastic Agent complete image used starting in Elastic stack versions 8.16.0-SNAPSHOT. Starting with that stack version, complete Elastic Agent image would be based on wolfi. --- internal/install/application_configuration.go | 35 ++++++++++++------- .../install/application_configuration_test.go | 10 ++++-- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/internal/install/application_configuration.go b/internal/install/application_configuration.go index 61934b4bf..075761ab9 100644 --- a/internal/install/application_configuration.go +++ b/internal/install/application_configuration.go @@ -32,6 +32,7 @@ const ( 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" + elasticAgentCompleteWolfiImageName = "docker.elastic.co/elastic-agent/elastic-agent-complete-wolfi" elasticAgentWolfiImageName = "docker.elastic.co/elastic-agent/elastic-agent-wolfi" elasticsearchImageName = "docker.elastic.co/elasticsearch/elasticsearch" kibanaImageName = "docker.elastic.co/kibana/kibana" @@ -162,26 +163,34 @@ func selectElasticAgentImageName(version, agentBaseImage string) string { return elasticAgentWolfiImageName } - disableWolfiImages := false - valueEnv, ok := os.LookupEnv(disableElasticAgentWolfiEnvVar) - if ok && strings.ToLower(valueEnv) != "false" { - disableWolfiImages = true - } - switch { - case agentBaseImage == "complete": - return selectElasticAgentCompleteImageName(v) - case agentBaseImage == "systemd": + shouldUseWolfiImage := shouldUseWolfiImages(v) + + switch agentBaseImage { + case "systemd": return selectElasticAgentSystemDImageName(v) + case "complete": + if shouldUseWolfiImage { + return elasticAgentCompleteWolfiImageName + } + return selectElasticAgentCompleteImageName(v) default: - switch { - case !disableWolfiImages && !v.LessThan(elasticAgentWolfiVersion): + if shouldUseWolfiImage { return elasticAgentWolfiImageName - default: - return selectElasticAgentCompleteImageName(v) } + return selectElasticAgentCompleteImageName(v) } } +func shouldUseWolfiImages(version *semver.Version) bool { + disableWolfiImages := false + valueEnv, ok := os.LookupEnv(disableElasticAgentWolfiEnvVar) + if ok && strings.ToLower(valueEnv) != "false" { + disableWolfiImages = true + } + + return !disableWolfiImages && !version.LessThan(elasticAgentWolfiVersion) +} + func selectElasticAgentCompleteImageName(version *semver.Version) string { switch { case !version.LessThan(elasticAgentCompleteOwnNamespaceVersion): diff --git a/internal/install/application_configuration_test.go b/internal/install/application_configuration_test.go index 4e257608e..83a7709fa 100644 --- a/internal/install/application_configuration_test.go +++ b/internal/install/application_configuration_test.go @@ -76,12 +76,18 @@ func TestSelectElasticAgentImageName_EnableWolfiImageEnvVar(t *testing.T) { assert.Equal(t, elasticAgentWolfiImageName, selected) } -func TestSelectCompleteElasticAgentImageName_ForceCompleteImage(t *testing.T) { - version := stackVersion8160 +func TestSelectCompleteElasticAgentImageName_ForceCompleteImage_NonWolfi(t *testing.T) { + version := "8.15.0" selected := selectElasticAgentImageName(version, "complete") assert.Equal(t, elasticAgentCompleteImageName, selected) } +func TestSelectCompleteElasticAgentImageName_ForceCompleteImage_Wolfi(t *testing.T) { + version := stackVersion8160 + selected := selectElasticAgentImageName(version, "complete") + assert.Equal(t, elasticAgentCompleteWolfiImageName, selected) +} + func TestSelectCompleteElasticAgentImageName_ForceDefaultImage_DisabledEnvVar(t *testing.T) { version := stackVersion8160 t.Setenv(disableElasticAgentWolfiEnvVar, "true")