@@ -257,9 +257,27 @@ func getTenant(ctx context.Context, operatorClient OperatorClientI, namespace, t
257
257
return minInst , nil
258
258
}
259
259
260
+ func isPrometheusEnabled (annotations map [string ]string ) bool {
261
+ if annotations == nil {
262
+ return false
263
+ }
264
+ // if one of the following prometheus annotations are not present
265
+ // we consider the tenant as not integrated with prometheus
266
+ if _ , ok := annotations [prometheusPath ]; ! ok {
267
+ return false
268
+ }
269
+ if _ , ok := annotations [prometheusPort ]; ! ok {
270
+ return false
271
+ }
272
+ if _ , ok := annotations [prometheusScrape ]; ! ok {
273
+ return false
274
+ }
275
+ return true
276
+ }
277
+
260
278
func getTenantInfo (tenant * operator.Tenant ) * models.Tenant {
261
279
var zones []* models.Zone
262
-
280
+ consoleImage := ""
263
281
var totalSize int64
264
282
for _ , z := range tenant .Spec .Zones {
265
283
zones = append (zones , parseTenantZone (& z ))
@@ -271,15 +289,27 @@ func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
271
289
deletion = tenant .ObjectMeta .DeletionTimestamp .String ()
272
290
}
273
291
292
+ if tenant .HasConsoleEnabled () {
293
+ consoleImage = tenant .Spec .Console .Image
294
+ }
295
+
296
+ if tenant .Spec .Metadata == nil {
297
+ tenant .Spec .Metadata = & metav1.ObjectMeta {
298
+ Annotations : map [string ]string {},
299
+ }
300
+ }
301
+
274
302
return & models.Tenant {
275
- CreationDate : tenant .ObjectMeta .CreationTimestamp .String (),
276
- DeletionDate : deletion ,
277
- Name : tenant .Name ,
278
- TotalSize : totalSize ,
279
- CurrentState : tenant .Status .CurrentState ,
280
- Zones : zones ,
281
- Namespace : tenant .ObjectMeta .Namespace ,
282
- Image : tenant .Spec .Image ,
303
+ CreationDate : tenant .ObjectMeta .CreationTimestamp .String (),
304
+ DeletionDate : deletion ,
305
+ Name : tenant .Name ,
306
+ TotalSize : totalSize ,
307
+ CurrentState : tenant .Status .CurrentState ,
308
+ Zones : zones ,
309
+ Namespace : tenant .ObjectMeta .Namespace ,
310
+ Image : tenant .Spec .Image ,
311
+ ConsoleImage : consoleImage ,
312
+ EnablePrometheus : isPrometheusEnabled (tenant .Spec .Metadata .Annotations ),
283
313
}
284
314
}
285
315
@@ -695,9 +725,9 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
695
725
696
726
// prometheus annotations support
697
727
if tenantReq .EnablePrometheus != nil && * tenantReq .EnablePrometheus && minInst .Spec .Metadata != nil && minInst .Spec .Metadata .Annotations != nil {
698
- minInst .Spec .Metadata .Annotations ["prometheus.io/path" ] = "/minio/prometheus/metrics"
699
- minInst .Spec .Metadata .Annotations ["prometheus.io/port" ] = fmt .Sprint (operator .MinIOPort )
700
- minInst .Spec .Metadata .Annotations ["prometheus.io/scrape" ] = "true"
728
+ minInst .Spec .Metadata .Annotations [prometheusPath ] = "/minio/prometheus/metrics"
729
+ minInst .Spec .Metadata .Annotations [prometheusPort ] = fmt .Sprint (operator .MinIOPort )
730
+ minInst .Spec .Metadata .Annotations [prometheusScrape ] = "true"
701
731
}
702
732
703
733
// set console image if provided
@@ -831,6 +861,40 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
831
861
}
832
862
}
833
863
864
+ // Prometheus Annotations
865
+ if minInst .Spec .Metadata == nil {
866
+ minInst .Spec .Metadata = & metav1.ObjectMeta {
867
+ Annotations : map [string ]string {},
868
+ }
869
+ }
870
+ currentAnnotations := minInst .Spec .Metadata .Annotations
871
+ prometheusAnnotations := map [string ]string {
872
+ prometheusPath : "/minio/prometheus/metrics" ,
873
+ prometheusPort : fmt .Sprint (operator .MinIOPort ),
874
+ prometheusScrape : "true" ,
875
+ }
876
+ if params .Body .EnablePrometheus && minInst .Spec .Metadata != nil && currentAnnotations != nil {
877
+ // add prometheus annotations to the tenant
878
+ minInst .Spec .Metadata .Annotations = addAnnotations (currentAnnotations , prometheusAnnotations )
879
+ // add prometheus annotations to the each zone
880
+ if minInst .Spec .Zones != nil {
881
+ for _ , zone := range minInst .Spec .Zones {
882
+ zoneAnnotations := zone .VolumeClaimTemplate .GetObjectMeta ().GetAnnotations ()
883
+ zone .VolumeClaimTemplate .GetObjectMeta ().SetAnnotations (addAnnotations (zoneAnnotations , prometheusAnnotations ))
884
+ }
885
+ }
886
+ } else {
887
+ // remove prometheus annotations to the tenant
888
+ minInst .Spec .Metadata .Annotations = removeAnnotations (currentAnnotations , prometheusAnnotations )
889
+ // add prometheus annotations from each zone
890
+ if minInst .Spec .Zones != nil {
891
+ for _ , zone := range minInst .Spec .Zones {
892
+ zoneAnnotations := zone .VolumeClaimTemplate .GetObjectMeta ().GetAnnotations ()
893
+ zone .VolumeClaimTemplate .GetObjectMeta ().SetAnnotations (removeAnnotations (zoneAnnotations , prometheusAnnotations ))
894
+ }
895
+ }
896
+ }
897
+
834
898
payloadBytes , err := json .Marshal (minInst )
835
899
if err != nil {
836
900
return err
@@ -842,6 +906,28 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
842
906
return nil
843
907
}
844
908
909
+ // addAnnotations will merge two annotation maps
910
+ func addAnnotations (annotationsOne , annotationsTwo map [string ]string ) map [string ]string {
911
+ if annotationsOne == nil {
912
+ annotationsOne = map [string ]string {}
913
+ }
914
+ for key , value := range annotationsTwo {
915
+ annotationsOne [key ] = value
916
+ }
917
+ return annotationsOne
918
+ }
919
+
920
+ // removeAnnotations will remove keys from the first annotations map based on the second one
921
+ func removeAnnotations (annotationsOne , annotationsTwo map [string ]string ) map [string ]string {
922
+ if annotationsOne == nil {
923
+ annotationsOne = map [string ]string {}
924
+ }
925
+ for key := range annotationsTwo {
926
+ delete (annotationsOne , key )
927
+ }
928
+ return annotationsOne
929
+ }
930
+
845
931
func getUpdateTenantResponse (session * models.Principal , params admin_api.UpdateTenantParams ) * models.Error {
846
932
ctx := context .Background ()
847
933
opClientClientSet , err := cluster .OperatorClient (session .SessionToken )
0 commit comments