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/tenant.go

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

1 change: 1 addition & 0 deletions restapi/admin_tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
90 changes: 85 additions & 5 deletions restapi/admin_tenants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}{
Expand Down Expand Up @@ -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)
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion restapi/client-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions restapi/embedded_spec.go

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

2 changes: 2 additions & 0 deletions swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,8 @@ definitions:
used_size:
type: integer
format: int64
storage_class:
type: string

tenantList:
type: object
Expand Down