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

Add support to use wolfi Elastic Agent image starting in 8.16.0-SNAPSHOT #2038

Merged
merged 13 commits into from
Aug 29, 2024
18 changes: 18 additions & 0 deletions internal/install/application_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/Masterminds/semver/v3"

Expand All @@ -23,10 +24,14 @@ import (
const (
stackVersion715 = "7.15.0-SNAPSHOT"
stackVersion820 = "8.2.0-SNAPSHOT"
// Not setting here 8.16.0-SNAPSHOT to take also into account prerelease versions
// like 8.16.0-21bba6f5-SNAPSHOT
stackVersion8160 = "8.16.0-00000000-SNAPSHOT"
Copy link
Contributor Author

@mrodm mrodm Aug 26, 2024

Choose a reason for hiding this comment

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

Using 8.16.0-SNAPSHOT here as version did not change the docker image used for 8.16.0-21bba6f5-SNAPSHOT. So, this change is also applied for the Makefile target stack-command-8x.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add a comment mentioning this. Or set it to 8.15.999.

I guess we didn't have the same problem with the snapshots above because we were not using tagged versions, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, previously tests were using SNAPSHOT versions without the commit in the prerelease tag.

I'll add a comment 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment in 094f898


elasticAgentImageName = "docker.elastic.co/beats/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"
elasticsearchImageName = "docker.elastic.co/elasticsearch/elasticsearch"
kibanaImageName = "docker.elastic.co/kibana/kibana"
logstashImageName = "docker.elastic.co/logstash/logstash"
Expand All @@ -37,9 +42,12 @@ const (
var (
elasticAgentCompleteFirstSupportedVersion = semver.MustParse(stackVersion715)
elasticAgentCompleteOwnNamespaceVersion = semver.MustParse(stackVersion820)
elasticAgentWolfiVersion = semver.MustParse(stackVersion8160)

// ProfileNameEnvVar is the name of the environment variable to set the default profile
ProfileNameEnvVar = environment.WithElasticPackagePrefix("PROFILE")

disableElasticAgentWolfiEnvVar = environment.WithElasticPackagePrefix("DISABLE_ELASTIC_AGENT_WOLFI")
)

func DefaultConfiguration() *ApplicationConfiguration {
Expand Down Expand Up @@ -150,6 +158,16 @@ func selectElasticAgentImageName(version string) string {
logger.Errorf("stack version not in semver format (value: %s): %v", v, err)
return elasticAgentImageName
}

// TODO: Set as default using wolfi images once they are available
disableWolfiImages := true
valueEnv, ok := os.LookupEnv(disableElasticAgentWolfiEnvVar)
if ok && strings.ToLower(valueEnv) != "true" {
disableWolfiImages = false
}
if !disableWolfiImages && !v.LessThan(elasticAgentWolfiVersion) {
return elasticAgentWolfiImageName
}
if !v.LessThan(elasticAgentCompleteOwnNamespaceVersion) {
return elasticAgentCompleteImageName
}
Expand Down
20 changes: 20 additions & 0 deletions internal/install/application_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,23 @@ func TestSelectElasticAgentImageName_NextStackInOwnNamespace(t *testing.T) {
selected := selectElasticAgentImageName(version)
assert.Equal(t, selected, elasticAgentCompleteImageName)
}

func TestSelectElasticAgentImageName_WolfiImage(t *testing.T) {
version := "8.16.0-SNAPSHOT"
selected := selectElasticAgentImageName(version)
// TODO: update once changed the default value
assert.Equal(t, selected, elasticAgentCompleteImageName)
}

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