Skip to content

Commit

Permalink
helm: optimise repository index loading
Browse files Browse the repository at this point in the history
Avoid validating (and thus loading) indexes if the checksum already exists in storage.
In other words, if the YAML is identical to the Artifact in storage, the reconciliation should
be a no-op, and therefore can short-circuit long/heavy operations.

Co-authored-by: Hidde Beydals <[email protected]>
Signed-off-by: Paulo Gomes <[email protected]>
  • Loading branch information
Paulo Gomes and hiddeco committed Apr 25, 2022
1 parent cfbe6ac commit 3b8ec52
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions controllers/helmrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,19 @@ func (r *HelmRepositoryReconciler) reconcileSource(ctx context.Context, obj *sou
}
*chartRepo = *newChartRepo

// Load the cached repository index to ensure it passes validation.
if err := chartRepo.LoadFromCache(); err != nil {
e := &serror.Event{
Err: fmt.Errorf("failed to load Helm repository from cache: %w", err),
Reason: sourcev1.IndexationFailedReason,
}
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
return sreconcile.ResultEmpty, e
}
defer chartRepo.Unload()

// Mark observations about the revision on the object.
if !obj.GetArtifact().HasRevision(checksum) {
// Load the cached repository index to ensure it passes validation.
if err := chartRepo.LoadFromCache(); err != nil {
e := &serror.Event{
Err: fmt.Errorf("failed to load Helm repository from cache: %w", err),
Reason: sourcev1.IndexationFailedReason,
}
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, e.Err.Error())
return sreconcile.ResultEmpty, e
}
chartRepo.Unload()

message := fmt.Sprintf("new index revision '%s'", checksum)
conditions.MarkTrue(obj, sourcev1.ArtifactOutdatedCondition, "NewRevision", message)
conditions.MarkReconciling(obj, "NewRevision", message)
Expand Down

0 comments on commit 3b8ec52

Please sign in to comment.