Skip to content

Commit 064533d

Browse files
authored
Set annotations and labels at Tenant level (#279)
on Tenant Creation request api
1 parent 1768af9 commit 064533d

File tree

6 files changed

+89
-73
lines changed

6 files changed

+89
-73
lines changed

models/create_tenant_request.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/zone.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

restapi/admin_tenants.go

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,6 @@ func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
293293
consoleImage = tenant.Spec.Console.Image
294294
}
295295

296-
if tenant.Spec.Metadata == nil {
297-
tenant.Spec.Metadata = &metav1.ObjectMeta{
298-
Annotations: map[string]string{},
299-
}
300-
}
301-
302296
return &models.Tenant{
303297
CreationDate: tenant.ObjectMeta.CreationTimestamp.String(),
304298
DeletionDate: deletion,
@@ -309,7 +303,7 @@ func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
309303
Namespace: tenant.ObjectMeta.Namespace,
310304
Image: tenant.Spec.Image,
311305
ConsoleImage: consoleImage,
312-
EnablePrometheus: isPrometheusEnabled(tenant.Spec.Metadata.Annotations),
306+
EnablePrometheus: isPrometheusEnabled(tenant.Annotations),
313307
}
314308
}
315309

@@ -507,7 +501,8 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
507501
//Construct a MinIO Instance with everything we are getting from parameters
508502
minInst := operator.Tenant{
509503
ObjectMeta: metav1.ObjectMeta{
510-
Name: tenantName,
504+
Name: tenantName,
505+
Labels: tenantReq.Labels,
511506
},
512507
Spec: operator.TenantSpec{
513508
Image: minioImage,
@@ -698,18 +693,14 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
698693
}
699694
// add annotations
700695
var annotations map[string]string
701-
if minInst.Spec.Metadata == nil {
702-
minInst.Spec.Metadata = &metav1.ObjectMeta{
703-
Annotations: map[string]string{},
704-
}
705-
}
696+
706697
if len(tenantReq.Annotations) > 0 {
707698
annotations = tenantReq.Annotations
708-
minInst.Spec.Metadata.Annotations = annotations
699+
minInst.Annotations = annotations
709700
}
710701
// set the zones if they are provided
711702
for _, zone := range tenantReq.Zones {
712-
zone, err := parseTenantZoneRequest(zone, annotations)
703+
zone, err := parseTenantZoneRequest(zone)
713704
if err != nil {
714705
return nil, prepareError(err)
715706
}
@@ -737,10 +728,10 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
737728
}
738729

739730
// prometheus annotations support
740-
if tenantReq.EnablePrometheus != nil && *tenantReq.EnablePrometheus && minInst.Spec.Metadata != nil && minInst.Spec.Metadata.Annotations != nil {
741-
minInst.Spec.Metadata.Annotations[prometheusPath] = "/minio/prometheus/metrics"
742-
minInst.Spec.Metadata.Annotations[prometheusPort] = fmt.Sprint(operator.MinIOPort)
743-
minInst.Spec.Metadata.Annotations[prometheusScrape] = "true"
731+
if tenantReq.EnablePrometheus != nil && *tenantReq.EnablePrometheus && minInst.Annotations != nil {
732+
minInst.Annotations[prometheusPath] = "/minio/prometheus/metrics"
733+
minInst.Annotations[prometheusPort] = fmt.Sprint(operator.MinIOPort)
734+
minInst.Annotations[prometheusScrape] = "true"
744735
}
745736

746737
// set console image if provided
@@ -875,20 +866,15 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
875866
}
876867

877868
// Prometheus Annotations
878-
if minInst.Spec.Metadata == nil {
879-
minInst.Spec.Metadata = &metav1.ObjectMeta{
880-
Annotations: map[string]string{},
881-
}
882-
}
883-
currentAnnotations := minInst.Spec.Metadata.Annotations
869+
currentAnnotations := minInst.Annotations
884870
prometheusAnnotations := map[string]string{
885871
prometheusPath: "/minio/prometheus/metrics",
886872
prometheusPort: fmt.Sprint(operator.MinIOPort),
887873
prometheusScrape: "true",
888874
}
889875
if params.Body.EnablePrometheus && minInst.Spec.Metadata != nil && currentAnnotations != nil {
890876
// add prometheus annotations to the tenant
891-
minInst.Spec.Metadata.Annotations = addAnnotations(currentAnnotations, prometheusAnnotations)
877+
minInst.Annotations = addAnnotations(currentAnnotations, prometheusAnnotations)
892878
// add prometheus annotations to the each zone
893879
if minInst.Spec.Zones != nil {
894880
for _, zone := range minInst.Spec.Zones {
@@ -898,7 +884,7 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
898884
}
899885
} else {
900886
// remove prometheus annotations to the tenant
901-
minInst.Spec.Metadata.Annotations = removeAnnotations(currentAnnotations, prometheusAnnotations)
887+
minInst.Annotations = removeAnnotations(currentAnnotations, prometheusAnnotations)
902888
// add prometheus annotations from each zone
903889
if minInst.Spec.Zones != nil {
904890
for _, zone := range minInst.Spec.Zones {
@@ -974,7 +960,7 @@ func addTenantZone(ctx context.Context, operatorClient OperatorClientI, params a
974960
}
975961

976962
zoneParams := params.Body
977-
zone, err := parseTenantZoneRequest(zoneParams, tenant.ObjectMeta.Annotations)
963+
zone, err := parseTenantZoneRequest(zoneParams)
978964
if err != nil {
979965
return err
980966
}
@@ -1062,7 +1048,7 @@ func getTenantUsageResponse(session *models.Principal, params admin_api.GetTenan
10621048

10631049
// parseTenantZoneRequest parse zone request and returns the equivalent
10641050
// operator.Zone object
1065-
func parseTenantZoneRequest(zoneParams *models.Zone, annotations map[string]string) (*operator.Zone, error) {
1051+
func parseTenantZoneRequest(zoneParams *models.Zone) (*operator.Zone, error) {
10661052
if zoneParams.VolumeConfiguration == nil {
10671053
return nil, errors.New("a volume configuration must be specified")
10681054
}
@@ -1211,14 +1197,12 @@ func parseTenantZoneRequest(zoneParams *models.Zone, annotations map[string]stri
12111197
// Pass annotations to the volume
12121198
vct := &corev1.PersistentVolumeClaim{
12131199
ObjectMeta: metav1.ObjectMeta{
1214-
Name: "data",
1215-
Labels: zoneParams.VolumeConfiguration.Labels,
1200+
Name: "data",
1201+
Labels: zoneParams.VolumeConfiguration.Labels,
1202+
Annotations: zoneParams.VolumeConfiguration.Annotations,
12161203
},
12171204
Spec: volTemp,
12181205
}
1219-
if len(annotations) > 0 {
1220-
vct.ObjectMeta.Annotations = annotations
1221-
}
12221206

12231207
zone := &operator.Zone{
12241208
Name: zoneParams.Name,
@@ -1512,16 +1496,10 @@ func updateTenantZones(
15121496
return nil, err
15131497
}
15141498

1515-
if minInst.Spec.Metadata == nil {
1516-
minInst.Spec.Metadata = &metav1.ObjectMeta{
1517-
Annotations: map[string]string{},
1518-
}
1519-
}
1520-
15211499
// set the zones if they are provided
15221500
var newZoneArray []operator.Zone
15231501
for _, zone := range zonesReq {
1524-
zone, err := parseTenantZoneRequest(zone, minInst.Spec.Metadata.Annotations)
1502+
zone, err := parseTenantZoneRequest(zone)
15251503
if err != nil {
15261504
return nil, err
15271505
}

restapi/admin_tenants_test.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ func Test_TenantInfo(t *testing.T) {
331331
Name: "tenant1",
332332
Namespace: "minio-ns",
333333
DeletionTimestamp: &testTimeStamp,
334+
Annotations: map[string]string{
335+
prometheusPath: "some/path",
336+
prometheusPort: "other/path",
337+
prometheusScrape: "other/path",
338+
},
334339
},
335340
Spec: operator.TenantSpec{
336341
Zones: []operator.Zone{
@@ -351,13 +356,6 @@ func Test_TenantInfo(t *testing.T) {
351356
},
352357
},
353358
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
354-
Metadata: &metav1.ObjectMeta{
355-
Annotations: map[string]string{
356-
prometheusPath: "some/path",
357-
prometheusPort: "other/path",
358-
prometheusScrape: "other/path",
359-
},
360-
},
361359
},
362360
Status: operator.TenantStatus{
363361
CurrentState: "ready",
@@ -396,16 +394,14 @@ func Test_TenantInfo(t *testing.T) {
396394
CreationTimestamp: testTimeStamp,
397395
Name: "tenant1",
398396
Namespace: "minio-ns",
397+
Annotations: map[string]string{
398+
prometheusPath: "some/path",
399+
prometheusScrape: "other/path",
400+
},
399401
},
400402
Spec: operator.TenantSpec{
401403
Zones: []operator.Zone{},
402404
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
403-
Metadata: &metav1.ObjectMeta{
404-
Annotations: map[string]string{
405-
prometheusPath: "some/path",
406-
prometheusScrape: "other/path",
407-
},
408-
},
409405
},
410406
Status: operator.TenantStatus{
411407
CurrentState: "ready",
@@ -430,16 +426,14 @@ func Test_TenantInfo(t *testing.T) {
430426
CreationTimestamp: testTimeStamp,
431427
Name: "tenant1",
432428
Namespace: "minio-ns",
429+
Annotations: map[string]string{
430+
prometheusPath: "some/path",
431+
prometheusScrape: "other/path",
432+
},
433433
},
434434
Spec: operator.TenantSpec{
435435
Zones: []operator.Zone{},
436436
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
437-
Metadata: &metav1.ObjectMeta{
438-
Annotations: map[string]string{
439-
prometheusPath: "some/path",
440-
prometheusScrape: "other/path",
441-
},
442-
},
443437
Console: &operator.ConsoleConfiguration{
444438
Image: "minio/console:master",
445439
},

restapi/embedded_spec.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)