@@ -398,6 +398,8 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, obj *sou
398398 return sreconcile .ResultEmpty , e
399399 }
400400 }
401+
402+ // Fetch the repository index from remote.
401403 checksum , err := newChartRepo .CacheIndex ()
402404 if err != nil {
403405 e := & serror.Event {
@@ -410,6 +412,15 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, obj *sou
410412 }
411413 * chartRepo = * newChartRepo
412414
415+ // Short-circuit based on the fetched index being an exact match to the
416+ // stored Artifact. This prevents having to unmarshal the YAML to calculate
417+ // the (stable) revision, which is a memory expensive operation.
418+ if obj .GetArtifact ().HasChecksum (checksum ) {
419+ * artifact = * obj .GetArtifact ()
420+ conditions .Delete (obj , sourcev1 .FetchFailedCondition )
421+ return sreconcile .ResultSuccess , nil
422+ }
423+
413424 // Load the cached repository index to ensure it passes validation.
414425 if err := chartRepo .LoadFromCache (); err != nil {
415426 e := & serror.Event {
@@ -419,23 +430,24 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, obj *sou
419430 conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , e .Err .Error ())
420431 return sreconcile .ResultEmpty , e
421432 }
422- defer chartRepo .Unload ()
433+ chartRepo .Unload ()
423434
424435 // Mark observations about the revision on the object.
425- if ! obj .GetArtifact ().HasRevision (checksum ) {
436+ if ! obj .GetArtifact ().HasRevision (newChartRepo . Checksum ) {
426437 message := fmt .Sprintf ("new index revision '%s'" , checksum )
427438 conditions .MarkTrue (obj , sourcev1 .ArtifactOutdatedCondition , "NewRevision" , message )
428439 conditions .MarkReconciling (obj , "NewRevision" , message )
429440 }
430441
431- conditions .Delete (obj , sourcev1 .FetchFailedCondition )
432-
433442 // Create potential new artifact.
434443 * artifact = r .Storage .NewArtifactFor (obj .Kind ,
435444 obj .ObjectMeta .GetObjectMeta (),
436445 chartRepo .Checksum ,
437446 fmt .Sprintf ("index-%s.yaml" , checksum ))
438447
448+ // Delete any stale failure observation
449+ conditions .Delete (obj , sourcev1 .FetchFailedCondition )
450+
439451 return sreconcile .ResultSuccess , nil
440452}
441453
@@ -462,7 +474,7 @@ func (r *HelmRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *s
462474 }
463475 }()
464476
465- if obj .GetArtifact ().HasRevision (artifact .Revision ) {
477+ if obj .GetArtifact ().HasRevision (artifact .Revision ) && obj . GetArtifact (). HasChecksum ( artifact . Checksum ) {
466478 r .eventLogf (ctx , obj , events .EventTypeTrace , sourcev1 .ArtifactUpToDateReason , "artifact up-to-date with remote revision: '%s'" , artifact .Revision )
467479 return sreconcile .ResultSuccess , nil
468480 }
0 commit comments