<p>I am currently attempting to use the lookup function via Helm 3.1 to load a variable during installation.</p>
<pre><code>{{ $ingress := (lookup &quot;v1&quot; &quot;Ingress&quot; &quot;mynamespace&quot; &quot;ingressname&quot;).status.loadBalancer.ingress[0].hostname }}
</code></pre>
<p>Of course, this returns, &quot;bad character [.&quot; If I remove it, it returns &quot;nil pointer evaluating interface {}.loadBalancer&quot;.</p>
<p>Is what I am attempting to do even possible?</p>
<p>Thanks</p>

<p>You are attempting to use &quot;normal&quot; array indexing syntax, but helm charts use &quot;golang templates&quot; and thus array indexing is done via <a href="https://helm.sh/docs/chart_template_guide/function_list/#index" rel="nofollow noreferrer">the <code>index</code> function</a></p>
<pre class="lang-yaml prettyprint-override"><code>{{ $ingress := (index (lookup &quot;v1&quot; &quot;Ingress&quot; &quot;mynamespace&quot; &quot;ingressname&quot;).status.loadBalancer.ingress 0).hostname }}
</code></pre>
<hr />
<p>after further thought, I can easily imagine that <code>nil</code> pointer error happening during <code>helm template</code> runs, since <a href="https://github.com/helm/helm/issues/9309#issuecomment-771579215" rel="nofollow noreferrer"><code>lookup</code> returns <code>map[]</code> when running offline</a></p>
<p>In that case, you'd want to use the <code>index</code> function for <strong>every</strong> path navigation:</p>
<pre class="lang-yaml prettyprint-override"><code>{{ $ingress := (index (index (index (index (index (lookup &quot;v1&quot; &quot;Ingress&quot; &quot;mynamespace&quot; &quot;ingressname&quot;) &quot;status&quot;) &quot;loadBalancer&quot;)  &quot;ingress&quot;) 0) &quot;hostname&quot;) }}
</code></pre>
<p>or, assert the lookup is in &quot;offline&quot; mode and work around it:</p>
<pre class="lang-yaml prettyprint-override"><code>      {{ $ingress := &quot;fake.example.com&quot; }}
      {{ $maybeLookup := (lookup &quot;v1&quot; &quot;Ingress&quot; &quot;mynamespace&quot; &quot;ingressname&quot;) }}
      {{ if $maybeLookup }}
      {{   $ingress = (index $maybeLookup.status.loadBalancer.ingress 0).hostname }}
      {{ end }}
</code></pre>
