@@ -54,10 +54,6 @@ import (
54
54
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
55
55
)
56
56
57
- const (
58
- minioRegCred = "minio-regcred-secret"
59
- )
60
-
61
57
type imageRegistry struct {
62
58
Auths map [string ]imageRegistryCredentials `json:"auths"`
63
59
}
@@ -589,7 +585,7 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
589
585
590
586
const consoleVersion = "minio/console:v0.3.11"
591
587
minInst .Spec .Console = & operator.ConsoleConfiguration {
592
- Replicas : 2 ,
588
+ Replicas : 1 ,
593
589
Image : consoleVersion ,
594
590
ConsoleSecret : & corev1.LocalObjectReference {Name : consoleSecretName },
595
591
Resources : corev1.ResourceRequirements {
@@ -660,13 +656,25 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
660
656
minInst .Spec .Mountpath = tenantReq .MounthPath
661
657
}
662
658
663
- if err := setImageRegistry (ctx , tenantReq .ImageRegistry , clientset .CoreV1 (), ns ); err != nil {
659
+ // We accept either `image_pull_secret` or the individual details of the `image_registry` but not both
660
+ var imagePullSecret string
661
+
662
+ if tenantReq .ImagePullSecret != "" {
663
+ imagePullSecret = tenantReq .ImagePullSecret
664
+ } else if imagePullSecret , err = setImageRegistry (ctx , * tenantReq .Name , tenantReq .ImageRegistry , clientset .CoreV1 (), ns ); err != nil {
664
665
log .Println ("error setting image registry secret:" , err )
665
666
return nil , err
666
667
}
668
+ // pass the image pull secret to the Tenant
669
+ if imagePullSecret != "" {
670
+ minInst .Spec .ImagePullSecret = corev1.LocalObjectReference {
671
+ Name : imagePullSecret ,
672
+ }
673
+ }
667
674
668
- minInst .Spec .ImagePullSecret = corev1.LocalObjectReference {
669
- Name : minioRegCred ,
675
+ // set console image if provided
676
+ if tenantReq .ConsoleImage != "" {
677
+ minInst .Spec .Console .Image = tenantReq .ConsoleImage
670
678
}
671
679
672
680
opClient , err := cluster .OperatorClient (session .SessionToken )
@@ -700,9 +708,11 @@ func getTenantCreatedResponse(session *models.Principal, params admin_api.Create
700
708
return response , nil
701
709
}
702
710
703
- func setImageRegistry (ctx context.Context , req * models.ImageRegistry , clientset v1.CoreV1Interface , namespace string ) error {
711
+ // setImageRegistry creates a secret to store the private registry credentials, if one exist it updates the existing one
712
+ // returns the name of the secret created/updated
713
+ func setImageRegistry (ctx context.Context , tenantName string , req * models.ImageRegistry , clientset v1.CoreV1Interface , namespace string ) (string , error ) {
704
714
if req == nil || req .Registry == nil || req .Username == nil || req .Password == nil {
705
- return nil
715
+ return "" , nil
706
716
}
707
717
708
718
credentials := make (map [string ]imageRegistryCredentials )
@@ -720,12 +730,14 @@ func setImageRegistry(ctx context.Context, req *models.ImageRegistry, clientset
720
730
}
721
731
imRegistryJSON , err := json .Marshal (imRegistry )
722
732
if err != nil {
723
- return err
733
+ return "" , err
724
734
}
725
735
736
+ pullSecretName := fmt .Sprintf ("%s-regcred" , tenantName )
737
+
726
738
instanceSecret := corev1.Secret {
727
739
ObjectMeta : metav1.ObjectMeta {
728
- Name : minioRegCred ,
740
+ Name : pullSecretName ,
729
741
},
730
742
Data : map [string ][]byte {
731
743
corev1 .DockerConfigJsonKey : []byte (string (imRegistryJSON )),
@@ -734,48 +746,58 @@ func setImageRegistry(ctx context.Context, req *models.ImageRegistry, clientset
734
746
}
735
747
736
748
// Get or Create secret if it doesn't exist
737
- _ , err = clientset .Secrets (namespace ).Get (ctx , minioRegCred , metav1.GetOptions {})
749
+ _ , err = clientset .Secrets (namespace ).Get (ctx , pullSecretName , metav1.GetOptions {})
738
750
if err != nil {
739
751
if k8sErrors .IsNotFound (err ) {
740
752
_ , err = clientset .Secrets (namespace ).Create (ctx , & instanceSecret , metav1.CreateOptions {})
741
753
if err != nil {
742
- return err
754
+ return "" , err
743
755
}
744
- return nil
756
+ return "" , nil
745
757
}
746
- return err
758
+ return "" , err
747
759
}
748
760
_ , err = clientset .Secrets (namespace ).Update (ctx , & instanceSecret , metav1.UpdateOptions {})
749
761
if err != nil {
750
- return err
762
+ return "" , err
751
763
}
752
- return nil
764
+ return pullSecretName , nil
753
765
}
754
766
755
767
// updateTenantAction does an update on the minioTenant by patching the desired changes
756
768
func updateTenantAction (ctx context.Context , operatorClient OperatorClient , clientset v1.CoreV1Interface , httpCl cluster.HTTPClientI , namespace string , params admin_api.UpdateTenantParams ) error {
757
769
imageToUpdate := params .Body .Image
758
770
imageRegistryReq := params .Body .ImageRegistry
759
771
760
- if err := setImageRegistry (ctx , imageRegistryReq , clientset , namespace ); err != nil {
761
- log .Println ("error setting image registry secret:" , err )
762
- return err
763
- }
764
-
765
772
minInst , err := operatorClient .TenantGet (ctx , namespace , params .Tenant , metav1.GetOptions {})
766
773
if err != nil {
767
774
return err
768
775
}
776
+ // we can take either the `image_pull_secret` of the `image_registry` but not both
777
+ if params .Body .ImagePullSecret != "" {
778
+ minInst .Spec .ImagePullSecret .Name = params .Body .ImagePullSecret
779
+ } else {
780
+ // update the image pull secret content
781
+ if _ , err := setImageRegistry (ctx , params .Tenant , imageRegistryReq , clientset , namespace ); err != nil {
782
+ log .Println ("error setting image registry secret:" , err )
783
+ return err
784
+ }
785
+ }
786
+
787
+ // update the console image
788
+ if strings .TrimSpace (params .Body .ConsoleImage ) != "" && minInst .Spec .Console != nil {
789
+ minInst .Spec .Console .Image = params .Body .ConsoleImage
790
+ }
769
791
770
792
// if image to update is empty we'll use the latest image by default
771
793
if strings .TrimSpace (imageToUpdate ) != "" {
772
794
minInst .Spec .Image = imageToUpdate
773
795
} else {
774
796
im , err := cluster .GetLatestMinioImage (httpCl )
775
- if err != nil {
776
- return err
797
+ // if we can't get the MinIO image, we won' auto-update it unless it's explicit by name
798
+ if err == nil {
799
+ minInst .Spec .Image = * im
777
800
}
778
- minInst .Spec .Image = * im
779
801
}
780
802
781
803
payloadBytes , err := json .Marshal (minInst )
0 commit comments