Skip to content

Commit ad0993e

Browse files
committed
controllers: truncate temporary cached Helm index
Signed-off-by: Hidde Beydals <[email protected]>
1 parent 028a85d commit ad0993e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

controllers/helmrepository_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ func (r *HelmRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *s
416416
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason,
417417
"stored artifact for revision '%s'", artifact.Revision)
418418
}
419+
420+
if err := chartRepo.RemoveCache(); err != nil {
421+
ctrl.LoggerFrom(ctx).Error(err, "failed to remove temporary cached index file")
422+
}
419423
}()
420424

421425
if obj.GetArtifact().HasRevision(artifact.Revision) {
@@ -427,10 +431,7 @@ func (r *HelmRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *s
427431
// and they have to be reconciled.
428432
conditions.MarkReconciling(obj, "NewRevision", "new index revision '%s'", artifact.Revision)
429433

430-
// Clear cache at the very end.
431-
defer chartRepo.RemoveCache()
432-
433-
// Create artifact dir.
434+
// Create artifact dir
434435
if err := r.Storage.MkdirAll(*artifact); err != nil {
435436
return sreconcile.ResultEmpty, &serror.Event{
436437
Err: fmt.Errorf("failed to create artifact directory: %w", err),

controllers/helmrepository_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
471471

472472
var chartRepo repository.ChartRepository
473473
var artifact sourcev1.Artifact
474-
dlog := log.NewDelegatingLogSink(log.NullLogSink{})
475-
nullLogger := logr.New(dlog)
476-
got, err := r.reconcileSource(logr.NewContext(ctx, nullLogger), obj, &artifact, &chartRepo)
474+
got, err := r.reconcileSource(context.TODO(), obj, &artifact, &chartRepo)
475+
defer os.Remove(chartRepo.CachePath)
476+
477477
g.Expect(obj.Status.Conditions).To(conditions.MatchConditions(tt.assertConditions))
478478
g.Expect(err != nil).To(Equal(tt.wantErr))
479479
g.Expect(got).To(Equal(tt.want))

0 commit comments

Comments
 (0)