controllers: truncate temporary cached Helm index
Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
parent
028a85d61a
commit
ad0993e93e
|
@ -416,6 +416,10 @@ func (r *HelmRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *s
|
||||||
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason,
|
conditions.MarkTrue(obj, meta.ReadyCondition, meta.SucceededReason,
|
||||||
"stored artifact for revision '%s'", artifact.Revision)
|
"stored artifact for revision '%s'", artifact.Revision)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := chartRepo.RemoveCache(); err != nil {
|
||||||
|
ctrl.LoggerFrom(ctx).Error(err, "failed to remove temporary cached index file")
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if obj.GetArtifact().HasRevision(artifact.Revision) {
|
if obj.GetArtifact().HasRevision(artifact.Revision) {
|
||||||
|
@ -427,10 +431,7 @@ func (r *HelmRepositoryReconciler) reconcileArtifact(ctx context.Context, obj *s
|
||||||
// and they have to be reconciled.
|
// and they have to be reconciled.
|
||||||
conditions.MarkReconciling(obj, "NewRevision", "new index revision '%s'", artifact.Revision)
|
conditions.MarkReconciling(obj, "NewRevision", "new index revision '%s'", artifact.Revision)
|
||||||
|
|
||||||
// Clear cache at the very end.
|
// Create artifact dir
|
||||||
defer chartRepo.RemoveCache()
|
|
||||||
|
|
||||||
// Create artifact dir.
|
|
||||||
if err := r.Storage.MkdirAll(*artifact); err != nil {
|
if err := r.Storage.MkdirAll(*artifact); err != nil {
|
||||||
return sreconcile.ResultEmpty, &serror.Event{
|
return sreconcile.ResultEmpty, &serror.Event{
|
||||||
Err: fmt.Errorf("failed to create artifact directory: %w", err),
|
Err: fmt.Errorf("failed to create artifact directory: %w", err),
|
||||||
|
|
|
@ -471,9 +471,9 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
|
||||||
|
|
||||||
var chartRepo repository.ChartRepository
|
var chartRepo repository.ChartRepository
|
||||||
var artifact sourcev1.Artifact
|
var artifact sourcev1.Artifact
|
||||||
dlog := log.NewDelegatingLogSink(log.NullLogSink{})
|
got, err := r.reconcileSource(context.TODO(), obj, &artifact, &chartRepo)
|
||||||
nullLogger := logr.New(dlog)
|
defer os.Remove(chartRepo.CachePath)
|
||||||
got, err := r.reconcileSource(logr.NewContext(ctx, nullLogger), obj, &artifact, &chartRepo)
|
|
||||||
g.Expect(obj.Status.Conditions).To(conditions.MatchConditions(tt.assertConditions))
|
g.Expect(obj.Status.Conditions).To(conditions.MatchConditions(tt.assertConditions))
|
||||||
g.Expect(err != nil).To(Equal(tt.wantErr))
|
g.Expect(err != nil).To(Equal(tt.wantErr))
|
||||||
g.Expect(got).To(Equal(tt.want))
|
g.Expect(got).To(Equal(tt.want))
|
||||||
|
|
Loading…
Reference in New Issue