@@ -63,6 +63,7 @@ var gitRepositoryReadyCondition = summarize.Conditions{
63
63
sourcev1 .FetchFailedCondition ,
64
64
sourcev1 .IncludeUnavailableCondition ,
65
65
sourcev1 .ArtifactOutdatedCondition ,
66
+ sourcev1 .StorageOperationFailedCondition ,
66
67
meta .ReadyCondition ,
67
68
meta .ReconcilingCondition ,
68
69
meta .StalledCondition ,
@@ -72,13 +73,15 @@ var gitRepositoryReadyCondition = summarize.Conditions{
72
73
sourcev1 .SourceVerifiedCondition ,
73
74
sourcev1 .FetchFailedCondition ,
74
75
sourcev1 .ArtifactOutdatedCondition ,
76
+ sourcev1 .StorageOperationFailedCondition ,
75
77
meta .StalledCondition ,
76
78
meta .ReconcilingCondition ,
77
79
},
78
80
NegativePolarity : []string {
79
81
sourcev1 .FetchFailedCondition ,
80
82
sourcev1 .IncludeUnavailableCondition ,
81
83
sourcev1 .ArtifactOutdatedCondition ,
84
+ sourcev1 .StorageOperationFailedCondition ,
82
85
meta .StalledCondition ,
83
86
meta .ReconcilingCondition ,
84
87
},
@@ -213,16 +216,19 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
213
216
// Create temp dir for Git clone
214
217
tmpDir , err := util .TempDirForObj ("" , obj )
215
218
if err != nil {
216
- return sreconcile . ResultEmpty , & serror.Event {
217
- Err : fmt .Errorf ("failed to create temporary directory: %w" , err ),
218
- Reason : sourcev1 .StorageOperationFailedReason ,
219
+ e := & serror.Event {
220
+ Err : fmt .Errorf ("failed to create temporary working directory: %w" , err ),
221
+ Reason : sourcev1 .DirCreationFailedReason ,
219
222
}
223
+ conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
224
+ return sreconcile .ResultEmpty , e
220
225
}
221
226
defer func () {
222
227
if err = os .RemoveAll (tmpDir ); err != nil {
223
228
ctrl .LoggerFrom (ctx ).Error (err , "failed to remove temporary working directory" )
224
229
}
225
230
}()
231
+ conditions .Delete (obj , sourcev1 .StorageOperationFailedCondition )
226
232
227
233
// Run the sub-reconcilers and build the result of reconciliation.
228
234
var (
@@ -322,7 +328,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
322
328
Err : fmt .Errorf ("failed to get secret '%s': %w" , name .String (), err ),
323
329
Reason : sourcev1 .AuthenticationFailedReason ,
324
330
}
325
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 . AuthenticationFailedReason , e .Err .Error ())
331
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e . Reason , e .Err .Error ())
326
332
// Return error as the world as observed may change
327
333
return sreconcile .ResultEmpty , e
328
334
}
@@ -338,7 +344,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
338
344
Err : fmt .Errorf ("failed to configure auth strategy for Git implementation '%s': %w" , obj .Spec .GitImplementation , err ),
339
345
Reason : sourcev1 .AuthenticationFailedReason ,
340
346
}
341
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 . AuthenticationFailedReason , e .Err .Error ())
347
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e . Reason , e .Err .Error ())
342
348
// Return error as the contents of the secret may change
343
349
return sreconcile .ResultEmpty , e
344
350
}
@@ -358,7 +364,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
358
364
Err : fmt .Errorf ("failed to configure checkout strategy for Git implementation '%s': %w" , obj .Spec .GitImplementation , err ),
359
365
Reason : sourcev1 .GitOperationFailedReason ,
360
366
}
361
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 . GitOperationFailedReason , e .Err .Error ())
367
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e . Reason , e .Err .Error ())
362
368
// Do not return err as recovery without changes is impossible
363
369
return sreconcile .ResultEmpty , e
364
370
}
@@ -372,7 +378,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
372
378
Err : fmt .Errorf ("failed to checkout and determine revision: %w" , err ),
373
379
Reason : sourcev1 .GitOperationFailedReason ,
374
380
}
375
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 . GitOperationFailedReason , e .Err .Error ())
381
+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e . Reason , e .Err .Error ())
376
382
// Coin flip on transient or persistent error, return error and hope for the best
377
383
return sreconcile .ResultEmpty , e
378
384
}
@@ -429,24 +435,27 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context,
429
435
// Ensure target path exists and is a directory
430
436
if f , err := os .Stat (dir ); err != nil {
431
437
e := & serror.Event {
432
- Err : fmt .Errorf ("failed to stat target path: %w" , err ),
433
- Reason : sourcev1 .StorageOperationFailedReason ,
438
+ Err : fmt .Errorf ("failed to stat target artifact path: %w" , err ),
439
+ Reason : sourcev1 .StatOperationFailedReason ,
434
440
}
441
+ conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
435
442
return sreconcile .ResultEmpty , e
436
443
} else if ! f .IsDir () {
437
444
e := & serror.Event {
438
445
Err : fmt .Errorf ("invalid target path: '%s' is not a directory" , dir ),
439
- Reason : sourcev1 .StorageOperationFailedReason ,
446
+ Reason : sourcev1 .InvalidPathReason ,
440
447
}
448
+ conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
441
449
return sreconcile .ResultEmpty , e
442
450
}
443
451
444
452
// Ensure artifact directory exists and acquire lock
445
453
if err := r .Storage .MkdirAll (artifact ); err != nil {
446
454
e := & serror.Event {
447
455
Err : fmt .Errorf ("failed to create artifact directory: %w" , err ),
448
- Reason : sourcev1 .StorageOperationFailedReason ,
456
+ Reason : sourcev1 .DirCreationFailedReason ,
449
457
}
458
+ conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
450
459
return sreconcile .ResultEmpty , e
451
460
}
452
461
unlock , err := r .Storage .Lock (artifact )
@@ -472,10 +481,12 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context,
472
481
473
482
// Archive directory to storage
474
483
if err := r .Storage .Archive (& artifact , dir , SourceIgnoreFilter (ps , nil )); err != nil {
475
- return sreconcile . ResultEmpty , & serror.Event {
484
+ e := & serror.Event {
476
485
Err : fmt .Errorf ("unable to archive artifact to storage: %w" , err ),
477
- Reason : sourcev1 .StorageOperationFailedReason ,
486
+ Reason : sourcev1 .ArchiveOperationFailedReason ,
478
487
}
488
+ conditions .MarkTrue (obj , sourcev1 .StorageOperationFailedCondition , e .Reason , e .Err .Error ())
489
+ return sreconcile .ResultEmpty , e
479
490
}
480
491
r .AnnotatedEventf (obj , map [string ]string {
481
492
"revision" : artifact .Revision ,
@@ -489,12 +500,13 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context,
489
500
// Update symlink on a "best effort" basis
490
501
url , err := r .Storage .Symlink (artifact , "latest.tar.gz" )
491
502
if err != nil {
492
- r .eventLogf (ctx , obj , corev1 . EventTypeWarning , sourcev1 .StorageOperationFailedReason ,
503
+ r .eventLogf (ctx , obj , events . EventTypeTrace , sourcev1 .SymlinkUpdateFailedReason ,
493
504
"failed to update status URL symlink: %s" , err )
494
505
}
495
506
if url != "" {
496
507
obj .Status .URL = url
497
508
}
509
+ conditions .Delete (obj , sourcev1 .StorageOperationFailedCondition )
498
510
return sreconcile .ResultSuccess , nil
499
511
}
500
512
@@ -520,7 +532,7 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context,
520
532
Err : fmt .Errorf ("path calculation for include '%s' failed: %w" , incl .GitRepositoryRef .Name , err ),
521
533
Reason : "IllegalPath" ,
522
534
}
523
- conditions .MarkTrue (obj , sourcev1 .IncludeUnavailableCondition , "IllegalPath" , e .Err .Error ())
535
+ conditions .MarkTrue (obj , sourcev1 .IncludeUnavailableCondition , e . Reason , e .Err .Error ())
524
536
return sreconcile .ResultEmpty , e
525
537
}
526
538
@@ -531,7 +543,7 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context,
531
543
Err : fmt .Errorf ("could not get resource for include '%s': %w" , incl .GitRepositoryRef .Name , err ),
532
544
Reason : "NotFound" ,
533
545
}
534
- conditions .MarkTrue (obj , sourcev1 .IncludeUnavailableCondition , "NotFound" , e .Err .Error ())
546
+ conditions .MarkTrue (obj , sourcev1 .IncludeUnavailableCondition , e . Reason , e .Err .Error ())
535
547
return sreconcile .ResultEmpty , err
536
548
}
537
549
@@ -541,7 +553,7 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context,
541
553
Err : fmt .Errorf ("no artifact available for include '%s'" , incl .GitRepositoryRef .Name ),
542
554
Reason : "NoArtifact" ,
543
555
}
544
- conditions .MarkTrue (obj , sourcev1 .IncludeUnavailableCondition , "NoArtifact" , e .Err .Error ())
556
+ conditions .MarkTrue (obj , sourcev1 .IncludeUnavailableCondition , e . Reason , e .Err .Error ())
545
557
return sreconcile .ResultEmpty , e
546
558
}
547
559
@@ -551,7 +563,7 @@ func (r *GitRepositoryReconciler) reconcileInclude(ctx context.Context,
551
563
Err : fmt .Errorf ("failed to copy '%s' include from %s to %s: %w" , incl .GitRepositoryRef .Name , incl .GetFromPath (), incl .GetToPath (), err ),
552
564
Reason : "CopyFailure" ,
553
565
}
554
- conditions .MarkTrue (obj , sourcev1 .IncludeUnavailableCondition , "CopyFailure" , e .Err .Error ())
566
+ conditions .MarkTrue (obj , sourcev1 .IncludeUnavailableCondition , e . Reason , e .Err .Error ())
555
567
return sreconcile .ResultEmpty , e
556
568
}
557
569
artifacts [i ] = dep .GetArtifact ().DeepCopy ()
@@ -598,7 +610,7 @@ func (r *GitRepositoryReconciler) verifyCommitSignature(ctx context.Context, obj
598
610
Err : fmt .Errorf ("PGP public keys secret error: %w" , err ),
599
611
Reason : "VerificationError" ,
600
612
}
601
- conditions .MarkFalse (obj , sourcev1 .SourceVerifiedCondition , meta . FailedReason , e .Err .Error ())
613
+ conditions .MarkFalse (obj , sourcev1 .SourceVerifiedCondition , e . Reason , e .Err .Error ())
602
614
return sreconcile .ResultEmpty , e
603
615
}
604
616
@@ -612,7 +624,7 @@ func (r *GitRepositoryReconciler) verifyCommitSignature(ctx context.Context, obj
612
624
Err : fmt .Errorf ("signature verification of commit '%s' failed: %w" , commit .Hash .String (), err ),
613
625
Reason : "InvalidCommitSignature" ,
614
626
}
615
- conditions .MarkFalse (obj , sourcev1 .SourceVerifiedCondition , meta . FailedReason , e .Err .Error ())
627
+ conditions .MarkFalse (obj , sourcev1 .SourceVerifiedCondition , e . Reason , e .Err .Error ())
616
628
// Return error in the hope the secret changes
617
629
return sreconcile .ResultEmpty , e
618
630
}
0 commit comments