Skip to content

Commit

Permalink
Rename system test configuration setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodm committed Aug 28, 2024
1 parent 905207f commit 34c21ef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions internal/agentdeployer/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (d *DockerComposeAgentDeployer) installDockerCompose(agentInfo AgentInfo) (
stackVersion = config.Parameters[stack.ParamServerlessLocalStackVersion]
}

agentImage, err := selectElasticAgentImage(stackVersion, agentInfo.Agent.Type)
agentImage, err := selectElasticAgentImage(stackVersion, agentInfo.Agent.BaseImage)
if err != nil {
return "", nil
}
Expand Down Expand Up @@ -303,8 +303,8 @@ func (d *DockerComposeAgentDeployer) installDockerCompose(agentInfo AgentInfo) (
return customAgentDir, nil
}

func selectElasticAgentImage(stackVersion, agentImageType string) (string, error) {
appConfig, err := install.Configuration(install.OptionWithAgentImageType(agentImageType), install.OptionWithStackVersion(stackVersion))
func selectElasticAgentImage(stackVersion, agentBaseImage string) (string, error) {
appConfig, err := install.Configuration(install.OptionWithAgentBaseImage(agentBaseImage), install.OptionWithStackVersion(stackVersion))
if err != nil {
return "", fmt.Errorf("can't read application configuration: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/agentdeployer/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type AgentScript struct {
type AgentSettings struct {
// User user to run Elastic Agent process
User string `config:"user"`
// Type elastic-agent image type to be used for testing (allowed values complete, default or empty)
Type string `config:"type"`
// BaseImage elastic-agent base image to be used for testing
BaseImage string `config:"base_image"`
// PidMode selects the host PID mode
// (From docker-compose docs) Turns on sharing between container and the host
// operating system the PID address space
Expand Down
18 changes: 9 additions & 9 deletions internal/install/application_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func DefaultConfiguration() *ApplicationConfiguration {
// ApplicationConfiguration represents the configuration of the elastic-package.
type ApplicationConfiguration struct {
c configFile
agentImageType string
agentBaseImage string
stackVersion string
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func (ir ImageRefs) AsEnv() []string {
// StackImageRefs function selects the appropriate set of Docker image references for the given stack version.
func (ac *ApplicationConfiguration) StackImageRefs() ImageRefs {
refs := ac.c.Stack.ImageRefOverridesForVersion(ac.stackVersion)
refs.ElasticAgent = stringOrDefault(refs.ElasticAgent, fmt.Sprintf("%s:%s", selectElasticAgentImageName(ac.stackVersion, ac.agentImageType), ac.stackVersion))
refs.ElasticAgent = stringOrDefault(refs.ElasticAgent, fmt.Sprintf("%s:%s", selectElasticAgentImageName(ac.stackVersion, ac.agentBaseImage), ac.stackVersion))
refs.Elasticsearch = stringOrDefault(refs.Elasticsearch, fmt.Sprintf("%s:%s", elasticsearchImageName, ac.stackVersion))
refs.Kibana = stringOrDefault(refs.Kibana, fmt.Sprintf("%s:%s", kibanaImageName, ac.stackVersion))
refs.Logstash = stringOrDefault(refs.Logstash, fmt.Sprintf("%s:%s", logstashImageName, ac.stackVersion))
Expand All @@ -150,7 +150,7 @@ func (ac *ApplicationConfiguration) SetCurrentProfile(name string) {

// selectElasticAgentImageName function returns the appropriate image name for Elastic-Agent depending on the stack version.
// This is mandatory as "elastic-agent-complete" is available since 7.15.0-SNAPSHOT.
func selectElasticAgentImageName(version, agentImageType string) string {
func selectElasticAgentImageName(version, agentBaseImage string) string {
if version == "" { // as version is optional and can be empty
return elasticAgentImageName
}
Expand All @@ -168,7 +168,7 @@ func selectElasticAgentImageName(version, agentImageType string) string {
disableWolfiImages = false
}
switch {
case !disableWolfiImages && !v.LessThan(elasticAgentWolfiVersion) && agentImageType != "complete":
case !disableWolfiImages && !v.LessThan(elasticAgentWolfiVersion) && agentBaseImage != "complete":
return elasticAgentWolfiImageName
case !v.LessThan(elasticAgentCompleteOwnNamespaceVersion):
return elasticAgentCompleteImageName
Expand All @@ -180,16 +180,16 @@ func selectElasticAgentImageName(version, agentImageType string) string {
}

type configurationOptions struct {
agentImageType string
agentBaseImage string
stackVersion string
}

type ConfigurationOption func(*configurationOptions)

// OptionWithAgentImageType sets the agent image type to be used.
func OptionWithAgentImageType(agentImageType string) ConfigurationOption {
// OptionWithAgentBaseImage sets the agent image type to be used.
func OptionWithAgentBaseImage(agentBaseImage string) ConfigurationOption {
return func(opts *configurationOptions) {
opts.agentImageType = agentImageType
opts.agentBaseImage = agentBaseImage
}
}

Expand Down Expand Up @@ -228,7 +228,7 @@ func Configuration(options ...ConfigurationOption) (*ApplicationConfiguration, e

configuration := ApplicationConfiguration{
c: c,
agentImageType: configOptions.agentImageType,
agentBaseImage: configOptions.agentBaseImage,
stackVersion: configOptions.stackVersion,
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ 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.Type) {
return agentdeployer.AgentInfo{}, fmt.Errorf("invalid value for agent.type")
if !slices.Contains([]string{"", "default", "complete"}, info.Agent.BaseImage) {
return agentdeployer.AgentInfo{}, fmt.Errorf("invalid value for agent.base_image")
}

return info, nil
Expand Down

0 comments on commit 34c21ef

Please sign in to comment.