Skip to content

Commit 319d96c

Browse files
authored
Use operator port variables (#282)
1 parent 6d58290 commit 319d96c

File tree

4 files changed

+46
-50
lines changed

4 files changed

+46
-50
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/minio/mc v0.0.0-20200808005614-7e52c104bee1
2020
github.com/minio/minio v0.0.0-20200808024306-2a9819aff876
2121
github.com/minio/minio-go/v7 v7.0.5-0.20200807085956-d7db33ea7618
22-
github.com/minio/operator v0.0.0-20200904194631-b8aa01dc5d70
22+
github.com/minio/operator v0.0.0-20200921211523-69f9eef5b7b5
2323
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
2424
github.com/secure-io/sio-go v0.3.1
2525
github.com/stretchr/testify v1.6.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,8 @@ github.com/minio/minio-go/v7 v7.0.2/go.mod h1:dJ80Mv2HeGkYLH1sqS/ksz07ON6csH3S6J
781781
github.com/minio/minio-go/v7 v7.0.3/go.mod h1:TA0CQCjJZHM5SJj9IjqR0NmpmQJ6bCbXifAJ3mUU6Hw=
782782
github.com/minio/minio-go/v7 v7.0.5-0.20200807085956-d7db33ea7618 h1:8iTb0TFs6kDGAUnhI/s2QCZOYcSTtYmY9dF+Cbc0WJo=
783783
github.com/minio/minio-go/v7 v7.0.5-0.20200807085956-d7db33ea7618/go.mod h1:CSt2ETZNs+bIIhWTse0mcZKZWMGrFU7Er7RR0TmkDYk=
784-
github.com/minio/operator v0.0.0-20200904194631-b8aa01dc5d70 h1:FjyhnnrOHMzhJryqNoOISgp8p1dmmn1IMOlgBAaf8r4=
785-
github.com/minio/operator v0.0.0-20200904194631-b8aa01dc5d70/go.mod h1:NVl1+c7TYxJB22opK/m2L5SkTvlEYd1ZFPuL6SX5fCg=
784+
github.com/minio/operator v0.0.0-20200921211523-69f9eef5b7b5 h1:yQ7WHA2wbTTGHz0Z4xXSRxfUTm5fafM0ajvlZlQ2Zl4=
785+
github.com/minio/operator v0.0.0-20200921211523-69f9eef5b7b5/go.mod h1:6lavbNo2YuJWeQR5bZYsEWdbpRCO2KrTyfQ0PtC/AN4=
786786
github.com/minio/selfupdate v0.3.1 h1:BWEFSNnrZVMUWXbXIgLDNDjbejkmpAmZvy/nCz1HlEs=
787787
github.com/minio/selfupdate v0.3.1/go.mod h1:b8ThJzzH7u2MkF6PcIra7KaXO9Khf6alWPvMSyTDCFM=
788788
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=

restapi/admin_tenants.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,19 @@ func deleteTenantAction(
218218
return nil
219219
}
220220

221-
func getTenantScheme(mi *operator.Tenant) string {
221+
// GetTenantServiceURL gets tenant's service url with the proper scheme and port
222+
func GetTenantServiceURL(mi *operator.Tenant) (svcURL string) {
222223
scheme := "http"
224+
port := operator.MinIOPortLoadBalancerSVC
223225
if mi.AutoCert() || mi.ExternalCert() {
224226
scheme = "https"
227+
port = operator.MinIOTLSPortLoadBalancerSVC
225228
}
226-
return scheme
229+
svc := fmt.Sprintf("%s.%s.svc.cluster.local", mi.MinIOCIServiceName(), mi.Namespace)
230+
return fmt.Sprintf("%s://%s", scheme, net.JoinHostPort(svc, strconv.Itoa(port)))
227231
}
228232

229-
func getTenantAdminClient(ctx context.Context, client K8sClientI, namespace, tenantName, serviceName, scheme string, insecure bool) (*madmin.AdminClient, error) {
233+
func getTenantAdminClient(ctx context.Context, client K8sClientI, namespace, tenantName, svcURL string, insecure bool) (*madmin.AdminClient, error) {
230234
// get admin credentials from secret
231235
creds, err := client.getSecret(ctx, namespace, fmt.Sprintf("%s-secret", tenantName), metav1.GetOptions{})
232236
if err != nil {
@@ -242,7 +246,7 @@ func getTenantAdminClient(ctx context.Context, client K8sClientI, namespace, ten
242246
log.Println("tenant's secret doesn't contain secretkey")
243247
return nil, errorGeneric
244248
}
245-
mAdmin, pErr := NewAdminClientWithInsecure(scheme+"://"+net.JoinHostPort(serviceName, strconv.Itoa(operator.MinIOPort)), string(accessKey), string(secretkey), insecure)
249+
mAdmin, pErr := NewAdminClientWithInsecure(svcURL, string(accessKey), string(secretkey), insecure)
246250
if pErr != nil {
247251
return nil, pErr.Cause
248252
}
@@ -872,7 +876,7 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
872876
prometheusPort: fmt.Sprint(operator.MinIOPort),
873877
prometheusScrape: "true",
874878
}
875-
if params.Body.EnablePrometheus && minInst.Spec.Metadata != nil && currentAnnotations != nil {
879+
if params.Body.EnablePrometheus && currentAnnotations != nil {
876880
// add prometheus annotations to the tenant
877881
minInst.Annotations = addAnnotations(currentAnnotations, prometheusAnnotations)
878882
// add prometheus annotations to the each zone
@@ -1019,17 +1023,15 @@ func getTenantUsageResponse(session *models.Principal, params admin_api.GetTenan
10191023
return nil, prepareError(err, errorUnableToGetTenantUsage)
10201024
}
10211025
minTenant.EnsureDefaults()
1022-
tenantScheme := getTenantScheme(minTenant)
10231026

1024-
svcName := fmt.Sprintf("%s.%s.svc.cluster.local", minTenant.MinIOCIServiceName(), minTenant.Namespace)
1027+
svcURL := GetTenantServiceURL(minTenant)
10251028

10261029
mAdmin, err := getTenantAdminClient(
10271030
ctx,
10281031
k8sClient,
10291032
params.Namespace,
10301033
params.Tenant,
1031-
svcName,
1032-
tenantScheme,
1034+
svcURL,
10331035
true)
10341036
if err != nil {
10351037
return nil, prepareError(err, errorUnableToGetTenantUsage)

restapi/admin_tenants_test.go

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
8787
ctx := context.Background()
8888
kClient := k8sClientMock{}
8989
type args struct {
90-
ctx context.Context
91-
client K8sClientI
92-
namespace string
93-
tenantName string
94-
serviceName string
95-
scheme string
96-
insecure bool
90+
ctx context.Context
91+
client K8sClientI
92+
namespace string
93+
tenantName string
94+
serviceURL string
95+
insecure bool
9796
}
9897
tests := []struct {
9998
name string
@@ -105,12 +104,11 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
105104
{
106105
name: "Return Tenant Admin, no errors",
107106
args: args{
108-
ctx: ctx,
109-
client: kClient,
110-
namespace: "default",
111-
tenantName: "tenant-1",
112-
serviceName: "service-1",
113-
scheme: "http",
107+
ctx: ctx,
108+
client: kClient,
109+
namespace: "default",
110+
tenantName: "tenant-1",
111+
serviceURL: "http://service-1.default.svc.cluster.local:80",
114112
},
115113
mockGetSecret: func(ctx context.Context, namespace, secretName string, opts metav1.GetOptions) (*corev1.Secret, error) {
116114
vals := make(map[string][]byte)
@@ -134,12 +132,11 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
134132
{
135133
name: "Access key not stored on secrets",
136134
args: args{
137-
ctx: ctx,
138-
client: kClient,
139-
namespace: "default",
140-
tenantName: "tenant-1",
141-
serviceName: "service-1",
142-
scheme: "http",
135+
ctx: ctx,
136+
client: kClient,
137+
namespace: "default",
138+
tenantName: "tenant-1",
139+
serviceURL: "http://service-1.default.svc.cluster.local:80",
143140
},
144141
mockGetSecret: func(ctx context.Context, namespace, secretName string, opts metav1.GetOptions) (*corev1.Secret, error) {
145142
vals := make(map[string][]byte)
@@ -162,12 +159,11 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
162159
{
163160
name: "Secret key not stored on secrets",
164161
args: args{
165-
ctx: ctx,
166-
client: kClient,
167-
namespace: "default",
168-
tenantName: "tenant-1",
169-
serviceName: "service-1",
170-
scheme: "http",
162+
ctx: ctx,
163+
client: kClient,
164+
namespace: "default",
165+
tenantName: "tenant-1",
166+
serviceURL: "http://service-1.default.svc.cluster.local:80",
171167
},
172168
mockGetSecret: func(ctx context.Context, namespace, secretName string, opts metav1.GetOptions) (*corev1.Secret, error) {
173169
vals := make(map[string][]byte)
@@ -190,12 +186,11 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
190186
{
191187
name: "Handle error on getService",
192188
args: args{
193-
ctx: ctx,
194-
client: kClient,
195-
namespace: "default",
196-
tenantName: "tenant-1",
197-
serviceName: "service-1",
198-
scheme: "http",
189+
ctx: ctx,
190+
client: kClient,
191+
namespace: "default",
192+
tenantName: "tenant-1",
193+
serviceURL: "http://service-1.default.svc.cluster.local:80",
199194
},
200195
mockGetSecret: func(ctx context.Context, namespace, secretName string, opts metav1.GetOptions) (*corev1.Secret, error) {
201196
vals := make(map[string][]byte)
@@ -214,12 +209,11 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
214209
{
215210
name: "Handle error on getSecret",
216211
args: args{
217-
ctx: ctx,
218-
client: kClient,
219-
namespace: "default",
220-
tenantName: "tenant-1",
221-
serviceName: "service-1",
222-
scheme: "http",
212+
ctx: ctx,
213+
client: kClient,
214+
namespace: "default",
215+
tenantName: "tenant-1",
216+
serviceURL: "http://service-1.default.svc.cluster.local:80",
223217
},
224218
mockGetSecret: func(ctx context.Context, namespace, secretName string, opts metav1.GetOptions) (*corev1.Secret, error) {
225219
return nil, errors.New("error")
@@ -239,7 +233,7 @@ func Test_TenantInfoTenantAdminClient(t *testing.T) {
239233
k8sclientGetSecretMock = tt.mockGetSecret
240234
k8sclientGetServiceMock = tt.mockGetService
241235
t.Run(tt.name, func(t *testing.T) {
242-
got, err := getTenantAdminClient(tt.args.ctx, tt.args.client, tt.args.namespace, tt.args.tenantName, tt.args.serviceName, tt.args.scheme, tt.args.insecure)
236+
got, err := getTenantAdminClient(tt.args.ctx, tt.args.client, tt.args.namespace, tt.args.tenantName, tt.args.serviceURL, tt.args.insecure)
243237
if err != nil {
244238
if tt.wantErr {
245239
return

0 commit comments

Comments
 (0)