Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions v1/minio/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ type ConnectionConfig struct {

// Region specifies the S3 region (e.g., "us-east-1")
Region string

// SkipConnectionValidation disables the ListBuckets call used for
// connection health checks (startup, periodic monitoring, reconnection).
// Enable this for environments with restricted IAM policies where
// s3:ListAllMyBuckets is not granted. Defaults to false.
SkipConnectionValidation bool
}

// UploadConfig defines the configuration for upload constraints.
Expand Down
33 changes: 17 additions & 16 deletions v1/minio/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,9 @@ outerLoop:
return

default:
// Create a context with timeout for the reconnection attempt
ctxReconnect, cancel := context.WithTimeout(context.Background(), 10*time.Second)

// Attempt to create new clients
newClient, err := connectToMinio(m.cfg)
if err != nil {
cancel() // Cancel the context to free resources
m.logError(ctx, "MinIO reconnection failed", map[string]interface{}{
"endpoint": m.cfg.Connection.Endpoint,
"will_retry_in": "1s",
Expand All @@ -408,7 +404,6 @@ outerLoop:

newCoreClient, err := connectToMinioCore(m.cfg)
if err != nil {
cancel() // Cancel the context to free resources
m.logError(ctx, "MinIO core client reconnection failed", map[string]interface{}{
"endpoint": m.cfg.Connection.Endpoint,
"will_retry_in": "1s",
Expand All @@ -419,15 +414,18 @@ outerLoop:
}

// Validate the new connection before swapping pointers
_, err = newClient.ListBuckets(ctxReconnect)
cancel() // Cancel the context to free resources

if err != nil {
m.logError(ctx, "MinIO connection validation failed", map[string]interface{}{
"error": err.Error(),
})
time.Sleep(time.Second)
continue reconnectLoop
if !m.cfg.Connection.SkipConnectionValidation {
ctxReconnect, cancel := context.WithTimeout(context.Background(), 10*time.Second)
_, err = newClient.ListBuckets(ctxReconnect)
cancel()

if err != nil {
m.logError(ctx, "MinIO connection validation failed", map[string]interface{}{
"error": err.Error(),
})
time.Sleep(time.Second)
continue reconnectLoop
}
}

// Update the client references
Expand Down Expand Up @@ -496,13 +494,17 @@ func connectToMinioCore(cfg Config) (*minio.Core, error) {

// validateConnection performs a simple operation to validate connectivity to MinIO.
// It attempts to list buckets to ensure the connection and credentials are valid.
// When SkipConnectionValidation is true, this is a no-op.
//
// Parameters:
// - ctx: Context for controlling the validation operation
//
// Returns nil if the connection is valid, or an error if the validation fails.
func (m *MinioClient) validateConnection(ctx context.Context) error {
// Set a timeout for validation
if m.cfg.Connection.SkipConnectionValidation {
return nil
}

ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

Expand All @@ -511,7 +513,6 @@ func (m *MinioClient) validateConnection(ctx context.Context) error {
return ErrConnectionFailed
}

// Validate by listing buckets - this doesn't require a specific bucket
_, err := c.ListBuckets(ctx)
return err
}
Expand Down