@@ -71,7 +71,9 @@ func DefaultConfiguration() *ApplicationConfiguration {
71
71
72
72
// ApplicationConfiguration represents the configuration of the elastic-package.
73
73
type ApplicationConfiguration struct {
74
- c configFile
74
+ c configFile
75
+ agentBaseImage string
76
+ stackVersion string
75
77
}
76
78
77
79
type configFile struct {
@@ -119,12 +121,12 @@ func (ir ImageRefs) AsEnv() []string {
119
121
}
120
122
121
123
// 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 ))
128
130
return refs
129
131
}
130
132
@@ -148,7 +150,7 @@ func (ac *ApplicationConfiguration) SetCurrentProfile(name string) {
148
150
149
151
// selectElasticAgentImageName function returns the appropriate image name for Elastic-Agent depending on the stack version.
150
152
// 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 {
152
154
if version == "" { // as version is optional and can be empty
153
155
return elasticAgentImageName
154
156
}
@@ -164,20 +166,41 @@ func selectElasticAgentImageName(version string) string {
164
166
if ok && strings .ToLower (valueEnv ) != "false" {
165
167
disableWolfiImages = true
166
168
}
167
- if ! disableWolfiImages && ! v .LessThan (elasticAgentWolfiVersion ) {
169
+ switch {
170
+ case ! disableWolfiImages && ! v .LessThan (elasticAgentWolfiVersion ) && agentBaseImage != "complete" :
168
171
return elasticAgentWolfiImageName
169
- }
170
- if ! v .LessThan (elasticAgentCompleteOwnNamespaceVersion ) {
172
+ case ! v .LessThan (elasticAgentCompleteOwnNamespaceVersion ):
171
173
return elasticAgentCompleteImageName
172
- }
173
- if ! v .LessThan (elasticAgentCompleteFirstSupportedVersion ) {
174
+ case ! v .LessThan (elasticAgentCompleteFirstSupportedVersion ):
174
175
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
175
199
}
176
- return elasticAgentImageName
177
200
}
178
201
179
202
// Configuration function returns the elastic-package configuration.
180
- func Configuration () (* ApplicationConfiguration , error ) {
203
+ func Configuration (options ... ConfigurationOption ) (* ApplicationConfiguration , error ) {
181
204
configPath , err := locations .NewLocationManager ()
182
205
if err != nil {
183
206
return nil , fmt .Errorf ("can't read configuration directory: %w" , err )
@@ -197,9 +220,18 @@ func Configuration() (*ApplicationConfiguration, error) {
197
220
return nil , fmt .Errorf ("can't unmarshal configuration file: %w" , err )
198
221
}
199
222
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
203
235
}
204
236
205
237
func stringOrDefault (value string , defaultValue string ) string {
0 commit comments