@@ -107,7 +107,7 @@ type GitRepositoryReconcilerOptions struct {
107
107
108
108
// gitRepoReconcilerFunc is the function type for all the Git repository
109
109
// reconciler functions.
110
- type gitRepoReconcilerFunc func (ctx context.Context , obj * sourcev1.GitRepository , artifact * sourcev1. Artifact , includes * artifactSet , dir string ) (sreconcile.Result , error )
110
+ type gitRepoReconcilerFunc func (ctx context.Context , obj * sourcev1.GitRepository , commit * git. Commit , includes * artifactSet , dir string ) (sreconcile.Result , error )
111
111
112
112
func (r * GitRepositoryReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
113
113
return r .SetupWithManagerAndOptions (mgr , GitRepositoryReconcilerOptions {})
@@ -207,7 +207,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
207
207
conditions .MarkReconciling (obj , "NewGeneration" , "reconciling new object generation (%d)" , obj .Generation )
208
208
}
209
209
210
- var artifact sourcev1. Artifact
210
+ var commit git. Commit
211
211
var includes artifactSet
212
212
213
213
// Create temp dir for Git clone
@@ -224,7 +224,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
224
224
var res sreconcile.Result
225
225
var resErr error
226
226
for _ , rec := range reconcilers {
227
- recResult , err := rec (ctx , obj , & artifact , & includes , tmpDir )
227
+ recResult , err := rec (ctx , obj , & commit , & includes , tmpDir )
228
228
// Exit immediately on ResultRequeue.
229
229
if recResult == sreconcile .ResultRequeue {
230
230
return sreconcile .ResultRequeue , nil
@@ -248,7 +248,8 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, obj *sourcev1.G
248
248
// If the artifact in the Status object of the resource disappeared from storage, it is removed from the object.
249
249
// If the object does not have an artifact in its Status object, a v1beta1.ArtifactUnavailableCondition is set.
250
250
// If the hostname of any of the URLs on the object do not match the current storage server hostname, they are updated.
251
- func (r * GitRepositoryReconciler ) reconcileStorage (ctx context.Context , obj * sourcev1.GitRepository , artifact * sourcev1.Artifact , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
251
+ func (r * GitRepositoryReconciler ) reconcileStorage (ctx context.Context ,
252
+ obj * sourcev1.GitRepository , _ * git.Commit , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
252
253
// Garbage collect previous advertised artifact(s) from storage
253
254
_ = r .garbageCollect (ctx , obj )
254
255
@@ -284,7 +285,7 @@ func (r *GitRepositoryReconciler) reconcileStorage(ctx context.Context, obj *sou
284
285
// If both the checkout and signature verification are successful, the given artifact pointer is set to a new artifact
285
286
// with the available metadata.
286
287
func (r * GitRepositoryReconciler ) reconcileSource (ctx context.Context ,
287
- obj * sourcev1.GitRepository , artifact * sourcev1. Artifact , _ * artifactSet , dir string ) (sreconcile.Result , error ) {
288
+ obj * sourcev1.GitRepository , commit * git. Commit , _ * artifactSet , dir string ) (sreconcile.Result , error ) {
288
289
// Configure authentication strategy to access the source
289
290
var authOpts * git.AuthOptions
290
291
var err error
@@ -344,7 +345,7 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
344
345
// Checkout HEAD of reference in object
345
346
gitCtx , cancel := context .WithTimeout (ctx , obj .Spec .Timeout .Duration )
346
347
defer cancel ()
347
- commit , err := checkoutStrategy .Checkout (gitCtx , dir , obj .Spec .URL , authOpts )
348
+ c , err := checkoutStrategy .Checkout (gitCtx , dir , obj .Spec .URL , authOpts )
348
349
if err != nil {
349
350
e := & serror.Event {
350
351
Err : fmt .Errorf ("failed to checkout and determine revision: %w" , err ),
@@ -354,6 +355,8 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
354
355
// Coin flip on transient or persistent error, return error and hope for the best
355
356
return sreconcile .ResultEmpty , e
356
357
}
358
+ // Assign the commit to the shared commit reference.
359
+ * commit = * c
357
360
ctrl .LoggerFrom (ctx ).V (logger .DebugLevel ).Info ("git repository checked out" , "url" , obj .Spec .URL , "revision" , commit .String ())
358
361
conditions .Delete (obj , sourcev1 .FetchFailedCondition )
359
362
@@ -362,9 +365,6 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
362
365
return result , err
363
366
}
364
367
365
- // Create potential new artifact with current available metadata
366
- * artifact = r .Storage .NewArtifactFor (obj .Kind , obj .GetObjectMeta (), commit .String (), fmt .Sprintf ("%s.tar.gz" , commit .Hash .String ()))
367
-
368
368
// Mark observations about the revision on the object
369
369
if ! obj .GetArtifact ().HasRevision (commit .String ()) {
370
370
message := fmt .Sprintf ("new upstream revision '%s'" , commit .String ())
@@ -383,7 +383,11 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context,
383
383
// Source ignore patterns are loaded, and the given directory is archived.
384
384
// On a successful archive, the artifact and includes in the status of the given object are set, and the symlink in the
385
385
// storage is updated to its path.
386
- func (r * GitRepositoryReconciler ) reconcileArtifact (ctx context.Context , obj * sourcev1.GitRepository , artifact * sourcev1.Artifact , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
386
+ func (r * GitRepositoryReconciler ) reconcileArtifact (ctx context.Context ,
387
+ obj * sourcev1.GitRepository , commit * git.Commit , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
388
+ // Create potential new artifact with current available metadata
389
+ artifact := r .Storage .NewArtifactFor (obj .Kind , obj .GetObjectMeta (), commit .String (), fmt .Sprintf ("%s.tar.gz" , commit .Hash .String ()))
390
+
387
391
// Always restore the Ready condition in case it got removed due to a transient error
388
392
defer func () {
389
393
if obj .GetArtifact ().HasRevision (artifact .Revision ) && ! includes .Diff (obj .Status .IncludedArtifacts ) {
@@ -419,14 +423,14 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
419
423
}
420
424
421
425
// Ensure artifact directory exists and acquire lock
422
- if err := r .Storage .MkdirAll (* artifact ); err != nil {
426
+ if err := r .Storage .MkdirAll (artifact ); err != nil {
423
427
e := & serror.Event {
424
428
Err : fmt .Errorf ("failed to create artifact directory: %w" , err ),
425
429
Reason : sourcev1 .StorageOperationFailedReason ,
426
430
}
427
431
return sreconcile .ResultEmpty , e
428
432
}
429
- unlock , err := r .Storage .Lock (* artifact )
433
+ unlock , err := r .Storage .Lock (artifact )
430
434
if err != nil {
431
435
return sreconcile .ResultEmpty , & serror.Event {
432
436
Err : fmt .Errorf ("failed to acquire lock for artifact: %w" , err ),
@@ -448,7 +452,7 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
448
452
}
449
453
450
454
// Archive directory to storage
451
- if err := r .Storage .Archive (artifact , dir , SourceIgnoreFilter (ps , nil )); err != nil {
455
+ if err := r .Storage .Archive (& artifact , dir , SourceIgnoreFilter (ps , nil )); err != nil {
452
456
return sreconcile .ResultEmpty , & serror.Event {
453
457
Err : fmt .Errorf ("unable to archive artifact to storage: %w" , err ),
454
458
Reason : sourcev1 .StorageOperationFailedReason ,
@@ -457,14 +461,14 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
457
461
r .AnnotatedEventf (obj , map [string ]string {
458
462
"revision" : artifact .Revision ,
459
463
"checksum" : artifact .Checksum ,
460
- }, corev1 .EventTypeNormal , "NewArtifact" , "stored artifact for revision '%s'" , artifact . Revision )
464
+ }, corev1 .EventTypeNormal , "NewArtifact" , "stored artifact for commit '%s'" , commit . ShortMessage () )
461
465
462
466
// Record it on the object
463
467
obj .Status .Artifact = artifact .DeepCopy ()
464
468
obj .Status .IncludedArtifacts = * includes
465
469
466
470
// Update symlink on a "best effort" basis
467
- url , err := r .Storage .Symlink (* artifact , "latest.tar.gz" )
471
+ url , err := r .Storage .Symlink (artifact , "latest.tar.gz" )
468
472
if err != nil {
469
473
r .eventLogf (ctx , obj , corev1 .EventTypeWarning , sourcev1 .StorageOperationFailedReason ,
470
474
"failed to update status URL symlink: %s" , err )
@@ -481,7 +485,8 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *so
481
485
// If an include is unavailable, it marks the object with v1beta1.IncludeUnavailableCondition and returns early.
482
486
// If the copy operations are successful, it deletes the v1beta1.IncludeUnavailableCondition from the object.
483
487
// If the artifactSet differs from the current set, it marks the object with v1beta1.ArtifactOutdatedCondition.
484
- func (r * GitRepositoryReconciler ) reconcileInclude (ctx context.Context , obj * sourcev1.GitRepository , _ * sourcev1.Artifact , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
488
+ func (r * GitRepositoryReconciler ) reconcileInclude (ctx context.Context ,
489
+ obj * sourcev1.GitRepository , _ * git.Commit , includes * artifactSet , dir string ) (sreconcile.Result , error ) {
485
490
artifacts := make (artifactSet , len (obj .Spec .Include ))
486
491
for i , incl := range obj .Spec .Include {
487
492
// Do this first as it is much cheaper than copy operations
0 commit comments