<p>I have a helm chart that deploys a number of Kubernetes resources. One of them is a resource that is of a Custom Resource Definition (CRD) type (<code>ServiceMonitor</code> used by <code>prometheus-operator</code>). </p>

<p>I am looking for a way, how to "tell" helm that I'd want to create this resource only if such a CRD is defined in the cluster OR to ignore errors <em>only</em> caused by the fact that such a CRD is missing.</p>

<p>Is that possible and how can I achieve that?</p>

LIvanov
<p>Helm's <a href="https://v2.helm.sh/docs/chart_template_guide/#built-in-objects" rel="noreferrer">Capabilities</a> object can tell you if an entire API class is installed in the cluster.  I don't think it can test for a specific custom resource type.</p>

<p>In your <code>.tpl</code> files, you can wrap the entire file in a <code>{{ if }}...{{ end }}</code> block.  Helm doesn't especially care if the rendered version of a file is empty.</p>

<p>That would lead you to a file like:</p>

<pre><code>{{ if .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  ...
{{ end -}}
</code></pre>

<p>That would get installed if the operator is installed in the cluster, and skipped if not.</p>
