@@ -71,7 +71,9 @@ func DefaultConfiguration() *ApplicationConfiguration {
7171
7272// ApplicationConfiguration represents the configuration of the elastic-package.
7373type ApplicationConfiguration struct {
74- c configFile
74+ c configFile
75+ agentBaseImage string
76+ stackVersion string
7577}
7678
7779type configFile struct {
@@ -119,12 +121,12 @@ func (ir ImageRefs) AsEnv() []string {
119121}
120122
121123// StackImageRefs function selects the appropriate set of Docker image references for the given stack version.
122- func (ac * ApplicationConfiguration ) StackImageRefs (version string ) ImageRefs {
123- refs := ac .c .Stack .ImageRefOverridesForVersion (version )
124- refs .ElasticAgent = stringOrDefault (refs .ElasticAgent , fmt .Sprintf ("%s:%s" , selectElasticAgentImageName (version ), version ))
125- refs .Elasticsearch = stringOrDefault (refs .Elasticsearch , fmt .Sprintf ("%s:%s" , elasticsearchImageName , version ))
126- refs .Kibana = stringOrDefault (refs .Kibana , fmt .Sprintf ("%s:%s" , kibanaImageName , version ))
127- refs .Logstash = stringOrDefault (refs .Logstash , fmt .Sprintf ("%s:%s" , logstashImageName , version ))
124+ func (ac * ApplicationConfiguration ) StackImageRefs () ImageRefs {
125+ refs := ac .c .Stack .ImageRefOverridesForVersion (ac . stackVersion )
126+ refs .ElasticAgent = stringOrDefault (refs .ElasticAgent , fmt .Sprintf ("%s:%s" , selectElasticAgentImageName (ac . stackVersion , ac . agentBaseImage ), ac . stackVersion ))
127+ refs .Elasticsearch = stringOrDefault (refs .Elasticsearch , fmt .Sprintf ("%s:%s" , elasticsearchImageName , ac . stackVersion ))
128+ refs .Kibana = stringOrDefault (refs .Kibana , fmt .Sprintf ("%s:%s" , kibanaImageName , ac . stackVersion ))
129+ refs .Logstash = stringOrDefault (refs .Logstash , fmt .Sprintf ("%s:%s" , logstashImageName , ac . stackVersion ))
128130 return refs
129131}
130132
@@ -148,7 +150,7 @@ func (ac *ApplicationConfiguration) SetCurrentProfile(name string) {
148150
149151// selectElasticAgentImageName function returns the appropriate image name for Elastic-Agent depending on the stack version.
150152// This is mandatory as "elastic-agent-complete" is available since 7.15.0-SNAPSHOT.
151- func selectElasticAgentImageName (version string ) string {
153+ func selectElasticAgentImageName (version , agentBaseImage string ) string {
152154 if version == "" { // as version is optional and can be empty
153155 return elasticAgentImageName
154156 }
@@ -164,20 +166,41 @@ func selectElasticAgentImageName(version string) string {
164166 if ok && strings .ToLower (valueEnv ) != "false" {
165167 disableWolfiImages = true
166168 }
167- if ! disableWolfiImages && ! v .LessThan (elasticAgentWolfiVersion ) {
169+ switch {
170+ case ! disableWolfiImages && ! v .LessThan (elasticAgentWolfiVersion ) && agentBaseImage != "complete" :
168171 return elasticAgentWolfiImageName
169- }
170- if ! v .LessThan (elasticAgentCompleteOwnNamespaceVersion ) {
172+ case ! v .LessThan (elasticAgentCompleteOwnNamespaceVersion ):
171173 return elasticAgentCompleteImageName
172- }
173- if ! v .LessThan (elasticAgentCompleteFirstSupportedVersion ) {
174+ case ! v .LessThan (elasticAgentCompleteFirstSupportedVersion ):
174175 return elasticAgentCompleteLegacyImageName
176+ default :
177+ return elasticAgentImageName
178+ }
179+ }
180+
181+ type configurationOptions struct {
182+ agentBaseImage string
183+ stackVersion string
184+ }
185+
186+ type ConfigurationOption func (* configurationOptions )
187+
188+ // OptionWithAgentBaseImage sets the agent image type to be used.
189+ func OptionWithAgentBaseImage (agentBaseImage string ) ConfigurationOption {
190+ return func (opts * configurationOptions ) {
191+ opts .agentBaseImage = agentBaseImage
192+ }
193+ }
194+
195+ // OptionWithStackVersion sets the Elastic Stack version to be used.
196+ func OptionWithStackVersion (stackVersion string ) ConfigurationOption {
197+ return func (opts * configurationOptions ) {
198+ opts .stackVersion = stackVersion
175199 }
176- return elasticAgentImageName
177200}
178201
179202// Configuration function returns the elastic-package configuration.
180- func Configuration () (* ApplicationConfiguration , error ) {
203+ func Configuration (options ... ConfigurationOption ) (* ApplicationConfiguration , error ) {
181204 configPath , err := locations .NewLocationManager ()
182205 if err != nil {
183206 return nil , fmt .Errorf ("can't read configuration directory: %w" , err )
@@ -197,9 +220,18 @@ func Configuration() (*ApplicationConfiguration, error) {
197220 return nil , fmt .Errorf ("can't unmarshal configuration file: %w" , err )
198221 }
199222
200- return & ApplicationConfiguration {
201- c : c ,
202- }, nil
223+ configOptions := configurationOptions {}
224+ for _ , option := range options {
225+ option (& configOptions )
226+ }
227+
228+ configuration := ApplicationConfiguration {
229+ c : c ,
230+ agentBaseImage : configOptions .agentBaseImage ,
231+ stackVersion : configOptions .stackVersion ,
232+ }
233+
234+ return & configuration , nil
203235}
204236
205237func stringOrDefault (value string , defaultValue string ) string {
0 commit comments