Skip to content

Commit

Permalink
Fix: use two Docker images of elastic-agent (#521)
Browse files Browse the repository at this point in the history
* Define two different images

* Fix
  • Loading branch information
mtojek authored Sep 22, 2021
1 parent d39f666 commit 4c8b1ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
18 changes: 17 additions & 1 deletion internal/install/application_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import (
"os"
"path/filepath"

"github.com/Masterminds/semver"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"

"github.com/elastic/elastic-package/internal/configuration/locations"
"github.com/elastic/elastic-package/internal/logger"
)

var elasticAgentCompleteFirstSupportedVersion = semver.MustParse("7.15.0-SNAPSHOT")

// ApplicationConfiguration represents the configuration of the elastic-package.
type ApplicationConfiguration struct {
c configFile
Expand Down Expand Up @@ -60,12 +64,24 @@ func (ac *ApplicationConfiguration) DefaultStackImageRefs() ImageRefs {
// StackImageRefs function selects the appropriate set of Docker image references for the given stack version.
func (ac *ApplicationConfiguration) StackImageRefs(version string) ImageRefs {
refs := ac.c.Stack.ImageRefOverridesForVersion(version)
refs.ElasticAgent = stringOrDefault(refs.ElasticAgent, fmt.Sprintf("%s:%s", elasticAgentImageName, version))
refs.ElasticAgent = stringOrDefault(refs.ElasticAgent, fmt.Sprintf("%s:%s", selectElasticAgentImageName(version), version))
refs.Elasticsearch = stringOrDefault(refs.Elasticsearch, fmt.Sprintf("%s:%s", elasticsearchImageName, version))
refs.Kibana = stringOrDefault(refs.Kibana, fmt.Sprintf("%s:%s", kibanaImageName, version))
return refs
}

// 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 string) string {
v, err := semver.NewVersion(version)
if err != nil {
logger.Errorf("stack version not in semver format (value: %s): %v", v, err)
} else if !v.LessThan(elasticAgentCompleteFirstSupportedVersion) {
return elasticAgentCompleteImageName
}
return elasticAgentImageName
}

// Configuration function returns the elastic-package configuration.
func Configuration() (*ApplicationConfiguration, error) {
configPath, err := locations.NewLocationManager()
Expand Down
7 changes: 4 additions & 3 deletions internal/install/application_configuration_yml.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
package install

const (
elasticAgentImageName = "docker.elastic.co/beats/elastic-agent-complete"
elasticsearchImageName = "docker.elastic.co/elasticsearch/elasticsearch"
kibanaImageName = "docker.elastic.co/kibana/kibana"
elasticAgentImageName = "docker.elastic.co/beats/elastic-agent"
elasticAgentCompleteImageName = "docker.elastic.co/beats/elastic-agent-complete"
elasticsearchImageName = "docker.elastic.co/elasticsearch/elasticsearch"
kibanaImageName = "docker.elastic.co/kibana/kibana"
)

const applicationConfigurationYmlFile = "config.yml"
Expand Down

0 comments on commit 4c8b1ff

Please sign in to comment.