@@ -747,8 +747,7 @@ func (r *ScanReconciler) ensureServiceAccountExists(namespace, serviceAccountNam
747747 return nil
748748}
749749
750- // SetupWithManager sets up the controller and initializes every thing it needs
751- func (r * ScanReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
750+ func (r * ScanReconciler ) initS3Connection () * minio.Client {
752751 endpoint := os .Getenv ("S3_ENDPOINT" )
753752 accessKeyID := os .Getenv ("S3_ACCESS_KEY" )
754753 secretAccessKey := os .Getenv ("S3_SECRET_KEY" )
@@ -763,20 +762,36 @@ func (r *ScanReconciler) SetupWithManager(mgr ctrl.Manager) error {
763762 }
764763
765764 // Initialize minio client object.
766- minioClient , err := minio .New (fmt .Sprintf ("%s:%s" , endpoint , port ), accessKeyID , secretAccessKey , useSSL )
767- if err != nil {
768- r .Log .Error (err , "Could not create minio client to communicate with s3 or compatible storage provider" )
769- panic (err )
765+ var minioClient * minio.Client
766+ const maxRetries = 5
767+ for i := 0 ; i < 5 ; i ++ {
768+ client , err := minio .New (fmt .Sprintf ("%s:%s" , endpoint , port ), accessKeyID , secretAccessKey , useSSL )
769+ if err != nil && i < maxRetries - 1 {
770+ r .Log .Info ("Could not create minio client to communicate to s3 endpoint" , "retiresLeft" , maxRetries - i )
771+ time .Sleep (5 * time .Second )
772+ } else if err != nil {
773+ r .Log .Error (err , "S3 Client init failed repeatedly. Process will exit." )
774+ panic (err )
775+ } else {
776+ minioClient = client
777+ }
770778 }
771- r . MinioClient = * minioClient
779+
772780 bucketName := os .Getenv ("S3_BUCKET" )
773781
774- bucketExists , err := r . MinioClient .BucketExists (bucketName )
782+ bucketExists , err := minioClient .BucketExists (bucketName )
775783 if err != nil || bucketExists == false {
776784 r .Log .Error (err , "Could not communicate with s3 or compatible storage provider" )
777785 panic (err )
778786 }
779787
788+ return minioClient
789+ }
790+
791+ // SetupWithManager sets up the controller and initializes every thing it needs
792+ func (r * ScanReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
793+ r .MinioClient = * r .initS3Connection ()
794+
780795 // Todo: Better config management
781796
782797 if err := mgr .GetFieldIndexer ().IndexField (& batch.Job {}, ownerKey , func (rawObj runtime.Object ) []string {
0 commit comments