<p>To simplify, I want to list all the docker images defined in a helm chart.</p>
<p>For eg, let's say I have the following set of templates:</p>
<pre><code>$ helm template jenkins/jenkins
</code></pre>
<p><a href="https://charts.jenkins.io/" rel="nofollow noreferrer">https://charts.jenkins.io/</a></p>
<p>Then, I want to somehow use <code>kubectl</code> to parse this result so I can apply a filter such as:</p>
<pre><code>kubectl get pods -l k8s-app=kube-dns -o jsonpath={.items[*].spec.containers[*].name}
</code></pre>
<p>To return me the list. However, that command is to get pods. Any clue?</p>
<p>EDIT: I found a way:</p>
<pre><code>❯ helm template jenkins/jenkins | kubectl apply -f - --dry-run=client -o jsonpath=&quot;{..image}&quot; | tr -s '[[:space:]]' '\n' | sort | uniq
bats/bats:1.2.1
jenkins/jenkins:2.263.1
kiwigrid/k8s-sidecar:0.1.275
</code></pre>
<p>With one drawback: <code>kubectl</code> needs to be connected to a cluster. I would like to prevent that.</p>

felipecrs
<p>You can use a different jsonpath to get all images:</p>
<p><code>kubectl get pods -A -o jsonpath=&quot;{..image}&quot;</code></p>
<p>If you just want unique images: <code>kubectl get pods -A -o jsonpath=&quot;{..image}&quot; | tr -s '[[:space:]]' '\n' | sort -u</code>.</p>
<p>Substituting <code>-A</code> for the namespace of your chart or manifests.</p>
<p>If you have the manifests on your machine and not deployed, of course, you can just grep: <code>grep 'image: ' *.yml</code></p>
<p>You can also use Go template syntax:</p>
<p><code>kubectl get pods -A -o go-template --template=&quot;{{range .items}}{{range .spec.containers}}{{.image}} {{end}}{{end}}&quot;</code></p>
<p>If you have more than one chart in a given namespace, I think grepping would be the best way: <code>helm template some-chart | grep 'image:'</code></p>
<p>EDIT:</p>
<p>Since this will be running in CI, it would be better to use a little bit of code to avoid potential false positives. This Python script does the trick:</p>
<pre class="lang-py prettyprint-override"><code>#!/usr/bin/env python3
import sys
import yaml  # pip install PyYAML
from nested_lookup import nested_lookup  # pip install nested-lookup

template = &quot;&quot;

for line in sys.stdin:
    template += line

parts = template.split('---')
for p in parts:
    y = yaml.safe_load(p)
    matches = nested_lookup(&quot;image&quot;, y)
    if (len(matches)):
        print(&quot;\n&quot;.join(matches))
</code></pre>
<p>Usage: <code>helm template jenkins/jenkins | ./this-script.py</code>. It prints out each occurrence of images, so if you only want unique images you'd need to throw all the <code>matches</code> in a list, then unique that before printing (or pipe it to <code>sort -u</code>).</p>
