<p>Say I have a configmap like this, and I want to get the value(12301) of version 123v1 in map_a, what is the correct way?</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfig
  namespace: default
data:
  test.yml: |
    map_a:
      &quot;123v1&quot;:
        &quot;Version&quot;: 12301
        &quot;Type&quot;: &quot;abc&quot;
......
</code></pre>
<p>Here is my attempts:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
{{- $configmap := (lookup &quot;v1&quot; &quot;ConfigMap&quot; &quot;default&quot; &quot;myconfig&quot;) }}
{{- if $configmap }}
  {{- $models := get $configmap.data &quot;test.yml&quot; }}
  version: {{ $models.map_a.123v1.Version }}
{{- end }}

$ helm template .
install.go:173: [debug] Original chart version: &quot;&quot;
install.go:190: [debug] CHART PATH: /root/test-lookup


Error: parse error at (test-lookup/templates/config.yaml:9): &quot;.123v&quot;
helm.go:88: [debug] parse error at (test-lookup/templates/config.yaml:9): &quot;.123v&quot;
</code></pre>

qxing
<p>The pipe symbol at the end of a line in YAML signifies that any indented text that follows should be interpreted as a multi-line scalar value. See the <a href="https://yaml.org/spec/1.2/spec.html#id2795688" rel="nofollow noreferrer">YAML spec</a>. This is also mentioned in the <a href="https://docs.helm.sh/zh/docs/chart_template_guide/control_structures/" rel="nofollow noreferrer">helm doc |-</a></p>
<p><code>{{ $models }}</code> is a value behind a pipe symbol of <code>myconfig&gt;data&gt;test.yml</code>.</p>
<p>So, the value of the expression <code>{{ $models }}</code> is a string instead of a map. In other words, <code>{{ $models. map_a }}</code> is an illegal operation.</p>
<p>The real value of <code>{{ $models }}</code> is a multi-line string, the string content is:</p>
<pre><code>map_a:
  &quot;123v1&quot;:
    &quot;Version&quot;: 12301
    &quot;Type&quot;: &quot;abc&quot;
</code></pre>
<hr />
<p>This can work here, of course the result is not what you want:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  {{- $configmap := (lookup &quot;v1&quot; &quot;ConfigMap&quot; &quot;default&quot; &quot;myconfig&quot;) }}
  {{- if $configmap }}
  {{- $models := get $configmap.data &quot;test.yml&quot; }}
  version: {{ $models | quote }}
  {{- end }}
</code></pre>
<p>output：</p>
<pre><code>apiVersion: v1
data:
  version: |
    map_a:
      &quot;123v1&quot;:
        &quot;Version&quot;: 12301
        &quot;Type&quot;: &quot;abc&quot;
kind: ConfigMap
metadata:
  annotations:
...
</code></pre>
<hr />
<p>So in order to achieve your purpose, you have to operate <code>{{ $models }}</code> in accordance with the method of operating strings.</p>
<p>config.yaml</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test-config
data:
  {{- $configmap := (lookup &quot;v1&quot; &quot;ConfigMap&quot; &quot;default&quot; &quot;myconfig&quot;) }}
  {{- if $configmap }}
  {{- $models := get $configmap.data &quot;test.yml&quot; }}
  {{- range ( split &quot;\n&quot; $models) }}
  {{- if ( contains &quot;Version&quot; .) }}
  version: {{ (split &quot;:&quot; .)._1 | trim | quote }}
  {{- end }}
  {{- end }}
  {{- end }}
</code></pre>
<p>output:</p>
<pre><code>apiVersion: v1
data:
  version: &quot;12301&quot;
kind: ConfigMap
metadata:
  annotations:
...
</code></pre>
