<p>I have one pre-install hook which creates a dynamic PVC and looks like this</p>
<pre><code>kind: PersistentVolumeClaim
metadata:
  name: my-dynamic-pv
  annotations:
    &quot;helm.sh/resource-policy&quot;: keep
    &quot;helm.sh/hook&quot;: &quot;pre-install&quot;
spec:
  storageClassName: {{ .Values.persistence.storageClass }}
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
</code></pre>
<p>I want to preserve the same PVC across restarts that's why I have provided <code>&quot;helm.sh/resource-policy&quot;: keep</code>. I am able to create the PVC with the pre-install hook the very first time I start my service. But the subsequent installs/restarts are failing with error <code>Error: persistentvolumeclaims &quot;my-dynamic-pv&quot; already exists</code>.</p>
<p>Is there a way to ignore this failure and continue with the helm installation?</p>

subrat
<p>You can use <code>helm lookup</code> function to check the existence of the pvc before creating it.</p>
<pre><code>{{- $mypvc := (lookup &quot;v1&quot; &quot;PersistentVolumeClaim&quot; .Release.Namespace (printf &quot;my- 
dynamic-pv&quot;)) }}
{{- if not $mypvc }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: my-dynamic-pv
  annotations:
    &quot;helm.sh/resource-policy&quot;: keep
    &quot;helm.sh/hook&quot;: &quot;pre-install&quot;
spec:
  storageClassName: {{ .Values.persistence.storageClass }}
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
{{- end -}}
</code></pre>
<p>More on helm lookup funtion - <a href="https://helm.sh/docs/chart_template_guide/functions_and_pipelines/" rel="noreferrer">Helm template functions</a></p>
<p>I'm using helm 3.2.1. You will probably need a near version to use the lookup function.</p>
