<p>Kubectl provides a nice way to convert environment variable files into secrets using:</p>
<pre><code>$ kubectl create secret generic my-env-list --from-env-file=envfile
</code></pre>
<p>Is there any way to achieve this in Helm? I tried the below snippet but the result was quite different:</p>
<pre><code>kind: Secret
metadata:
  name: my-env-list
data:
  {{ .Files.Get &quot;envfile&quot; | b64enc }}

</code></pre>

Sayon Roy Choudhury
<p>It appears kubectl just does the simple thing and only <a href="https://github.com/kubernetes/kubernetes/blob/v1.22.0/staging/src/k8s.io/kubectl/pkg/cmd/util/env_file.go#L56" rel="nofollow noreferrer">splits on a single <code>=</code> character</a> so the Helm way would be to replicate that behavior (helm has <code>regexSplit</code> which will suffice for our purposes):</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Secret
data:
  {{ range .Files.Lines &quot;envfile&quot; }}
  {{   if . }}
  {{     $parts := regexSplit &quot;=&quot; . 2 }}
  {{     index $parts 0  }}: {{ index $parts 1 | b64enc }}
  {{   end }}
  {{ end }}
</code></pre>
<p>that <code>{{ if . }}</code> is because <code>.Files.Lines</code> returned an empty string which of course doesn't comply with the pattern</p>
<p>Be aware that kubectl's version accepts <a href="https://github.com/kubernetes/kubernetes/blob/v1.22.0/staging/src/k8s.io/kubectl/pkg/cmd/util/env_file.go#L65-L66" rel="nofollow noreferrer">barewords looked up from the environment</a> which helm has no support for doing, so if your <code>envfile</code> is formatted like that, this specific implementation will fail</p>
