Skip to content

Commit 1297f8b

Browse files
authored
Merge pull request #208 from fluxcd/gc-bugfix
2 parents d326ae4 + 2f50e3f commit 1297f8b

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

controllers/bucket_controller.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (r *BucketReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
108108
}
109109

110110
// purge old artifacts from storage
111-
if err := r.gc(bucket, false); err != nil {
111+
if err := r.gc(bucket); err != nil {
112112
log.Error(err, "unable to purge old artifacts")
113113
}
114114

@@ -252,7 +252,7 @@ func (r *BucketReconciler) reconcile(ctx context.Context, bucket sourcev1.Bucket
252252
}
253253

254254
func (r *BucketReconciler) reconcileDelete(ctx context.Context, bucket sourcev1.Bucket) (ctrl.Result, error) {
255-
if err := r.gc(bucket, true); err != nil {
255+
if err := r.gc(bucket); err != nil {
256256
r.event(bucket, events.EventSeverityError, fmt.Sprintf("garbage collection for deleted resource failed: %s", err.Error()))
257257
// Return the error so we retry the failed garbage collection
258258
return ctrl.Result{}, err
@@ -349,10 +349,13 @@ func (r *BucketReconciler) resetStatus(bucket sourcev1.Bucket) (sourcev1.Bucket,
349349
return bucket, false
350350
}
351351

352-
// gc performs a garbage collection on all but current artifacts of the given bucket.
353-
func (r *BucketReconciler) gc(bucket sourcev1.Bucket, all bool) error {
354-
if all {
355-
return r.Storage.RemoveAll(r.Storage.NewArtifactFor(bucket.Kind, bucket.GetObjectMeta(), "", ""))
352+
// gc performs a garbage collection for the given v1beta1.Bucket.
353+
// It removes all but the current artifact except for when the
354+
// deletion timestamp is set, which will result in the removal of
355+
// all artifacts for the resource.
356+
func (r *BucketReconciler) gc(bucket sourcev1.Bucket) error {
357+
if !bucket.DeletionTimestamp.IsZero() {
358+
return r.Storage.RemoveAll(r.Storage.NewArtifactFor(bucket.Kind, bucket.GetObjectMeta(), "", "*"))
356359
}
357360
if bucket.GetArtifact() != nil {
358361
return r.Storage.RemoveAllButCurrent(*bucket.GetArtifact())

controllers/gitrepository_controller.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
107107
}
108108

109109
// purge old artifacts from storage
110-
if err := r.gc(repository, false); err != nil {
110+
if err := r.gc(repository); err != nil {
111111
log.Error(err, "unable to purge old artifacts")
112112
}
113113

@@ -250,7 +250,7 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
250250
}
251251

252252
func (r *GitRepositoryReconciler) reconcileDelete(ctx context.Context, repository sourcev1.GitRepository) (ctrl.Result, error) {
253-
if err := r.gc(repository, true); err != nil {
253+
if err := r.gc(repository); err != nil {
254254
r.event(repository, events.EventSeverityError, fmt.Sprintf("garbage collection for deleted resource failed: %s", err.Error()))
255255
// Return the error so we retry the failed garbage collection
256256
return ctrl.Result{}, err
@@ -308,11 +308,13 @@ func (r *GitRepositoryReconciler) resetStatus(repository sourcev1.GitRepository)
308308
return repository, false
309309
}
310310

311-
// gc performs a garbage collection on all but current artifacts of
312-
// the given repository.
313-
func (r *GitRepositoryReconciler) gc(repository sourcev1.GitRepository, all bool) error {
314-
if all {
315-
return r.Storage.RemoveAll(r.Storage.NewArtifactFor(repository.Kind, repository.GetObjectMeta(), "", ""))
311+
// gc performs a garbage collection for the given v1beta1.GitRepository.
312+
// It removes all but the current artifact except for when the
313+
// deletion timestamp is set, which will result in the removal of
314+
// all artifacts for the resource.
315+
func (r *GitRepositoryReconciler) gc(repository sourcev1.GitRepository) error {
316+
if !repository.DeletionTimestamp.IsZero() {
317+
return r.Storage.RemoveAll(r.Storage.NewArtifactFor(repository.Kind, repository.GetObjectMeta(), "", "*"))
316318
}
317319
if repository.GetArtifact() != nil {
318320
return r.Storage.RemoveAllButCurrent(*repository.GetArtifact())

controllers/helmchart_controller.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
114114
}
115115

116116
// Purge all but current artifact from storage
117-
if err := r.gc(chart, false); err != nil {
117+
if err := r.gc(chart); err != nil {
118118
log.Error(err, "unable to purge old artifacts")
119119
}
120120

@@ -589,7 +589,7 @@ func (r *HelmChartReconciler) reconcileFromTarballArtifact(ctx context.Context,
589589

590590
func (r *HelmChartReconciler) reconcileDelete(ctx context.Context, chart sourcev1.HelmChart) (ctrl.Result, error) {
591591
// Our finalizer is still present, so lets handle garbage collection
592-
if err := r.gc(chart, true); err != nil {
592+
if err := r.gc(chart); err != nil {
593593
r.event(chart, events.EventSeverityError, fmt.Sprintf("garbage collection for deleted resource failed: %s", err.Error()))
594594
// Return the error so we retry the failed garbage collection
595595
return ctrl.Result{}, err
@@ -624,11 +624,13 @@ func (r *HelmChartReconciler) resetStatus(chart sourcev1.HelmChart) (sourcev1.He
624624
return chart, false
625625
}
626626

627-
// gc performs a garbage collection on all but the current artifact of
628-
// the given chart.
629-
func (r *HelmChartReconciler) gc(chart sourcev1.HelmChart, all bool) error {
630-
if all {
631-
return r.Storage.RemoveAll(r.Storage.NewArtifactFor(chart.Kind, chart.GetObjectMeta(), "", ""))
627+
// gc performs a garbage collection for the given v1beta1.HelmChart.
628+
// It removes all but the current artifact except for when the
629+
// deletion timestamp is set, which will result in the removal of
630+
// all artifacts for the resource.
631+
func (r *HelmChartReconciler) gc(chart sourcev1.HelmChart) error {
632+
if !chart.DeletionTimestamp.IsZero() {
633+
return r.Storage.RemoveAll(r.Storage.NewArtifactFor(chart.Kind, chart.GetObjectMeta(), "", "*"))
632634
}
633635
if chart.GetArtifact() != nil {
634636
return r.Storage.RemoveAllButCurrent(*chart.GetArtifact())

controllers/helmrepository_controller.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
108108
}
109109

110110
// purge old artifacts from storage
111-
if err := r.gc(repository, false); err != nil {
111+
if err := r.gc(repository); err != nil {
112112
log.Error(err, "unable to purge old artifacts")
113113
}
114114

@@ -248,7 +248,7 @@ func (r *HelmRepositoryReconciler) reconcile(ctx context.Context, repository sou
248248

249249
func (r *HelmRepositoryReconciler) reconcileDelete(ctx context.Context, repository sourcev1.HelmRepository) (ctrl.Result, error) {
250250
// Our finalizer is still present, so lets handle garbage collection
251-
if err := r.gc(repository, true); err != nil {
251+
if err := r.gc(repository); err != nil {
252252
r.event(repository, events.EventSeverityError, fmt.Sprintf("garbage collection for deleted resource failed: %s", err.Error()))
253253
// Return the error so we retry the failed garbage collection
254254
return ctrl.Result{}, err
@@ -282,11 +282,13 @@ func (r *HelmRepositoryReconciler) resetStatus(repository sourcev1.HelmRepositor
282282
return repository, false
283283
}
284284

285-
// gc performs a garbage collection on all but current artifacts of
286-
// the given repository.
287-
func (r *HelmRepositoryReconciler) gc(repository sourcev1.HelmRepository, all bool) error {
288-
if all {
289-
return r.Storage.RemoveAll(r.Storage.NewArtifactFor(repository.Kind, repository.GetObjectMeta(), "", ""))
285+
// gc performs a garbage collection for the given v1beta1.HelmRepository.
286+
// It removes all but the current artifact except for when the
287+
// deletion timestamp is set, which will result in the removal of
288+
// all artifacts for the resource.
289+
func (r *HelmRepositoryReconciler) gc(repository sourcev1.HelmRepository) error {
290+
if !repository.DeletionTimestamp.IsZero() {
291+
return r.Storage.RemoveAll(r.Storage.NewArtifactFor(repository.Kind, repository.GetObjectMeta(), "", "*"))
290292
}
291293
if repository.GetArtifact() != nil {
292294
return r.Storage.RemoveAllButCurrent(*repository.GetArtifact())

0 commit comments

Comments
 (0)