@@ -255,14 +255,15 @@ func (r *BucketReconciler) reconcileStorage(ctx context.Context, obj *sourcev1.B
255
255
// set to a new artifact.
256
256
func (r * BucketReconciler ) reconcileSource (ctx context.Context , obj * sourcev1.Bucket , artifact * sourcev1.Artifact , dir string ) (ctrl.Result , error ) {
257
257
// Attempt to retrieve secret if one is configured
258
- secret := & corev1.Secret {}
258
+ var secret * corev1.Secret
259
259
if obj .Spec .SecretRef != nil {
260
+ secret = & corev1.Secret {}
260
261
name := types.NamespacedName {
261
262
Namespace : obj .GetNamespace (),
262
263
Name : obj .Spec .SecretRef .Name ,
263
264
}
264
265
if err := r .Client .Get (ctx , name , secret ); err != nil {
265
- conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .AuthenticationFailedReason , "Failed to get secret %s : %s" , name .String (), err .Error ())
266
+ conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .AuthenticationFailedReason , "Failed to get secret '%s' : %s" , name .String (), err .Error ())
266
267
r .Events .Event (ctx , obj , events .EventSeverityError , sourcev1 .AuthenticationFailedReason , conditions .Get (obj , sourcev1 .SourceAvailableCondition ).Message )
267
268
// Return transient errors but wait for next interval on not found
268
269
return ctrl.Result {RequeueAfter : obj .Spec .Interval .Duration }, client .IgnoreNotFound (err )
@@ -272,7 +273,7 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, obj *sourcev1.Bu
272
273
// Build the client with the configuration from the object and secret
273
274
s3Client , err := r .buildClient (obj , secret )
274
275
if err != nil {
275
- conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Client construction failed : %s" , err .Error ())
276
+ conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Failed to construct S3 client : %s" , err .Error ())
276
277
// Recovering from this without a change to the secret or object
277
278
// is impossible
278
279
return ctrl.Result {RequeueAfter : obj .Spec .Interval .Duration }, nil
@@ -283,7 +284,8 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, obj *sourcev1.Bu
283
284
// Confirm bucket exists
284
285
exists , err := s3Client .BucketExists (ctxTimeout , obj .Spec .BucketName )
285
286
if err != nil {
286
- conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Verification of bucket %q existence failed: %s" , obj .Spec .BucketName , err .Error ())
287
+ // Error may be transient
288
+ conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Failed to verify existence of bucket %q: %s" , obj .Spec .BucketName , err .Error ())
287
289
return ctrl.Result {}, err
288
290
}
289
291
if ! exists {
@@ -297,13 +299,13 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, obj *sourcev1.Bu
297
299
path := filepath .Join (dir , sourceignore .IgnoreFile )
298
300
if err := s3Client .FGetObject (ctxTimeout , obj .Spec .BucketName , sourceignore .IgnoreFile , path , minio.GetObjectOptions {}); err != nil {
299
301
if resp , ok := err .(minio.ErrorResponse ); ok && resp .Code != "NoSuchKey" {
300
- conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Downloading %s file failed : %s" , sourceignore .IgnoreFile , err .Error ())
302
+ conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Failed to download '%s' file: %s" , sourceignore .IgnoreFile , err .Error ())
301
303
return ctrl.Result {}, err
302
304
}
303
305
}
304
306
ps , err := sourceignore .ReadIgnoreFile (path , nil )
305
307
if err != nil {
306
- conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Reading %s file failed : %s" , sourceignore .IgnoreFile , err .Error ())
308
+ conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Failed to read '%s' file: %s" , sourceignore .IgnoreFile , err .Error ())
307
309
return ctrl.Result {}, err
308
310
}
309
311
// In-spec patterns take precedence
@@ -319,7 +321,7 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, obj *sourcev1.Bu
319
321
UseV1 : s3utils .IsGoogleEndpoint (* s3Client .EndpointURL ()),
320
322
}) {
321
323
if err = object .Err ; err != nil {
322
- conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Listing objects from bucket %q failed : %s" , obj .Spec .BucketName , err .Error ())
324
+ conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Failed to list objects from bucket %q: %s" , obj .Spec .BucketName , err .Error ())
323
325
return ctrl.Result {}, err
324
326
}
325
327
@@ -333,23 +335,23 @@ func (r *BucketReconciler) reconcileSource(ctx context.Context, obj *sourcev1.Bu
333
335
334
336
localPath := filepath .Join (dir , object .Key )
335
337
if err = s3Client .FGetObject (ctx , obj .Spec .BucketName , object .Key , localPath , minio.GetObjectOptions {}); err != nil {
336
- conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Downloading object %q from bucket %q failed : %s" , object .Key , obj .Spec .BucketName , err .Error ())
338
+ conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Failed to download object %q from bucket %q: %s" , object .Key , obj .Spec .BucketName , err .Error ())
337
339
return ctrl.Result {}, err
338
340
}
339
341
340
342
objCount ++
341
343
}
342
344
343
- // Compute the checksum
344
- revision , err := r .checksum (dir )
345
+ // Compute the checksum of the downloaded file contents, which is used as the revision
346
+ checksum , err := r .checksum (dir )
345
347
if err != nil {
346
- conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Failed to compute revision : %s" , err .Error ())
348
+ conditions .MarkFalse (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationFailedReason , "Failed to compute checksum for downloaded objects : %s" , err .Error ())
347
349
return ctrl.Result {}, err
348
350
}
349
351
350
352
// Create potential new artifact
351
- * artifact = r .Storage .NewArtifactFor (obj .Kind , obj , revision , fmt .Sprintf ("%s.tar.gz" , revision ))
352
- conditions .MarkTrue (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationSucceedReason , "Downloaded %d bucket objects from %q" , objCount , obj .Spec .BucketName )
353
+ * artifact = r .Storage .NewArtifactFor (obj .Kind , obj , checksum , fmt .Sprintf ("%s.tar.gz" , checksum ))
354
+ conditions .MarkTrue (obj , sourcev1 .SourceAvailableCondition , sourcev1 .BucketOperationSucceedReason , "Downloaded %d objects from bucket %q" , objCount , obj .Spec .BucketName )
353
355
354
356
return ctrl.Result {RequeueAfter : obj .Spec .Interval .Duration }, nil
355
357
}
@@ -363,7 +365,7 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, obj *sourcev1.
363
365
// The artifact is up-to-date
364
366
if obj .GetArtifact ().HasRevision (artifact .Revision ) {
365
367
logr .FromContext (ctx ).Info ("Artifact is up-to-date" )
366
- conditions .MarkTrue (obj , sourcev1 .ArtifactAvailableCondition , "ArchivedArtifact" , "Compressed source to artifact with revision %s " , artifact .Revision )
368
+ conditions .MarkTrue (obj , sourcev1 .ArtifactAvailableCondition , meta . SucceededReason , "Compressed source to artifact with revision '%s' " , artifact .Revision )
367
369
return ctrl.Result {RequeueAfter : obj .GetInterval ().Duration }, nil
368
370
}
369
371
@@ -390,17 +392,17 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, obj *sourcev1.
390
392
defer unlock ()
391
393
392
394
// Archive directory to storage
393
- if err : = r .Storage .Archive (& artifact , dir , nil ); err != nil {
395
+ if err = r .Storage .Archive (& artifact , dir , nil ); err != nil {
394
396
conditions .MarkFalse (obj , sourcev1 .ArtifactAvailableCondition , sourcev1 .StorageOperationFailedReason , "Unable to archive artifact to storage: %s" , err )
395
397
return ctrl.Result {}, err
396
398
}
397
399
398
400
// Record it on the object
399
401
obj .Status .Artifact = artifact .DeepCopy ()
400
- conditions .MarkTrue (obj , sourcev1 .ArtifactAvailableCondition , "ArchivedArtifact" , "Compressed source to artifact with revision %s " , artifact .Revision )
402
+ conditions .MarkTrue (obj , sourcev1 .ArtifactAvailableCondition , meta . SucceededReason , "Compressed source to artifact with revision '%s' " , artifact .Revision )
401
403
r .Events .EventWithMetaf (ctx , obj , map [string ]string {
402
404
"revision" : obj .GetArtifact ().Revision ,
403
- }, events .EventSeverityInfo , sourcev1 . GitOperationSucceedReason , conditions .Get (obj , sourcev1 .ArtifactAvailableCondition ).Message )
405
+ }, events .EventSeverityInfo , meta . SucceededReason , conditions .Get (obj , sourcev1 .ArtifactAvailableCondition ).Message )
404
406
405
407
// Update symlink on a "best effort" basis
406
408
url , err := r .Storage .Symlink (artifact , "latest.tar.gz" )
@@ -458,10 +460,6 @@ func (r *BucketReconciler) buildClient(obj *sourcev1.Bucket, secret *corev1.Secr
458
460
opts .Creds = credentials .NewIAM ("" )
459
461
}
460
462
461
- if opts .Creds == nil {
462
- return nil , fmt .Errorf ("no bucket credentials configured" )
463
- }
464
-
465
463
return minio .New (obj .Spec .Endpoint , & opts )
466
464
}
467
465
0 commit comments