Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions models/create_tenant_request.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions models/zone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 19 additions & 41 deletions restapi/admin_tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,6 @@ func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
consoleImage = tenant.Spec.Console.Image
}

if tenant.Spec.Metadata == nil {
tenant.Spec.Metadata = &metav1.ObjectMeta{
Annotations: map[string]string{},
}
}

return &models.Tenant{
CreationDate: tenant.ObjectMeta.CreationTimestamp.String(),
DeletionDate: deletion,
Expand All @@ -309,7 +303,7 @@ func getTenantInfo(tenant *operator.Tenant) *models.Tenant {
Namespace: tenant.ObjectMeta.Namespace,
Image: tenant.Spec.Image,
ConsoleImage: consoleImage,
EnablePrometheus: isPrometheusEnabled(tenant.Spec.Metadata.Annotations),
EnablePrometheus: isPrometheusEnabled(tenant.Annotations),
}
}

Expand Down Expand Up @@ -507,7 +501,8 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
//Construct a MinIO Instance with everything we are getting from parameters
minInst := operator.Tenant{
ObjectMeta: metav1.ObjectMeta{
Name: tenantName,
Name: tenantName,
Labels: tenantReq.Labels,
},
Spec: operator.TenantSpec{
Image: minioImage,
Expand Down Expand Up @@ -698,18 +693,14 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
}
// add annotations
var annotations map[string]string
if minInst.Spec.Metadata == nil {
minInst.Spec.Metadata = &metav1.ObjectMeta{
Annotations: map[string]string{},
}
}

if len(tenantReq.Annotations) > 0 {
annotations = tenantReq.Annotations
minInst.Spec.Metadata.Annotations = annotations
minInst.Annotations = annotations
}
// set the zones if they are provided
for _, zone := range tenantReq.Zones {
zone, err := parseTenantZoneRequest(zone, annotations)
zone, err := parseTenantZoneRequest(zone)
if err != nil {
return nil, prepareError(err)
}
Expand Down Expand Up @@ -737,10 +728,10 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
}

// prometheus annotations support
if tenantReq.EnablePrometheus != nil && *tenantReq.EnablePrometheus && minInst.Spec.Metadata != nil && minInst.Spec.Metadata.Annotations != nil {
minInst.Spec.Metadata.Annotations[prometheusPath] = "/minio/prometheus/metrics"
minInst.Spec.Metadata.Annotations[prometheusPort] = fmt.Sprint(operator.MinIOPort)
minInst.Spec.Metadata.Annotations[prometheusScrape] = "true"
if tenantReq.EnablePrometheus != nil && *tenantReq.EnablePrometheus && minInst.Annotations != nil {
minInst.Annotations[prometheusPath] = "/minio/prometheus/metrics"
minInst.Annotations[prometheusPort] = fmt.Sprint(operator.MinIOPort)
minInst.Annotations[prometheusScrape] = "true"
}

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

// Prometheus Annotations
if minInst.Spec.Metadata == nil {
minInst.Spec.Metadata = &metav1.ObjectMeta{
Annotations: map[string]string{},
}
}
currentAnnotations := minInst.Spec.Metadata.Annotations
currentAnnotations := minInst.Annotations
prometheusAnnotations := map[string]string{
prometheusPath: "/minio/prometheus/metrics",
prometheusPort: fmt.Sprint(operator.MinIOPort),
prometheusScrape: "true",
}
if params.Body.EnablePrometheus && minInst.Spec.Metadata != nil && currentAnnotations != nil {
// add prometheus annotations to the tenant
minInst.Spec.Metadata.Annotations = addAnnotations(currentAnnotations, prometheusAnnotations)
minInst.Annotations = addAnnotations(currentAnnotations, prometheusAnnotations)
// add prometheus annotations to the each zone
if minInst.Spec.Zones != nil {
for _, zone := range minInst.Spec.Zones {
Expand All @@ -898,7 +884,7 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
}
} else {
// remove prometheus annotations to the tenant
minInst.Spec.Metadata.Annotations = removeAnnotations(currentAnnotations, prometheusAnnotations)
minInst.Annotations = removeAnnotations(currentAnnotations, prometheusAnnotations)
// add prometheus annotations from each zone
if minInst.Spec.Zones != nil {
for _, zone := range minInst.Spec.Zones {
Expand Down Expand Up @@ -974,7 +960,7 @@ func addTenantZone(ctx context.Context, operatorClient OperatorClientI, params a
}

zoneParams := params.Body
zone, err := parseTenantZoneRequest(zoneParams, tenant.ObjectMeta.Annotations)
zone, err := parseTenantZoneRequest(zoneParams)
if err != nil {
return err
}
Expand Down Expand Up @@ -1062,7 +1048,7 @@ func getTenantUsageResponse(session *models.Principal, params admin_api.GetTenan

// parseTenantZoneRequest parse zone request and returns the equivalent
// operator.Zone object
func parseTenantZoneRequest(zoneParams *models.Zone, annotations map[string]string) (*operator.Zone, error) {
func parseTenantZoneRequest(zoneParams *models.Zone) (*operator.Zone, error) {
if zoneParams.VolumeConfiguration == nil {
return nil, errors.New("a volume configuration must be specified")
}
Expand Down Expand Up @@ -1211,14 +1197,12 @@ func parseTenantZoneRequest(zoneParams *models.Zone, annotations map[string]stri
// Pass annotations to the volume
vct := &corev1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: "data",
Labels: zoneParams.VolumeConfiguration.Labels,
Name: "data",
Labels: zoneParams.VolumeConfiguration.Labels,
Annotations: zoneParams.VolumeConfiguration.Annotations,
},
Spec: volTemp,
}
if len(annotations) > 0 {
vct.ObjectMeta.Annotations = annotations
}

zone := &operator.Zone{
Name: zoneParams.Name,
Expand Down Expand Up @@ -1512,16 +1496,10 @@ func updateTenantZones(
return nil, err
}

if minInst.Spec.Metadata == nil {
minInst.Spec.Metadata = &metav1.ObjectMeta{
Annotations: map[string]string{},
}
}

// set the zones if they are provided
var newZoneArray []operator.Zone
for _, zone := range zonesReq {
zone, err := parseTenantZoneRequest(zone, minInst.Spec.Metadata.Annotations)
zone, err := parseTenantZoneRequest(zone)
if err != nil {
return nil, err
}
Expand Down
32 changes: 13 additions & 19 deletions restapi/admin_tenants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ func Test_TenantInfo(t *testing.T) {
Name: "tenant1",
Namespace: "minio-ns",
DeletionTimestamp: &testTimeStamp,
Annotations: map[string]string{
prometheusPath: "some/path",
prometheusPort: "other/path",
prometheusScrape: "other/path",
},
},
Spec: operator.TenantSpec{
Zones: []operator.Zone{
Expand All @@ -351,13 +356,6 @@ func Test_TenantInfo(t *testing.T) {
},
},
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
Metadata: &metav1.ObjectMeta{
Annotations: map[string]string{
prometheusPath: "some/path",
prometheusPort: "other/path",
prometheusScrape: "other/path",
},
},
},
Status: operator.TenantStatus{
CurrentState: "ready",
Expand Down Expand Up @@ -396,16 +394,14 @@ func Test_TenantInfo(t *testing.T) {
CreationTimestamp: testTimeStamp,
Name: "tenant1",
Namespace: "minio-ns",
Annotations: map[string]string{
prometheusPath: "some/path",
prometheusScrape: "other/path",
},
},
Spec: operator.TenantSpec{
Zones: []operator.Zone{},
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
Metadata: &metav1.ObjectMeta{
Annotations: map[string]string{
prometheusPath: "some/path",
prometheusScrape: "other/path",
},
},
},
Status: operator.TenantStatus{
CurrentState: "ready",
Expand All @@ -430,16 +426,14 @@ func Test_TenantInfo(t *testing.T) {
CreationTimestamp: testTimeStamp,
Name: "tenant1",
Namespace: "minio-ns",
Annotations: map[string]string{
prometheusPath: "some/path",
prometheusScrape: "other/path",
},
},
Spec: operator.TenantSpec{
Zones: []operator.Zone{},
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
Metadata: &metav1.ObjectMeta{
Annotations: map[string]string{
prometheusPath: "some/path",
prometheusScrape: "other/path",
},
},
Console: &operator.ConsoleConfiguration{
Image: "minio/console:master",
},
Expand Down
30 changes: 30 additions & 0 deletions restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading