Added Logger to closing GCP client

Signed-off-by: pa250194 <pa250194@ncr.com>
This commit is contained in:
pa250194 2021-10-14 09:51:49 -05:00
parent f62571bcec
commit f797fbfdf0
2 changed files with 9 additions and 2 deletions

View File

@ -272,10 +272,9 @@ func (r *BucketReconciler) reconcileWithGCP(ctx context.Context, bucket sourcev1
gcpClient, err := r.authGCP(ctx, bucket) gcpClient, err := r.authGCP(ctx, bucket)
if err != nil { if err != nil {
err = fmt.Errorf("auth error: %w", err) err = fmt.Errorf("auth error: %w", err)
log.Error(err, "GCP Provider")
return sourcev1.BucketNotReady(bucket, sourcev1.AuthenticationFailedReason, err.Error()), err return sourcev1.BucketNotReady(bucket, sourcev1.AuthenticationFailedReason, err.Error()), err
} }
defer gcpClient.Client.Close() defer gcpClient.Close(log)
ctxTimeout, cancel := context.WithTimeout(ctx, bucket.Spec.Timeout.Duration) ctxTimeout, cancel := context.WithTimeout(ctx, bucket.Spec.Timeout.Duration)
defer cancel() defer cancel()

View File

@ -25,6 +25,7 @@ import (
"path/filepath" "path/filepath"
gcpstorage "cloud.google.com/go/storage" gcpstorage "cloud.google.com/go/storage"
"github.com/go-logr/logr"
"google.golang.org/api/iterator" "google.golang.org/api/iterator"
"google.golang.org/api/option" "google.golang.org/api/option"
) )
@ -162,3 +163,10 @@ func (c *GCPClient) ListObjects(ctx context.Context, bucketName string, query *g
items := c.Client.Bucket(bucketName).Objects(ctx, query) items := c.Client.Bucket(bucketName).Objects(ctx, query)
return items return items
} }
// Close closes the GCP Client and logs any useful errors
func (c *GCPClient) Close(log logr.Logger) {
if err := c.Client.Close(); err != nil {
log.Error(err, "GCP Provider")
}
}