diff --git a/pkg/controllers/chart/chart.go b/pkg/controllers/chart/chart.go index 0c65dc6a..08681fa0 100644 --- a/pkg/controllers/chart/chart.go +++ b/pkg/controllers/chart/chart.go @@ -289,6 +289,20 @@ func (c *Controller) OnRemove(key string, chart *v1.HelmChart) (*v1.HelmChart, e chartCopy.Status.JobName = job.Name newChart, err := c.helms.Update(chartCopy) if err != nil { + // if chart is gone, clean resources + if apierrors.IsNotFound(err) || strings.Contains(err.Error(), "StorageError") { + // note: an empty apply removes all resources owned by this chart + err = generic.ConfigureApplyForObject(c.apply, chart, &generic.GeneratingHandlerOptions{ + AllowClusterScoped: true, + }). + WithOwner(chart). + WithSetID("helm-chart-registration"). + ApplyObjects() + if err != nil { + return nil, fmt.Errorf("chart is gone, but unable to remove resources tied to HelmChart %s/%s, %w", chart.Namespace, chart.Name, err) + } + return chart, nil + } return chart, fmt.Errorf("unable to update status of helm chart to add uninstall job name %s, %w", chartCopy.Status.JobName, err) } return newChart, fmt.Errorf("waiting for delete of helm chart for %s by %s", key, job.Name)