Skip to content
This repository was archived by the owner on Mar 20, 2026. It is now read-only.

Commit 0790e5e

Browse files
Generate correctly the MinIO scrape configs for Multi Tenants scenarios (#2456)
* Simplify check for existing MinIO scrape configs for current tenant * Allow all actions to prometheuses and prometheusagents resources through kustomize
1 parent d3e77e0 commit 0790e5e

5 files changed

Lines changed: 329 additions & 60 deletions

File tree

‎pkg/apis/minio.min.io/v2/names.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (t *Tenant) PrometheusConfigJobName() string {
207207
// PrometheusOperatorAddlConfigJobName returns the name of the prometheus job
208208
// when prometheus operator is enabled
209209
func (t *Tenant) PrometheusOperatorAddlConfigJobName() string {
210-
return fmt.Sprintf("%s-minio-job", t.Name)
210+
return fmt.Sprintf("%s-%s-minio-job", t.Name, t.Namespace)
211211
}
212212

213213
// PrometheusConfigMapName returns name of the config map for Prometheus.

‎pkg/controller/main-controller.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ func NewController(
304304
}
305305
controller.enqueueTenant(newObj)
306306
},
307+
// Enqueue tenant to perform some delete handling actions
308+
// during reconciliation
309+
DeleteFunc: controller.enqueueTenant,
307310
})
308311

309312
// Set up an event handler for when StatefulSet resources change. This

‎pkg/controller/prometheus.go‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,13 @@ func (c *Controller) checkAndCreatePrometheusAddlConfig(ctx context.Context, ten
140140
}
141141

142142
promCfg := configmaps.GetPrometheusConfig(tenant, accessKey, secretKey)
143+
minIOScrapeConfigs := make([]configmaps.ScrapeConfig, len(promCfg.ScrapeConfigs))
144+
copy(minIOScrapeConfigs, promCfg.ScrapeConfigs)
143145

144146
// If the secret is not found, create the secret
145147
if k8serrors.IsNotFound(err) {
146148
klog.Infof("Adding MinIO tenant %s/%s Prometheus scrape config", ns, tenant.Name)
147-
scrapeCfgYaml, err := yaml.Marshal(&promCfg.ScrapeConfigs)
149+
scrapeCfgYaml, err := yaml.Marshal(&minIOScrapeConfigs)
148150
if err != nil {
149151
return err
150152
}
@@ -168,33 +170,47 @@ func (c *Controller) checkAndCreatePrometheusAddlConfig(ctx context.Context, ten
168170
if err != nil {
169171
return err
170172
}
171-
// get other scrape configs
173+
// Get all non-MinIO scrape configs, as well as MinIO scrape configs for other tenants
172174
for _, sc := range scrapeConfigs {
173175
if !strings.HasPrefix(sc.JobName, tenant.PrometheusOperatorAddlConfigJobName()) {
174176
expectedScrapeConfigs = append(expectedScrapeConfigs, sc)
175177
}
176178
}
177-
ignoreScrapeConfigsIndex := len(expectedScrapeConfigs)
178-
expectedScrapeConfigs = append(expectedScrapeConfigs, promCfg.ScrapeConfigs...)
179+
180+
// Add the expected MinIO scrape configs for the current tenant
181+
expectedScrapeConfigs = append(expectedScrapeConfigs, minIOScrapeConfigs...)
182+
183+
// Verify that all expected scrape configs are present in the installed configs
179184
updateScrapeConfig := false
180185
if len(scrapeConfigs) != len(expectedScrapeConfigs) {
181186
updateScrapeConfig = true
182187
} else {
183-
for i := range scrapeConfigs {
184-
// can't compare that is generated by operator
185-
if i < ignoreScrapeConfigsIndex {
186-
continue
187-
}
188-
if scrapeConfigs[i].JobName != expectedScrapeConfigs[i].JobName ||
189-
scrapeConfigs[i].MetricsPath != expectedScrapeConfigs[i].MetricsPath ||
190-
scrapeConfigs[i].Scheme != expectedScrapeConfigs[i].Scheme ||
191-
!reflect.DeepEqual(scrapeConfigs[i].TLSConfig, expectedScrapeConfigs[i].TLSConfig) ||
192-
!reflect.DeepEqual(scrapeConfigs[i].StaticConfigs, expectedScrapeConfigs[i].StaticConfigs) {
193-
updateScrapeConfig = true
194-
break
188+
// Verify that all MinIO scrape configs for the current tenant
189+
// are included in the installed configs
190+
for _, minIOConfig := range minIOScrapeConfigs {
191+
configMatched := false
192+
for _, config := range scrapeConfigs {
193+
if minIOConfig.JobName == config.JobName {
194+
if config.MetricsPath != minIOConfig.MetricsPath ||
195+
config.Scheme != minIOConfig.Scheme ||
196+
!reflect.DeepEqual(config.TLSConfig, minIOConfig.TLSConfig) ||
197+
!reflect.DeepEqual(config.StaticConfigs, minIOConfig.StaticConfigs) {
198+
updateScrapeConfig = true
199+
break
200+
}
201+
accKey, err := miniov2.GetAccessKeyFromBearerToken(config.BearerToken, secretKey)
202+
if err != nil || accKey != accessKey {
203+
updateScrapeConfig = true
204+
break
205+
}
206+
207+
configMatched = true
208+
break
209+
}
195210
}
196-
accKey, _ := miniov2.GetAccessKeyFromBearerToken(scrapeConfigs[i].BearerToken, secretKey)
197-
if accKey != accessKey {
211+
// Update the installed scrape configs if any MinIO configs for
212+
// the current tenant are missing
213+
if !configMatched {
198214
updateScrapeConfig = true
199215
break
200216
}
@@ -255,6 +271,7 @@ func (c *Controller) deletePrometheusAddlConfig(ctx context.Context, tenant *min
255271
return err
256272
}
257273
for _, sc := range scrapeConfigs {
274+
// Get all non-MinIO scrape configs, as well as MinIO scrape configs for other tenants
258275
if !strings.HasPrefix(sc.JobName, tenant.PrometheusOperatorAddlConfigJobName()) {
259276
exceptedScrapeConfigs = append(exceptedScrapeConfigs, sc)
260277
}

0 commit comments

Comments
 (0)