@@ -20,7 +20,6 @@ package operatorapi
2020import (
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
0 commit comments