<p>I'm trying to get the restartCount of the pod for matching deployment but '/' causing an issue</p>
<p><strong>Query:</strong> <code> kubectl -n &lt;namespace&gt; get pod -o go-template='{{range .items}}{{if eq .metadata.labels.app.kubernetes.io/name &quot;my-app&quot;}}{{ (index .status.containerStatuses 0).restartCount}}{{end}}{{end}}'</code></p>
<p><strong>Error</strong>: <code>template: output:1: bad character U+002F '/'</code></p>
<p>I tried with the 'index' but did not help. Also tried adding quotes, escaping the special character '/' but no luck.</p>
<p>Any help is really appreciable. Thank you.</p>

mansing shinde
<p>In the test</p>
<pre class="lang-none prettyprint-override"><code>if eq .metadata.labels.app.kubernetes.io/name &quot;my-app&quot;
</code></pre>
<p>the <code>/</code> character isn't allowed in the <a href="https://pkg.go.dev/text/template" rel="nofollow noreferrer">Go text/template</a> syntax.  You are probably looking for an object like</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  labels:
    app.kubernetes.io/name: my-app
</code></pre>
<p>and <code>.</code> also has special syntax here: it will look up <code>metadata</code>, <code>labels</code>, and then a single level <code>app</code> within that and so on.</p>
<p>The standard <code>index</code> function will let you use an arbitrary string as a map index (in other contexts, including a computed value, or an integer for an array index) and that's probably what you need here</p>
<pre class="lang-none prettyprint-override"><code>if eq (index .metadata.labels &quot;app.kubernetes.io/name&quot;) &quot;my-app&quot;
</code></pre>
