Skip to content

Commit 68947cf

Browse files
committed
controllers: resolve issue with gc on delete
When a delete of a resource is requested a `deletionTimestamp` is set on the resource by the requester, this also results in a generation change of the resource. If the resource is under reconciliation while this timestamp is set, and had not produced an artifact earlier on, this becomes a problem as the artifact metadata is used to determine what should be garbage collected on a deletion, resulting in stray files for resources that are no longer present. To resolve this for now, we always create a new artifact object for the resource when `all==true` on the GC method call, and no longer rely on the presence of the artifact object on the resource itself.
1 parent 99b74da commit 68947cf

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

controllers/gitrepository_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,10 @@ func (r *GitRepositoryReconciler) verify(ctx context.Context, publicKeySecret ty
302302
// gc performs a garbage collection on all but current artifacts of
303303
// the given repository.
304304
func (r *GitRepositoryReconciler) gc(repository sourcev1.GitRepository, all bool) error {
305+
if all {
306+
return r.Storage.RemoveAll(r.Storage.ArtifactFor(repository.Kind, repository.GetObjectMeta(), "", "", ""))
307+
}
305308
if repository.Status.Artifact != nil {
306-
if all {
307-
return r.Storage.RemoveAll(*repository.Status.Artifact)
308-
}
309309
return r.Storage.RemoveAllButCurrent(*repository.Status.Artifact)
310310
}
311311
return nil

controllers/helmchart_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,10 @@ func (r *HelmChartReconciler) getGitRepositoryWithArtifact(ctx context.Context,
435435
// gc performs a garbage collection on all but current artifacts of
436436
// the given chart.
437437
func (r *HelmChartReconciler) gc(chart sourcev1.HelmChart, all bool) error {
438+
if all {
439+
return r.Storage.RemoveAll(r.Storage.ArtifactFor(chart.Kind, chart.GetObjectMeta(), "", "", ""))
440+
}
438441
if chart.Status.Artifact != nil {
439-
if all {
440-
return r.Storage.RemoveAll(*chart.Status.Artifact)
441-
}
442442
return r.Storage.RemoveAllButCurrent(*chart.Status.Artifact)
443443
}
444444
return nil

controllers/helmrepository_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ func (r *HelmRepositoryReconciler) shouldResetStatus(repository sourcev1.HelmRep
294294
// gc performs a garbage collection on all but current artifacts of
295295
// the given repository.
296296
func (r *HelmRepositoryReconciler) gc(repository sourcev1.HelmRepository, all bool) error {
297+
if all {
298+
return r.Storage.RemoveAll(r.Storage.ArtifactFor(repository.Kind, repository.GetObjectMeta(), "", "", ""))
299+
}
297300
if repository.Status.Artifact != nil {
298-
if all {
299-
return r.Storage.RemoveAll(*repository.Status.Artifact)
300-
}
301301
return r.Storage.RemoveAllButCurrent(*repository.Status.Artifact)
302302
}
303303
return nil

0 commit comments

Comments
 (0)