@@ -48,11 +48,18 @@ type ClusterMonitoringConfiguration struct {
48
48
K8sPrometheusAdapter * K8sPrometheusAdapter `json:"k8sPrometheusAdapter"`
49
49
ThanosQuerierConfig * ThanosQuerierConfig `json:"thanosQuerier"`
50
50
UserWorkloadEnabled * bool `json:"enableUserWorkload"`
51
- // TODO: Remove in 4.7 release.
52
- PrometheusUserWorkloadConfig * PrometheusK8sConfig `json:"prometheusUserWorkload"`
53
- PrometheusOperatorUserWorkloadConfig * PrometheusOperatorConfig `json:"prometheusOperatorUserWorkload"`
54
- ThanosRulerConfig * ThanosRulerConfig `json:"thanosRuler"`
55
- UserWorkloadConfig * UserWorkloadConfig `json:"techPreviewUserWorkload"`
51
+ }
52
+
53
+ // TODO: Remove in 4.7 release.
54
+ type UserWorkloadLegacyConfiguration struct {
55
+ UserWorkloadConfiguration
56
+ TechPreviewUserWorkload * UserWorkloadConfig `json:"techPreviewUserWorkload"`
57
+ }
58
+
59
+ type UserWorkloadConfiguration struct {
60
+ PrometheusOperator * PrometheusOperatorConfig `json:"prometheusOperator"`
61
+ Prometheus * PrometheusK8sConfig `json:"prometheus"`
62
+ ThanosRuler * ThanosRulerConfig `json:"thanosRuler"`
56
63
}
57
64
58
65
type Images struct {
@@ -182,18 +189,36 @@ func (cfg *TelemeterClientConfig) IsEnabled() bool {
182
189
}
183
190
184
191
func NewConfig (content io.Reader ) (* Config , error ) {
185
- c := Config {}
192
+ c := & Config {}
186
193
cmc := ClusterMonitoringConfiguration {}
187
194
err := k8syaml .NewYAMLOrJSONDecoder (content , 4096 ).Decode (& cmc )
188
195
if err != nil {
189
196
return nil , err
190
197
}
191
198
c .ClusterMonitoringConfiguration = & cmc
192
- res := & c
193
- res .applyDefaults ()
199
+ c .applyDefaults ()
194
200
c .UserWorkloadConfiguration = NewDefaultUserWorkloadMonitoringConfig ()
195
201
196
- return res , nil
202
+ legacy := & UserWorkloadLegacyConfiguration {}
203
+ err = k8syaml .NewYAMLOrJSONDecoder (content , 4096 ).Decode (legacy )
204
+ if err != nil {
205
+ return nil , err
206
+ }
207
+ if legacy .PrometheusOperator != nil {
208
+ c .UserWorkloadConfiguration .PrometheusOperator = legacy .PrometheusOperator
209
+ }
210
+ if legacy .Prometheus != nil {
211
+ c .UserWorkloadConfiguration .Prometheus = legacy .Prometheus
212
+ }
213
+ if legacy .ThanosRuler != nil {
214
+ c .UserWorkloadConfiguration .ThanosRuler = legacy .ThanosRuler
215
+ }
216
+ if legacy .TechPreviewUserWorkload != nil && legacy .TechPreviewUserWorkload .Enabled != nil && * legacy .TechPreviewUserWorkload .Enabled {
217
+ enabled := true
218
+ c .ClusterMonitoringConfiguration .UserWorkloadEnabled = & enabled
219
+ }
220
+
221
+ return c , nil
197
222
}
198
223
199
224
func (c * Config ) applyDefaults () {
@@ -206,31 +231,19 @@ func (c *Config) applyDefaults() {
206
231
if c .ClusterMonitoringConfiguration .PrometheusOperatorConfig == nil {
207
232
c .ClusterMonitoringConfiguration .PrometheusOperatorConfig = & PrometheusOperatorConfig {}
208
233
}
209
- if c .ClusterMonitoringConfiguration .PrometheusOperatorUserWorkloadConfig == nil {
210
- c .ClusterMonitoringConfiguration .PrometheusOperatorUserWorkloadConfig = & PrometheusOperatorConfig {}
211
- }
212
234
if c .ClusterMonitoringConfiguration .PrometheusK8sConfig == nil {
213
235
c .ClusterMonitoringConfiguration .PrometheusK8sConfig = & PrometheusK8sConfig {}
214
236
}
215
237
if c .ClusterMonitoringConfiguration .PrometheusK8sConfig .Retention == "" {
216
238
c .ClusterMonitoringConfiguration .PrometheusK8sConfig .Retention = "15d"
217
239
}
218
- if c .ClusterMonitoringConfiguration .PrometheusUserWorkloadConfig == nil {
219
- c .ClusterMonitoringConfiguration .PrometheusUserWorkloadConfig = & PrometheusK8sConfig {}
220
- }
221
- if c .ClusterMonitoringConfiguration .PrometheusUserWorkloadConfig .Retention == "" {
222
- c .ClusterMonitoringConfiguration .PrometheusUserWorkloadConfig .Retention = "15d"
223
- }
224
240
if c .ClusterMonitoringConfiguration .AlertmanagerMainConfig == nil {
225
241
c .ClusterMonitoringConfiguration .AlertmanagerMainConfig = & AlertmanagerMainConfig {}
226
242
}
227
243
if c .ClusterMonitoringConfiguration .UserWorkloadEnabled == nil {
228
244
disable := false
229
245
c .ClusterMonitoringConfiguration .UserWorkloadEnabled = & disable
230
246
}
231
- if c .ClusterMonitoringConfiguration .ThanosRulerConfig == nil {
232
- c .ClusterMonitoringConfiguration .ThanosRulerConfig = & ThanosRulerConfig {}
233
- }
234
247
if c .ClusterMonitoringConfiguration .ThanosQuerierConfig == nil {
235
248
c .ClusterMonitoringConfiguration .ThanosQuerierConfig = & ThanosQuerierConfig {}
236
249
}
@@ -257,9 +270,6 @@ func (c *Config) applyDefaults() {
257
270
if c .ClusterMonitoringConfiguration .EtcdConfig == nil {
258
271
c .ClusterMonitoringConfiguration .EtcdConfig = & EtcdConfig {}
259
272
}
260
- if c .ClusterMonitoringConfiguration .UserWorkloadConfig == nil {
261
- c .ClusterMonitoringConfiguration .UserWorkloadConfig = & UserWorkloadConfig {}
262
- }
263
273
}
264
274
265
275
func (c * Config ) SetImages (images map [string ]string ) {
@@ -378,12 +388,6 @@ func NewDefaultConfig() *Config {
378
388
return c
379
389
}
380
390
381
- type UserWorkloadConfiguration struct {
382
- PrometheusOperator * PrometheusOperatorConfig `json:"prometheusOperator"`
383
- Prometheus * PrometheusK8sConfig `json:"prometheus"`
384
- ThanosRuler * ThanosRulerConfig `json:"thanosRuler"`
385
- }
386
-
387
391
func (u * UserWorkloadConfiguration ) applyDefaults () {
388
392
if u .PrometheusOperator == nil {
389
393
u .PrometheusOperator = & PrometheusOperatorConfig {}
@@ -420,18 +424,5 @@ func NewDefaultUserWorkloadMonitoringConfig() *UserWorkloadConfiguration {
420
424
// IsUserWorkloadEnabled checks if user workload monitoring is
421
425
// enabled on old or new configuration.
422
426
func (c * Config ) IsUserWorkloadEnabled () bool {
423
- if * c .ClusterMonitoringConfiguration .UserWorkloadEnabled == true {
424
- return true
425
- }
426
-
427
- return c .ClusterMonitoringConfiguration .UserWorkloadConfig .isEnabled ()
428
- }
429
-
430
- // isEnabled returns the underlying value of the `Enabled` boolean pointer.
431
- // It defaults to false if the pointer is nil.
432
- func (c * UserWorkloadConfig ) isEnabled () bool {
433
- if c .Enabled == nil {
434
- return false
435
- }
436
- return * c .Enabled
427
+ return * c .ClusterMonitoringConfiguration .UserWorkloadEnabled
437
428
}
0 commit comments