Skip to content

Commit 7d5d366

Browse files
committed
wip
Signed-off-by: Lenin Alevski <[email protected]>
1 parent b8564ac commit 7d5d366

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

operatorapi/operator_subscription.go

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package operatorapi
2020
import (
2121
"context"
2222
"errors"
23-
"log"
2423
"time"
2524

2625
"github.com/minio/console/pkg/subnet"
@@ -118,7 +117,7 @@ func getSubscriptionLicense(ctx context.Context, clientSet K8sClientI, namespace
118117
}
119118

120119
// addSubscriptionLicenseToTenant replace existing console tenant secret and adds the subnet license key
121-
func addSubscriptionLicenseToTenant(ctx context.Context, clientSet K8sClientI, license string, tenant *miniov2.Tenant) error {
120+
func addSubscriptionLicenseToTenant(ctx context.Context, clientSet K8sClientI, opClient OperatorClientI, license string, tenant *miniov2.Tenant) error {
122121
// If Tenant has a configuration secret update the license there and MinIO pods doesn't need to get restarted
123122
if tenant.HasConfigurationSecret() {
124123
// Update the Tenant Configuration
@@ -146,8 +145,36 @@ func addSubscriptionLicenseToTenant(ctx context.Context, clientSet K8sClientI, l
146145
}
147146
}
148147
} else {
149-
// Create new tenant configuration secret
150-
log.Println("no tenant secret yet :(")
148+
// If configuration file is not present set the license to the container env
149+
updatedTenant := tenant.DeepCopy()
150+
// reset container env vars
151+
updatedTenant.Spec.Env = []corev1.EnvVar{}
152+
var licenseIsSet bool
153+
for _, env := range tenant.GetEnvVars() {
154+
// check if license already exists and override
155+
if env.Name == "MINIO_SUBNET_LICENSE" {
156+
updatedTenant.Spec.Env = append(updatedTenant.Spec.Env, corev1.EnvVar{
157+
Name: "MINIO_SUBNET_LICENSE",
158+
Value: license,
159+
})
160+
licenseIsSet = true
161+
} else {
162+
// copy existing container env variables
163+
updatedTenant.Spec.Env = append(updatedTenant.Spec.Env, env)
164+
}
165+
}
166+
// if license didnt exists append it
167+
if !licenseIsSet {
168+
updatedTenant.Spec.Env = append(updatedTenant.Spec.Env, corev1.EnvVar{
169+
Name: "MINIO_SUBNET_LICENSE",
170+
Value: license,
171+
})
172+
}
173+
// this will start MinIO pods rolling restart
174+
_, err := opClient.TenantUpdate(ctx, updatedTenant, metav1.UpdateOptions{})
175+
if err != nil {
176+
return err
177+
}
151178
}
152179
return nil
153180
}
@@ -184,7 +211,7 @@ func getSubscriptionRefreshResponse(session *models.Principal) (*models.License,
184211
if err != nil {
185212
return nil, prepareError(err)
186213
}
187-
opClient := &operatorClient{
214+
opClient := operatorClient{
188215
client: opClientClientSet,
189216
}
190217
// iterate over all tenants and update licenses
@@ -193,7 +220,7 @@ func getSubscriptionRefreshResponse(session *models.Principal) (*models.License,
193220
return nil, prepareError(err)
194221
}
195222
for _, tenant := range tenants.Items {
196-
if err = addSubscriptionLicenseToTenant(ctx, &k8sClient, licenseRaw, &tenant); err != nil {
223+
if err = addSubscriptionLicenseToTenant(ctx, &k8sClient, &opClient, licenseRaw, &tenant); err != nil {
197224
return nil, prepareError(err)
198225
}
199226
}
@@ -342,10 +369,10 @@ func getSubscriptionActivateResponse(session *models.Principal, namespace, tenan
342369
if err != nil {
343370
return prepareError(errorGeneric, nil, err)
344371
}
345-
opClient := &operatorClient{
372+
opClient := operatorClient{
346373
client: opClientClientSet,
347374
}
348-
tenant, err := getTenant(ctx, opClient, namespace, tenantName)
375+
tenant, err := getTenant(ctx, &opClient, namespace, tenantName)
349376
if err != nil {
350377
return prepareError(err, errorGeneric)
351378
}
@@ -359,7 +386,7 @@ func getSubscriptionActivateResponse(session *models.Principal, namespace, tenan
359386
return prepareError(errInvalidCredentials, nil, err)
360387
}
361388
// add subscription license to existing console Tenant
362-
if err = addSubscriptionLicenseToTenant(ctx, &k8sClient, license, tenant); err != nil {
389+
if err = addSubscriptionLicenseToTenant(ctx, &k8sClient, &opClient, license, tenant); err != nil {
363390
return prepareError(err, errorGeneric)
364391
}
365392
return nil

operatorapi/operator_tenants.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,28 +351,21 @@ type tenantKeys struct {
351351
}
352352

353353
func getTenantCreds(ctx context.Context, client K8sClientI, tenant *miniov2.Tenant) (*tenantKeys, error) {
354-
if tenant == nil || tenant.Spec.CredsSecret == nil {
355-
return nil, errors.New("invalid arguments")
356-
}
357-
// get admin credentials from secret
358-
creds, err := client.getSecret(ctx, tenant.Namespace, tenant.Spec.CredsSecret.Name, metav1.GetOptions{})
354+
tenantConfiguration, err := GetTenantConfiguration(ctx, client, tenant)
359355
if err != nil {
360356
return nil, err
361357
}
362-
tenantAccessKey, ok := creds.Data["accesskey"]
358+
tenantAccessKey, ok := tenantConfiguration["accesskey"]
363359
if !ok {
364360
restapi.LogError("tenant's secret doesn't contain accesskey")
365361
return nil, restapi.ErrorGeneric
366362
}
367-
tenantSecretKey, ok := creds.Data["secretkey"]
363+
tenantSecretKey, ok := tenantConfiguration["secretkey"]
368364
if !ok {
369365
restapi.LogError("tenant's secret doesn't contain secretkey")
370366
return nil, restapi.ErrorGeneric
371367
}
372-
// TODO:
373-
// We need to avoid using minio root credentials to talk to tenants, and instead use a different user credentials
374-
// when that its implemented we also need to check here if the tenant has LDAP enabled so we authenticate first against AD
375-
return &tenantKeys{accessKey: string(tenantAccessKey), secretKey: string(tenantSecretKey)}, nil
368+
return &tenantKeys{accessKey: tenantAccessKey, secretKey: tenantSecretKey}, nil
376369
}
377370

378371
func getTenant(ctx context.Context, operatorClient OperatorClientI, namespace, tenantName string) (*miniov2.Tenant, error) {

operatorapi/utils.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ package operatorapi
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223

2324
miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
)
2627

2728
func GetTenantConfiguration(ctx context.Context, clientSet K8sClientI, tenant *miniov2.Tenant) (map[string]string, error) {
29+
if tenant == nil {
30+
return nil, errors.New("tenant cannot be nil")
31+
}
2832
tenantConfiguration := map[string]string{}
29-
3033
for _, config := range tenant.GetEnvVars() {
3134
tenantConfiguration[config.Name] = config.Value
3235
}
33-
3436
if tenant.HasCredsSecret() {
3537
minioSecret, err := clientSet.getSecret(ctx, tenant.Namespace, tenant.Spec.CredsSecret.Name, metav1.GetOptions{})
3638
if err != nil {
@@ -41,7 +43,6 @@ func GetTenantConfiguration(ctx context.Context, clientSet K8sClientI, tenant *m
4143
tenantConfiguration[key] = string(val)
4244
}
4345
}
44-
4546
if tenant.HasConfigurationSecret() {
4647
minioConfigurationSecret, err := clientSet.getSecret(ctx, tenant.Namespace, tenant.Spec.Configuration.Name, metav1.GetOptions{})
4748
if err == nil {

0 commit comments

Comments
 (0)