| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -268,12 +268,13 @@ func (r *BucketReconciler) reconcileDelete(ctx context.Context, bucket sourcev1. | |||
| 268 | 268 | // reconcileWithGCP handles getting objects from a Google Cloud Platform bucket | |
| 269 | 269 | // using a gcp client | |
| 270 | 270 | func (r *BucketReconciler) reconcileWithGCP(ctx context.Context, bucket sourcev1.Bucket, tempDir string) (sourcev1.Bucket, error) { | |
| 271 | + log := logr.FromContext(ctx) | ||
| 271 | 272 | gcpClient, err := r.authGCP(ctx, bucket) | |
| 272 | 273 | if err != nil { | |
| 273 | 274 | err = fmt.Errorf("auth error: %w", err) | |
| 274 | 275 | return sourcev1.BucketNotReady(bucket, sourcev1.AuthenticationFailedReason, err.Error()), err | |
| 275 | 276 | } | |
| 276 | - defer gcpClient.Client.Close() | ||
| 277 | + defer gcpClient.Close(log) | ||
| 277 | 278 | ||
| 278 | 279 | ctxTimeout, cancel := context.WithTimeout(ctx, bucket.Spec.Timeout.Duration) | |
| 279 | 280 | defer cancel() | |
@@ -432,7 +433,9 @@ func (r *BucketReconciler) authGCP(ctx context.Context, bucket sourcev1.Bucket) | |||
| 432 | 433 | ||
| 433 | 434 | } | |
| 434 | 435 | ||
| 435 | - func (r *BucketReconciler) auth(ctx context.Context, bucket sourcev1.Bucket) (*minio.Client, error) { | ||
| 436 | + // authMinio creates a new Minio client to interact with S3 | ||
| 437 | + // compatible storage services. | ||
| 438 | + func (r *BucketReconciler) authMinio(ctx context.Context, bucket sourcev1.Bucket) (*minio.Client, error) { | ||
| 436 | 439 | opt := minio.Options{ | |
| 437 | 440 | Region: bucket.Spec.Region, | |
| 438 | 441 | Secure: !bucket.Spec.Insecure, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ import ( | |||
| 25 | 25 | "path/filepath" | |
| 26 | 26 | ||
| 27 | 27 | gcpstorage "cloud.google.com/go/storage" | |
| 28 | + "github.com/go-logr/logr" | ||
| 28 | 29 | "google.golang.org/api/iterator" | |
| 29 | 30 | "google.golang.org/api/option" | |
| 30 | 31 | ) | |
@@ -127,7 +128,7 @@ func (c *GCPClient) FGetObject(ctx context.Context, bucketName, objectName, loca | |||
| 127 | 128 | return err | |
| 128 | 129 | } | |
| 129 | 130 | if !exists { | |
| 130 | - return ObjectDoesNotExist | ||
| 131 | + return ErrorObjectDoesNotExist | ||
| 131 | 132 | } | |
| 132 | 133 | ||
| 133 | 134 | 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 | |||
| 162 | 163 | items := c.Client.Bucket(bucketName).Objects(ctx, query) | |
| 163 | 164 | return items | |
| 164 | 165 | } | |
| 166 | + | ||
| 167 | + // Close closes the GCP Client and logs any useful errors | ||
| 168 | + func (c *GCPClient) Close(log logr.Logger) { | ||
| 169 | + if err := c.Client.Close(); err != nil { | ||
| 170 | + log.Error(err, "GCP Provider") | ||
| 171 | + } | ||
| 172 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,7 @@ import ( | |||
| 30 | 30 | "os" | |
| 31 | 31 | "path/filepath" | |
| 32 | 32 | "testing" | |
| 33 | + "time" | ||
| 33 | 34 | ||
| 34 | 35 | gcpstorage "cloud.google.com/go/storage" | |
| 35 | 36 | "github.com/fluxcd/source-controller/pkg/gcp" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments