@@ -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