werf / nelm

Nelm is a Helm 3 alternative and werf deployment engine
Apache License 2.0
269 stars 2 forks source link

werf dismiss and werf helm uninstall do not remove the release version resources if there is a Job with "helm.sh/hook: pre-delete" #116

Open akaitux opened 4 months ago

akaitux commented 4 months ago

Before proceeding

Version

v1.2.321

How to reproduce

In any chart, add Job with annotation "helm.sh/hook: pre-delete", run werf dismiss or werf helm uninstall

Result

Common problem: the release version resources is not removed with either dismiss or helm uninstall, secret with the release (i.e. the release itself) is deleted, but its resources are not. If helm release has only one version, resources is not uninstalled at all. If there are two or more versions, the resources of previous versions are deleted, but the last one remains (a release can be deleted in its entirety, in which case resources from the last version are not counted, but I haven't checked what happens if there are new resources in the new version of release).

Expected result

The release has been deleted completely with all resources

Additional information

The problem is that when pre-delete hooks are executed, the release is set Phase = hooks-pre, which causes the phase to be considered not started in the Calculate() function (link to switch case) of the resources to delete and its resources are not included in the general deletion list. If there are no pre-delete hooks, then the release phase status before Calculate() is hooks-post and everything works fine.

The solution to this problem may be the following code after pre-delete hooks are executed:

    if *rel.Info.LastPhase == release.PhaseHooksPre {
        *rel.Info.LastPhase = release.PhaseHooksPost
    }

This same bug is repeated in werf v2, but I haven't checked it in the code and it requires additional confirmation.

Peter-kre commented 4 months ago

I confirmed this problem also exists in v.2.7.1