<p>I want to implement some k8s services only if there is a service with suffix &quot;mysuffix&quot; in the namespace. I tried the following but doesn't work</p>
<pre><code>{{- $previousReleaseInstalled := false -}}
{{- range $index, $service := (lookup &quot;v1&quot; &quot;Service&quot; .Release.Namespace &quot;&quot;).items }}
{{- if hasSuffix &quot;mysuffix&quot; &quot;$service.name&quot; }}
{{- $previousReleaseInstalled := true -}}
{{- end }}
{{- end }}


{{- if $previousReleaseInstalled -}}
implement some services
{{- end }}
</code></pre>

sotiris
<p>Your <code>lookup</code> function is almost correct. The issue with the assignment of the <code>$previousReleaseInstalled</code> variable. You need to use <code>=</code> instead of <code>:=</code> inside the <code>range</code>. Check this answer for the details <a href="https://stackoverflow.com/questions/64272789/why-doesnt-this-change-the-value-of-the-variable-in-the-range-loop-in-helm">Why doesn&#39;t this change the value of the variable in the range loop in Helm?</a></p>
<p>Another issue is the wrong key name. You should use <code>$service.metadata.name</code> instead of <code>$service.name</code>, and remove the quotes around the <code>$service.metadata.name</code></p>
<pre><code>{{- $previousReleaseInstalled := false -}}
{{- range $index, $service := (lookup &quot;v1&quot; &quot;Service&quot; .Release.Namespace 
&quot;&quot;).items }}
{{- if hasSuffix &quot;mysuffix&quot; $service.metadata.name }}
{{- $previousReleaseInstalled = true -}}
{{- end }}
{{- end }}


{{- if $previousReleaseInstalled -}}
implement some services
{{- end }}
</code></pre>
<p>Another important thing to note, the <code>lookup</code> function always returns empty response when used with the <code>helm template</code> command. <a href="https://helm.sh/docs/chart_template_guide/function_list/#lookup" rel="nofollow noreferrer">https://helm.sh/docs/chart_template_guide/function_list/#lookup</a></p>
