<p><strong>Values.yaml</strong></p>

<pre><code>cpulimit: 200m
memlimit: 512M
</code></pre>

<p><strong>configmap.yaml</strong></p>

<pre><code>mem_pool_size = {{ ((.Values.memlimit)) mul 0.8 }} --&gt; not working
mem_pool_size = {{  .Values.memlimit mul 0.8 }} --&gt; not working
mem_pool_size = {{ .Values.memlimit * 0.8 }} --&gt; not working
mem_pool_size = {{ .Values.memlimit }} * 0.8 --&gt; not working
mem_pool_size = {{ .Values.memlimit }} mul 0.8 --&gt; not working
</code></pre>

<p>Tried many ways but i dint got the exact solution.if user provides value of memlimit as 512M i should assign only 80 % ram so the value will be 410M. I am finding a way whether arithmetic operations are supported in helm templates. Is there any example for this.</p>

<p>In helm templates this is done via <a href="https://docs.helm.sh/chart_template_guide/#template-functions-and-pipelines" rel="nofollow noreferrer">pipelines</a>. Some of them are defined via Go template language and some others are part of <a href="http://masterminds.github.io/sprig/" rel="nofollow noreferrer">Sprig template library</a>.</p>

<p>I did not find a complete list which are valid and working in Helm, but I did not find a Sprig one not working as explained in the Sprig documentation.</p>

<p>So first the syntax for pipelines has to be:</p>

<pre><code>{{  .Values.memlimit | mul 2 }}
</code></pre>

<p>However the Math Functions only work on int64. But 512M is not an int. So you can let the user specify the limits as bytes or chain more pipes to first remove the "M" and then do the calculation:</p>

<pre><code>{{ .Values.memlimit | replace "M" "" |mul 2  }}M
</code></pre>

<p>Since Memory can be specified with different units you maybe need some regexp:</p>

<pre><code>{{ .Values.memlimit |regexFind "[1-9]+" |mul 2 }}{{ .Values.memlimit | regexFind "[a-zA-Z]+"  }}
</code></pre>

<p>But like stated all Sprig Math Functions only work on int64 so mul 0.8 will multiply by zero, mul 1,6 with only multiply with 1 and so on.</p>

<p>So probably you have to wait for the Sprig functions to also work with floats to achieve a percentage based calculation or you find some clever trick with the provided Math functions by Sprig and the int64 type.</p>

<p>Maybe something like explained in this answer:</p>

<p><a href="https://stackoverflow.com/questions/20788793/c-how-to-calculate-a-percentageperthousands-without-floating-point-precision">C How to calculate a percentage(perthousands) without floating point precision</a></p>
