Skip to content

Commit

Permalink
Support Elastic Agent complete wolfi image (#2115)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mrodm authored Sep 26, 2024
1 parent 9009c38 commit 3c876c0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
35 changes: 22 additions & 13 deletions internal/install/application_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions internal/install/application_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3c876c0

Please sign in to comment.