Skip to content

Commit c0a1099

Browse files
committed
helm: only use Digest to calculcate index revision
In #1001 bits around the Helm repository reconciliation logic were rewritten, mostly based on the documented behavior instead of the actual code. This resulted in the reintroduction of a YAML marshal of the (sorted) index YAML instead of reliance of just the checksum of the file. This to take situations into account in which a repository would e.g. provide a new random order on every generation. However, this approach is (extremely) expensive as the marshal goes through a JSON -> YAML loop, eating lots of RAM in the process. As the further (silently) introduced behavior has not resulted in any reported issues, I deem this approach safe and better than e.g. encoding to just JSON which would still require a substantial amount of memory. Signed-off-by: Hidde Beydals <[email protected]>
1 parent 568b932 commit c0a1099

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

controllers/helmrepository_controller.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc
475475
}
476476
if curDig.Validate() == nil {
477477
// Short-circuit based on the fetched index being an exact match to the
478-
// stored Artifact. This prevents having to unmarshal the YAML to calculate
479-
// the (stable) revision, which is a memory expensive operation.
478+
// stored Artifact.
480479
if newDig := chartRepo.Digest(curDig.Algorithm()); newDig.Validate() == nil && (newDig == curDig) {
481480
*artifact = *curArtifact
482481
conditions.Delete(obj, sourcev1.FetchFailedCondition)
@@ -501,11 +500,11 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, sp *patc
501500
var changed bool
502501
if artifact := obj.Status.Artifact; artifact != nil {
503502
curRev := digest.Digest(sourcev1.TransformLegacyRevision(artifact.Revision))
504-
changed = curRev.Validate() != nil || curRev != chartRepo.Revision(curRev.Algorithm())
503+
changed = curRev.Validate() != nil || curRev != chartRepo.Digest(curRev.Algorithm())
505504
}
506505

507506
// Calculate revision.
508-
revision := chartRepo.Revision(intdigest.Canonical)
507+
revision := chartRepo.Digest(intdigest.Canonical)
509508
if revision.Validate() != nil {
510509
e := &serror.Event{
511510
Err: fmt.Errorf("failed to calculate revision: %w", err),

internal/helm/repository/chart_repository.go

+2
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ func (r *ChartRepository) DownloadIndex(w io.Writer) (err error) {
386386

387387
// Revision returns the revision of the ChartRepository's Index. It assumes
388388
// the Index is stable sorted.
389+
// Deprecated: because of expensive memory usage of (YAML) marshal operations.
390+
// We only use Digest now.
389391
func (r *ChartRepository) Revision(algorithm digest.Algorithm) digest.Digest {
390392
if !r.HasIndex() {
391393
return ""

0 commit comments

Comments
 (0)