@@ -422,7 +422,7 @@ func getListTenantsResponse(session *models.Principal, params admin_api.ListTena
422
422
return listT , nil
423
423
}
424
424
425
- func getTenantCreatedResponse (session * models.Principal , params admin_api.CreateTenantParams ) (* models.CreateTenantResponse , * models.Error ) {
425
+ func getTenantCreatedResponse (session * models.Principal , params admin_api.CreateTenantParams ) (response * models.CreateTenantResponse , mError * models.Error ) {
426
426
tenantReq := params .Body
427
427
minioImage := tenantReq .Image
428
428
ctx := context .Background ()
@@ -478,11 +478,24 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
478
478
if err != nil {
479
479
return nil , prepareError (err )
480
480
}
481
+ // delete secrets created if an error occurred during tenant creation,
482
+ defer func () {
483
+ if mError != nil {
484
+ log .Printf ("deleting secrets created for failed tenant: %s if any\n " , tenantName )
485
+ opts := metav1.ListOptions {
486
+ LabelSelector : fmt .Sprintf ("%s=%s" , operator .TenantLabel , tenantName ),
487
+ }
488
+ err = clientSet .CoreV1 ().Secrets (ns ).DeleteCollection (ctx , metav1.DeleteOptions {}, opts )
489
+ if err != nil {
490
+ log .Println ("error deleting tenant's secrets:" , err )
491
+ }
492
+ }
493
+ }()
481
494
482
495
var envrionmentVariables []corev1.EnvVar
483
496
// Check the Erasure Coding Parity for validity and pass it to Tenant
484
497
if tenantReq .ErasureCodingParity > 0 {
485
- if tenantReq .ErasureCodingParity < 2 && tenantReq .ErasureCodingParity > 8 {
498
+ if tenantReq .ErasureCodingParity < 2 || tenantReq .ErasureCodingParity > 8 {
486
499
return nil , prepareError (errorInvalidErasureCodingValue )
487
500
}
488
501
envrionmentVariables = append (envrionmentVariables , corev1.EnvVar {
@@ -713,7 +726,7 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
713
726
714
727
if tenantReq .ImagePullSecret != "" {
715
728
imagePullSecret = tenantReq .ImagePullSecret
716
- } else if imagePullSecret , err = setImageRegistry (ctx , tenantName , tenantReq .ImageRegistry , clientSet .CoreV1 (), ns ); err != nil {
729
+ } else if imagePullSecret , err = setImageRegistry (ctx , tenantReq .ImageRegistry , clientSet .CoreV1 (), ns , tenantName ); err != nil {
717
730
return nil , prepareError (err )
718
731
}
719
732
// pass the image pull secret to the Tenant
@@ -752,7 +765,7 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
752
765
return nil , prepareError (err )
753
766
}
754
767
}
755
- response : = & models.CreateTenantResponse {
768
+ response = & models.CreateTenantResponse {
756
769
AccessKey : accessKey ,
757
770
SecretKey : secretKey ,
758
771
}
@@ -768,7 +781,7 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
768
781
769
782
// setImageRegistry creates a secret to store the private registry credentials, if one exist it updates the existing one
770
783
// returns the name of the secret created/updated
771
- func setImageRegistry (ctx context.Context , tenantName string , req * models.ImageRegistry , clientset v1.CoreV1Interface , namespace string ) (string , error ) {
784
+ func setImageRegistry (ctx context.Context , req * models.ImageRegistry , clientset v1.CoreV1Interface , namespace , tenantName string ) (string , error ) {
772
785
if req == nil || req .Registry == nil || req .Username == nil || req .Password == nil {
773
786
return "" , nil
774
787
}
@@ -839,7 +852,7 @@ func updateTenantAction(ctx context.Context, operatorClient OperatorClientI, cli
839
852
minInst .Spec .ImagePullSecret .Name = params .Body .ImagePullSecret
840
853
} else {
841
854
// update the image pull secret content
842
- if _ , err := setImageRegistry (ctx , params . Tenant , imageRegistryReq , clientset , namespace ); err != nil {
855
+ if _ , err := setImageRegistry (ctx , imageRegistryReq , clientset , namespace , params . Tenant ); err != nil {
843
856
log .Println ("error setting image registry secret:" , err )
844
857
return err
845
858
}
0 commit comments