From 28ac29c1787349a92d49c3e7000b39a6c623550e Mon Sep 17 00:00:00 2001 From: Cesar N Date: Fri, 17 Jul 2020 09:49:44 -0700 Subject: [PATCH] Add storageClass as part of tenant info api response (#196) --- models/tenant.go | 3 ++ restapi/admin_tenants.go | 1 + restapi/admin_tenants_test.go | 90 +++++++++++++++++++++++++++++++++-- restapi/client-admin.go | 2 +- restapi/embedded_spec.go | 6 +++ swagger.yml | 2 + 6 files changed, 98 insertions(+), 6 deletions(-) diff --git a/models/tenant.go b/models/tenant.go index 68adce4953..15cd8eaeec 100644 --- a/models/tenant.go +++ b/models/tenant.go @@ -53,6 +53,9 @@ type Tenant struct { // namespace Namespace string `json:"namespace,omitempty"` + // storage class + StorageClass string `json:"storage_class,omitempty"` + // total size TotalSize int64 `json:"total_size,omitempty"` diff --git a/restapi/admin_tenants.go b/restapi/admin_tenants.go index d094b526ab..7452da4f94 100644 --- a/restapi/admin_tenants.go +++ b/restapi/admin_tenants.go @@ -208,6 +208,7 @@ func getTenantInfo(minioInstance *operator.MinIOInstance, tenantInfo *usageInfo) Namespace: minioInstance.ObjectMeta.Namespace, Image: minioInstance.Spec.Image, UsedSize: tenantInfo.DisksUsage, + StorageClass: swag.StringValue(minioInstance.Spec.VolumeClaimTemplate.Spec.StorageClassName), } } diff --git a/restapi/admin_tenants_test.go b/restapi/admin_tenants_test.go index 1d92b3b094..cc2f242145 100644 --- a/restapi/admin_tenants_test.go +++ b/restapi/admin_tenants_test.go @@ -29,9 +29,10 @@ import ( "github.com/minio/mcs/cluster" "github.com/minio/mcs/models" "github.com/minio/mcs/restapi/operations/admin_api" + operator "github.com/minio/minio-operator/pkg/apis/operator.min.io/v1" v1 "github.com/minio/minio-operator/pkg/apis/operator.min.io/v1" - "github.com/minio/minio/pkg/madmin" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" types "k8s.io/apimachinery/pkg/types" ) @@ -77,7 +78,7 @@ func (c k8sClientMock) getService(ctx context.Context, namespace, serviceName st return k8sclientGetServiceMock(ctx, namespace, serviceName, opts) } -func Test_TenantInfo(t *testing.T) { +func Test_TenantInfoTenantAdminClient(t *testing.T) { ctx := context.Background() kClient := k8sClientMock{} type args struct { @@ -92,7 +93,6 @@ func Test_TenantInfo(t *testing.T) { name string args args wantErr bool - want madmin.AdminClient mockGetSecret func(ctx context.Context, namespace, secretName string, opts metav1.GetOptions) (*corev1.Secret, error) mockGetService func(ctx context.Context, namespace, serviceName string, opts metav1.GetOptions) (*corev1.Service, error) }{ @@ -240,11 +240,91 @@ func Test_TenantInfo(t *testing.T) { } t.Errorf("getTenantAdminClient() error = %v, wantErr %v", err, tt.wantErr) } - if reflect.DeepEqual(got, tt.want) { - t.Errorf("got %v want %v", got, tt.want) + if got == nil { + t.Errorf("getTenantAdminClient() expected type: *madmin.AdminClient, got: nil") } }) + } +} +func Test_TenantInfo(t *testing.T) { + testTimeStamp := metav1.Now() + type args struct { + minioInstance *operator.MinIOInstance + tenantInfo *usageInfo + } + tests := []struct { + name string + args args + want *models.Tenant + }{ + { + name: "Get tenant Info", + args: args{ + minioInstance: &operator.MinIOInstance{ + ObjectMeta: metav1.ObjectMeta{ + CreationTimestamp: testTimeStamp, + Name: "tenant1", + Namespace: "minio-ns", + }, + Spec: operator.MinIOInstanceSpec{ + Zones: []operator.Zone{ + { + Name: "zone1", + Servers: int32(2), + }, + }, + VolumesPerServer: 4, + VolumeClaimTemplate: &corev1.PersistentVolumeClaim{ + Spec: corev1.PersistentVolumeClaimSpec{ + Resources: corev1.ResourceRequirements{ + Requests: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceStorage: resource.MustParse("1Mi"), + }, + }, + StorageClassName: swag.String("standard"), + }, + }, + Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z", + }, + Status: operator.MinIOInstanceStatus{ + CurrentState: "ready", + }, + }, + tenantInfo: &usageInfo{ + DisksUsage: 1024, + }, + }, + want: &models.Tenant{ + CreationDate: testTimeStamp.String(), + InstanceCount: 2, // number of servers + Name: "tenant1", + VolumesPerServer: int64(4), + VolumeCount: int64(8), + VolumeSize: int64(1048576), + TotalSize: int64(8388608), + ZoneCount: int64(1), + CurrentState: "ready", + Zones: []*models.Zone{ + { + Name: swag.String("zone1"), + Servers: swag.Int64(int64(2)), + }, + }, + Namespace: "minio-ns", + Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z", + UsedSize: int64(1024), + StorageClass: "standard", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := getTenantInfo(tt.args.minioInstance, tt.args.tenantInfo) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("got %v want %v", got, tt.want) + } + }) } } diff --git a/restapi/client-admin.go b/restapi/client-admin.go index 32f12cc8c4..5ddb92c1f8 100644 --- a/restapi/client-admin.go +++ b/restapi/client-admin.go @@ -46,10 +46,10 @@ func NewAdminClient(url, accessKey, secretKey string) (*madmin.AdminClient, *pro AppComments: []string{appName, runtime.GOOS, runtime.GOARCH}, Insecure: false, }) - s3Client.SetCustomTransport(STSClient.Transport) if err != nil { return nil, err.Trace(url) } + s3Client.SetCustomTransport(STSClient.Transport) return s3Client, nil } diff --git a/restapi/embedded_spec.go b/restapi/embedded_spec.go index 10266cdf84..60039b942c 100644 --- a/restapi/embedded_spec.go +++ b/restapi/embedded_spec.go @@ -2584,6 +2584,9 @@ func init() { "namespace": { "type": "string" }, + "storage_class": { + "type": "string" + }, "total_size": { "type": "integer", "format": "int64" @@ -5315,6 +5318,9 @@ func init() { "namespace": { "type": "string" }, + "storage_class": { + "type": "string" + }, "total_size": { "type": "integer", "format": "int64" diff --git a/swagger.yml b/swagger.yml index 548f942a5b..1868df1a49 100644 --- a/swagger.yml +++ b/swagger.yml @@ -1718,6 +1718,8 @@ definitions: used_size: type: integer format: int64 + storage_class: + type: string tenantList: type: object