<p>In a helm chart is it possible to set a value at deployment time that is based on an annotation from the namespace it is being deployed to?</p>

Raymond Self
<p>Current versions of Helm 3 have a <a href="https://helm.sh/docs/chart_template_guide/functions_and_pipelines/#using-the-lookup-function" rel="nofollow noreferrer"><code>lookup</code> template function</a> that can retrieve object data from the cluster.  You could use this in this context as something like:</p>
<pre><code>{{- $ns := lookup &quot;v1&quot; &quot;Namespace&quot; &quot;&quot; .Release.Namespace }}
{{- $istio := index $ns.metadata.annotations &quot;istio-injection&quot; }}
{{- if eq $istio &quot;enabled&quot; }}
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
...
{{ end }}
</code></pre>
<p>The documentation has the important caveat that <code>lookup</code> doesn't work in <code>helm template</code> or <code>helm install --dry-run</code> since these modes don't contact the cluster at all; <code>lookup</code> will return <code>nil</code>.</p>
<p>Also note that this will only take effect when you re-run a <code>helm</code> command.  A custom Kubernetes operator might be a little more effort to build, but it will get re-triggered whenever an object you're watching changes, which will behave a little more consistently with other Kubernetes objects.  (That is to say, you could write an operator to automatically create or delete or modify resources whenever the annotation value changes.)</p>
