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.
This commit is contained in:
Hidde Beydals 2020-09-09 13:33:50 +02:00
parent 99b74da044
commit 68947cfca6
3 changed files with 9 additions and 9 deletions

View File

@ -302,10 +302,10 @@ func (r *GitRepositoryReconciler) verify(ctx context.Context, publicKeySecret ty
// gc performs a garbage collection on all but current artifacts of
// the given repository.
func (r *GitRepositoryReconciler) gc(repository sourcev1.GitRepository, all bool) error {
if all {
return r.Storage.RemoveAll(r.Storage.ArtifactFor(repository.Kind, repository.GetObjectMeta(), "", "", ""))
}
if repository.Status.Artifact != nil {
if all {
return r.Storage.RemoveAll(*repository.Status.Artifact)
}
return r.Storage.RemoveAllButCurrent(*repository.Status.Artifact)
}
return nil

View File

@ -435,10 +435,10 @@ func (r *HelmChartReconciler) getGitRepositoryWithArtifact(ctx context.Context,
// gc performs a garbage collection on all but current artifacts of
// the given chart.
func (r *HelmChartReconciler) gc(chart sourcev1.HelmChart, all bool) error {
if all {
return r.Storage.RemoveAll(r.Storage.ArtifactFor(chart.Kind, chart.GetObjectMeta(), "", "", ""))
}
if chart.Status.Artifact != nil {
if all {
return r.Storage.RemoveAll(*chart.Status.Artifact)
}
return r.Storage.RemoveAllButCurrent(*chart.Status.Artifact)
}
return nil

View File

@ -294,10 +294,10 @@ func (r *HelmRepositoryReconciler) shouldResetStatus(repository sourcev1.HelmRep
// gc performs a garbage collection on all but current artifacts of
// the given repository.
func (r *HelmRepositoryReconciler) gc(repository sourcev1.HelmRepository, all bool) error {
if all {
return r.Storage.RemoveAll(r.Storage.ArtifactFor(repository.Kind, repository.GetObjectMeta(), "", "", ""))
}
if repository.Status.Artifact != nil {
if all {
return r.Storage.RemoveAll(*repository.Status.Artifact)
}
return r.Storage.RemoveAllButCurrent(*repository.Status.Artifact)
}
return nil