Skip to content

Commit

Permalink
Clean helm-delete job when chart is gone
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Wang <w13915984028@gmail.com>
  • Loading branch information
w13915984028 committed Apr 19, 2024
1 parent 0d328f4 commit 487df70
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/controllers/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 487df70

Please sign in to comment.