Skip to content

Commit 28ac29c

Browse files
authored
Add storageClass as part of tenant info api response (#196)
1 parent 76f7c54 commit 28ac29c

File tree

6 files changed

+98
-6
lines changed

6 files changed

+98
-6
lines changed

models/tenant.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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func getTenantInfo(minioInstance *operator.MinIOInstance, tenantInfo *usageInfo)
208208
Namespace: minioInstance.ObjectMeta.Namespace,
209209
Image: minioInstance.Spec.Image,
210210
UsedSize: tenantInfo.DisksUsage,
211+
StorageClass: swag.StringValue(minioInstance.Spec.VolumeClaimTemplate.Spec.StorageClassName),
211212
}
212213
}
213214

restapi/admin_tenants_test.go

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import (
2929
"github.com/minio/mcs/cluster"
3030
"github.com/minio/mcs/models"
3131
"github.com/minio/mcs/restapi/operations/admin_api"
32+
operator "github.com/minio/minio-operator/pkg/apis/operator.min.io/v1"
3233
v1 "github.com/minio/minio-operator/pkg/apis/operator.min.io/v1"
33-
"github.com/minio/minio/pkg/madmin"
3434
corev1 "k8s.io/api/core/v1"
35+
"k8s.io/apimachinery/pkg/api/resource"
3536
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3637
types "k8s.io/apimachinery/pkg/types"
3738
)
@@ -77,7 +78,7 @@ func (c k8sClientMock) getService(ctx context.Context, namespace, serviceName st
7778
return k8sclientGetServiceMock(ctx, namespace, serviceName, opts)
7879
}
7980

80-
func Test_TenantInfo(t *testing.T) {
81+
func Test_TenantInfoTenantAdminClient(t *testing.T) {
8182
ctx := context.Background()
8283
kClient := k8sClientMock{}
8384
type args struct {
@@ -92,7 +93,6 @@ func Test_TenantInfo(t *testing.T) {
9293
name string
9394
args args
9495
wantErr bool
95-
want madmin.AdminClient
9696
mockGetSecret func(ctx context.Context, namespace, secretName string, opts metav1.GetOptions) (*corev1.Secret, error)
9797
mockGetService func(ctx context.Context, namespace, serviceName string, opts metav1.GetOptions) (*corev1.Service, error)
9898
}{
@@ -240,11 +240,91 @@ func Test_TenantInfo(t *testing.T) {
240240
}
241241
t.Errorf("getTenantAdminClient() error = %v, wantErr %v", err, tt.wantErr)
242242
}
243-
if reflect.DeepEqual(got, tt.want) {
244-
t.Errorf("got %v want %v", got, tt.want)
243+
if got == nil {
244+
t.Errorf("getTenantAdminClient() expected type: *madmin.AdminClient, got: nil")
245245
}
246246
})
247+
}
248+
}
247249

250+
func Test_TenantInfo(t *testing.T) {
251+
testTimeStamp := metav1.Now()
252+
type args struct {
253+
minioInstance *operator.MinIOInstance
254+
tenantInfo *usageInfo
255+
}
256+
tests := []struct {
257+
name string
258+
args args
259+
want *models.Tenant
260+
}{
261+
{
262+
name: "Get tenant Info",
263+
args: args{
264+
minioInstance: &operator.MinIOInstance{
265+
ObjectMeta: metav1.ObjectMeta{
266+
CreationTimestamp: testTimeStamp,
267+
Name: "tenant1",
268+
Namespace: "minio-ns",
269+
},
270+
Spec: operator.MinIOInstanceSpec{
271+
Zones: []operator.Zone{
272+
{
273+
Name: "zone1",
274+
Servers: int32(2),
275+
},
276+
},
277+
VolumesPerServer: 4,
278+
VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
279+
Spec: corev1.PersistentVolumeClaimSpec{
280+
Resources: corev1.ResourceRequirements{
281+
Requests: map[corev1.ResourceName]resource.Quantity{
282+
corev1.ResourceStorage: resource.MustParse("1Mi"),
283+
},
284+
},
285+
StorageClassName: swag.String("standard"),
286+
},
287+
},
288+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
289+
},
290+
Status: operator.MinIOInstanceStatus{
291+
CurrentState: "ready",
292+
},
293+
},
294+
tenantInfo: &usageInfo{
295+
DisksUsage: 1024,
296+
},
297+
},
298+
want: &models.Tenant{
299+
CreationDate: testTimeStamp.String(),
300+
InstanceCount: 2, // number of servers
301+
Name: "tenant1",
302+
VolumesPerServer: int64(4),
303+
VolumeCount: int64(8),
304+
VolumeSize: int64(1048576),
305+
TotalSize: int64(8388608),
306+
ZoneCount: int64(1),
307+
CurrentState: "ready",
308+
Zones: []*models.Zone{
309+
{
310+
Name: swag.String("zone1"),
311+
Servers: swag.Int64(int64(2)),
312+
},
313+
},
314+
Namespace: "minio-ns",
315+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
316+
UsedSize: int64(1024),
317+
StorageClass: "standard",
318+
},
319+
},
320+
}
321+
for _, tt := range tests {
322+
t.Run(tt.name, func(t *testing.T) {
323+
got := getTenantInfo(tt.args.minioInstance, tt.args.tenantInfo)
324+
if !reflect.DeepEqual(got, tt.want) {
325+
t.Errorf("got %v want %v", got, tt.want)
326+
}
327+
})
248328
}
249329
}
250330

restapi/client-admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ func NewAdminClient(url, accessKey, secretKey string) (*madmin.AdminClient, *pro
4646
AppComments: []string{appName, runtime.GOOS, runtime.GOARCH},
4747
Insecure: false,
4848
})
49-
s3Client.SetCustomTransport(STSClient.Transport)
5049
if err != nil {
5150
return nil, err.Trace(url)
5251
}
52+
s3Client.SetCustomTransport(STSClient.Transport)
5353
return s3Client, nil
5454
}
5555

restapi/embedded_spec.go

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

swagger.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,8 @@ definitions:
17181718
used_size:
17191719
type: integer
17201720
format: int64
1721+
storage_class:
1722+
type: string
17211723

17221724
tenantList:
17231725
type: object

0 commit comments

Comments
 (0)