Skip to content

Commit

Permalink
fix: use dedicated function to test minio availability (#4149)
Browse files Browse the repository at this point in the history
* fix: use dedicated function to test minio availability

* fix: make as bool the IsConnectionPossible func
  • Loading branch information
nicufk authored Jul 9, 2023
1 parent 315ee4c commit f3e13b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func main() {
bucket := cfg.LogsBucket
if bucket == "" {
log.DefaultLogger.Error("LOGS_BUCKET env var is not set")
} else if _, err := storageClient.ListBuckets(ctx); err == nil {
} else if ok, err := storageClient.IsConnectionPossible(ctx); ok && (err == nil) {
log.DefaultLogger.Info("setting minio as logs storage")
mongoResultsRepository.OutputRepository = result.NewMinioOutputRepository(storageClient, mongoResultsRepository.ResultsColl, bucket)
} else {
Expand Down
9 changes: 9 additions & 0 deletions pkg/storage/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,12 @@ func (c *Client) DeleteFile(ctx context.Context, bucketFolder, file string) erro
func (c *Client) DeleteFileFromBucket(ctx context.Context, bucket, bucketFolder, file string) error {
return c.deleteFile(ctx, bucket, bucketFolder, file)
}

// IsConnectionPossible checks if the connection to minio is possible
func (c *Client) IsConnectionPossible(ctx context.Context) (bool, error) {
if err := c.Connect(); err != nil {
return false, err
}

return true, nil
}
1 change: 1 addition & 0 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Client interface {

// ClientImplicitBucket is storage client abstraction where bucket name is provided from config
type ClientImplicitBucket interface {
IsConnectionPossible(ctx context.Context) (bool, error)
ListFiles(ctx context.Context, bucketFolder string) ([]testkube.Artifact, error)
SaveFile(ctx context.Context, bucketFolder, filePath string) error
DownloadFile(ctx context.Context, bucketFolder, file string) (*minio.Object, error)
Expand Down

0 comments on commit f3e13b6

Please sign in to comment.