Skip to content

Commit 5c2f413

Browse files
committed
Add storageClass as part of tenant info api response
1 parent 44551ac commit 5c2f413

File tree

5 files changed

+96
-6
lines changed

5 files changed

+96
-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: 84 additions & 6 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
}{
@@ -233,18 +233,96 @@ func Test_TenantInfo(t *testing.T) {
233233
k8sclientGetSecretMock = tt.mockGetSecret
234234
k8sclientGetServiceMock = tt.mockGetService
235235
t.Run(tt.name, func(t *testing.T) {
236-
got, err := getTenantAdminClient(tt.args.ctx, tt.args.client, tt.args.namespace, tt.args.tenantName, tt.args.serviceName, tt.args.scheme)
236+
_, err := getTenantAdminClient(tt.args.ctx, tt.args.client, tt.args.namespace, tt.args.tenantName, tt.args.serviceName, tt.args.scheme)
237237
if err != nil {
238238
if tt.wantErr {
239239
return
240240
}
241241
t.Errorf("getTenantAdminClient() error = %v, wantErr %v", err, tt.wantErr)
242242
}
243-
if reflect.DeepEqual(got, tt.want) {
243+
// we don't check the output
244+
})
245+
}
246+
}
247+
248+
func Test_TenantInfo(t *testing.T) {
249+
testTimeStamp := metav1.Now()
250+
type args struct {
251+
minioInstance *operator.MinIOInstance
252+
tenantInfo *usageInfo
253+
}
254+
tests := []struct {
255+
name string
256+
args args
257+
want *models.Tenant
258+
}{
259+
{
260+
name: "Get tenant Info",
261+
args: args{
262+
minioInstance: &operator.MinIOInstance{
263+
ObjectMeta: metav1.ObjectMeta{
264+
CreationTimestamp: testTimeStamp,
265+
Name: "tenant1",
266+
Namespace: "minio-ns",
267+
},
268+
Spec: operator.MinIOInstanceSpec{
269+
Zones: []operator.Zone{
270+
{
271+
Name: "zone1",
272+
Servers: int32(2),
273+
},
274+
},
275+
VolumesPerServer: 4,
276+
VolumeClaimTemplate: &corev1.PersistentVolumeClaim{
277+
Spec: corev1.PersistentVolumeClaimSpec{
278+
Resources: corev1.ResourceRequirements{
279+
Requests: map[corev1.ResourceName]resource.Quantity{
280+
corev1.ResourceStorage: resource.MustParse("1Mi"),
281+
},
282+
},
283+
StorageClassName: swag.String("standard"),
284+
},
285+
},
286+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
287+
},
288+
Status: operator.MinIOInstanceStatus{
289+
CurrentState: "ready",
290+
},
291+
},
292+
tenantInfo: &usageInfo{
293+
DisksUsage: 1024,
294+
},
295+
},
296+
want: &models.Tenant{
297+
CreationDate: testTimeStamp.String(),
298+
InstanceCount: 2, // number of servers
299+
Name: "tenant1",
300+
VolumesPerServer: int64(4),
301+
VolumeCount: int64(8),
302+
VolumeSize: int64(1048576),
303+
TotalSize: int64(8388608),
304+
ZoneCount: int64(1),
305+
CurrentState: "ready",
306+
Zones: []*models.Zone{
307+
{
308+
Name: swag.String("zone1"),
309+
Servers: swag.Int64(int64(2)),
310+
},
311+
},
312+
Namespace: "minio-ns",
313+
Image: "minio/minio:RELEASE.2020-06-14T18-32-17Z",
314+
UsedSize: int64(1024),
315+
StorageClass: "standard",
316+
},
317+
},
318+
}
319+
for _, tt := range tests {
320+
t.Run(tt.name, func(t *testing.T) {
321+
got := getTenantInfo(tt.args.minioInstance, tt.args.tenantInfo)
322+
if !reflect.DeepEqual(got, tt.want) {
244323
t.Errorf("got %v want %v", got, tt.want)
245324
}
246325
})
247-
248326
}
249327
}
250328

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)