Added Logger to closing GCP client
Signed-off-by: pa250194 <pa250194@ncr.com> Added log for GCP provider auth error Signed-off-by: pa250194 <pa250194@ncr.com>
This commit is contained in:
parent
7921caf056
commit
c4e4b3928c
|
@ -268,12 +268,13 @@ func (r *BucketReconciler) reconcileDelete(ctx context.Context, bucket sourcev1.
|
||||||
// reconcileWithGCP handles getting objects from a Google Cloud Platform bucket
|
// reconcileWithGCP handles getting objects from a Google Cloud Platform bucket
|
||||||
// using a gcp client
|
// using a gcp client
|
||||||
func (r *BucketReconciler) reconcileWithGCP(ctx context.Context, bucket sourcev1.Bucket, tempDir string) (sourcev1.Bucket, error) {
|
func (r *BucketReconciler) reconcileWithGCP(ctx context.Context, bucket sourcev1.Bucket, tempDir string) (sourcev1.Bucket, error) {
|
||||||
|
log := logr.FromContext(ctx)
|
||||||
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)
|
||||||
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()
|
||||||
|
@ -432,7 +433,9 @@ func (r *BucketReconciler) authGCP(ctx context.Context, bucket sourcev1.Bucket)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BucketReconciler) auth(ctx context.Context, bucket sourcev1.Bucket) (*minio.Client, error) {
|
// authMinio creates a new Minio client to interact with S3
|
||||||
|
// compatible storage services.
|
||||||
|
func (r *BucketReconciler) authMinio(ctx context.Context, bucket sourcev1.Bucket) (*minio.Client, error) {
|
||||||
opt := minio.Options{
|
opt := minio.Options{
|
||||||
Region: bucket.Spec.Region,
|
Region: bucket.Spec.Region,
|
||||||
Secure: !bucket.Spec.Insecure,
|
Secure: !bucket.Spec.Insecure,
|
||||||
|
|
|
@ -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"
|
||||||
)
|
)
|
||||||
|
@ -127,7 +128,7 @@ func (c *GCPClient) FGetObject(ctx context.Context, bucketName, objectName, loca
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !exists {
|
if !exists {
|
||||||
return ObjectDoesNotExist
|
return ErrorObjectDoesNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
objectFile, err := os.OpenFile(localPath, os.O_CREATE|os.O_WRONLY, 0600)
|
objectFile, err := os.OpenFile(localPath, os.O_CREATE|os.O_WRONLY, 0600)
|
||||||
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
gcpstorage "cloud.google.com/go/storage"
|
gcpstorage "cloud.google.com/go/storage"
|
||||||
"github.com/fluxcd/source-controller/pkg/gcp"
|
"github.com/fluxcd/source-controller/pkg/gcp"
|
||||||
|
|
Loading…
Reference in New Issue