<p>I am using two configmaps - one for install and one for uninstall / delete and to trigger actions before delete , I defined helm hooks in the uninstall daemonset <strong>annotations</strong>. Below is the code for the uninstall daemonset written in yaml</p>
<pre><code>    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: delete-pack
      namespace: mynamespace
      labels:
        app: &lt;ex&gt;
        chart: &lt;ex&gt;
      annotations:
        &quot;helm.sh/hook&quot;: pre-delete
        &quot;helm.sh/hook-weight&quot;: &quot;-10&quot;
        &quot;helm.sh/hook-delete-policy&quot;: hook-succeeded,before-hook-creation,hook-failed
    spec:
      selector:
        matchLabels:
            app: &lt;ex&gt;
</code></pre>
<p>The rest of the yaml file is of regular template of defining mount volume etc. When running the install command, the configmaps are registered in the namespace and while checking the namespace with <strong>kubectl describe configmaps -n mynamespace</strong>, for the <strong>delete-pack</strong> configmap, this is the following output:</p>
<pre><code>    Name:         delete-pack
    Labels:       app=sample
                  chart=sample
    Annotations:  meta.helm.sh/release-name: sample
</code></pre>
<p>The hook definitions are not loaded, due to which, while running delete, the configmaps are removed and the hook terminates with an error stating</p>
<pre><code>    configmap &quot;delete-pack&quot; not found
</code></pre>
<p>and the configmaps are cleared from the namespace. The hook becomes an <strong>orphanedPod</strong> and is deleted without the pre-delete actions defined being executed.</p>
<p>I find the reason to be the annotations not loaded along with the configmap name in the namespace. What could be the reason for the helm hooks to not be registered? Is there a fundamental error in Kubernetes installation?</p>
<p>Could you also please point me towards any further steps for debug?</p>
<p><strong>UPDATE</strong></p>
<p>The Configmap of <strong>delete-pack</strong> did not have the annotations. But when added, <strong>delete-pack</strong> does not get registered at all in the configmaps of the name space. (i.e)</p>
<pre><code>    Name:         pack
    Labels:       app=sample
                  chart=sample
    Annotations:  meta.helm.sh/release-name: sample

    &lt;delete-pack data absent&gt;
</code></pre>

Lakshmi Narayanan
<p>The primary design point for Helm hooks is to run Jobs.  You can sort of use them to load things your Job needs like ServiceAccounts and ConfigMaps.  It won't really work well to use them to load a DaemonSet, especially in a pre-delete hook.</p>
<p>The <a href="https://docs.helm.sh/docs/topics/charts_hooks/" rel="nofollow noreferrer">Helm hook documentation</a> notes:</p>
<blockquote>
<p>If the resource is a <code>Job</code> or <code>Pod</code> kind, Helm will wait until it successfully runs to completion.  [...] For all other kinds, as soon as Kubernetes marks the resource as loaded (added or updated), the resource is considered &quot;Ready&quot;.</p>
</blockquote>
<p>In your setup, you have a pre-delete DaemonSet.  That's not a Job or a bare Pod, so Helm sends the DaemonSet definition to Kubernetes; once it's done that, possibly before any individual Pods are created, Helm then sends the delete request for everything else in the chart.</p>
<p>This is where the hook annotation on the ConfigMap matters.  If the ConfigMap is also annotated as a pre-delete hook, then it won't be installed as part of the main <code>helm install</code> content, but it will be loaded when the DaemonSet is.  If it isn't, then it will be uninstalled immediately after the DaemonSet is sent to the cluster.</p>
<p>The other challenge you may be running into is the <code>helm.sh/hook-delete-policy: hook-succeeded</code> annotation.  It's not clearly documented what &quot;succeeded&quot; means for long-running workload resources.  If &quot;succeeded&quot; just means &quot;submitted to the cluster without error&quot; this could cause the DaemonSet to be sent and then immediately deleted.</p>
<p>The only concrete suggestion I have here is to make a second copy of the ConfigMap that the hook can use.  I could imagine writing a dedicated DaemonSet that did mostly sat idle but the cleanup work when it received SIGTERM, which could then run as a normal DaemonSet without being a Helm hook.  The use case seems unusual to me, especially the comment about needing to manipulate software on the host, since everything in Kubernetes usually runs in a container and can't see or affect the host filesystem at all.</p>
