<p>I am looking for any code example that deploys Helm chart without via CLI call. The reason behind this is:</p>

<ol>
<li>My company got couple existing pipelines written with AWS CodePipeline / CodeBuild / CodeDeploy. They don't like to investigate more time on re-writing all pipelines.</li>
<li>My company does not have any plan to maintain extra instance(s) just for deployment.</li>
<li>AWS CodePipeline could trigger Lambda, and theoretically I could write some Python code to do the job if Helm provides Python client.</li>
</ol>

<p>Currently I steal Lambda function from this:</p>

<p><a href="https://github.com/aws-samples/aws-kube-codesuite" rel="nofollow noreferrer">https://github.com/aws-samples/aws-kube-codesuite</a></p>

<p>Whereas this does not provide same level features as Helm does. We have to provide our release-name system, template system, etc. In other words, it functions poorly if I have big change on the manifest, and does not handle the first time deployment (means deploying manifest to an empty K8S cluster) Also we use Github, although not really relevant.</p>

<p>For python client of Helm chart, the best I could find is pyhelm listed on pip. But it does not have sample code for calling deployment, and from some user group / forum feedback the installation process is painful. Somebody also points to azure/draft and another repo but I have no clue on how to come out a solid example that only use Python to deploy Helm chart.</p>

<p>Please let me know where I miss. Thanks.</p>

<p>You can find my fork of pyhelm with examples and Python3 support.</p>

<pre><code>git clone git@github.com:andriisoldatenko/pyhelm.git
cd pyhelm &amp;&amp; python setup.py install
</code></pre>

<h2>How to use Pyhelm</h2>

<h3>First you need repo_url and chart name to download chart</h3>

<pre><code>from pyhelm.repo import from_repo

chart_path = chart_versions = from_repo('https://kubernetes-charts.storage.googleapis.com/', 'mariadb')

print(chart_path)
"/tmp/pyhelm-kibwtj8d/mongodb"
</code></pre>

<h3>Now you can see that chart folder of mongodb::</h3>

<pre><code>In [3]: ls -la /tmp/pyhelm-kibwtj8d/mongodb
total 40
drwxr-xr-x  7 andrii  wheel   224 Mar 21 17:26 ./
drwx------  3 andrii  wheel    96 Mar 21 17:26 ../
-rwxr-xr-x  1 andrii  wheel     5 Jan  1  1970 .helmignore*
-rwxr-xr-x  1 andrii  wheel   261 Jan  1  1970 Chart.yaml*
-rwxr-xr-x  1 andrii  wheel  4394 Jan  1  1970 README.md*
drwxr-xr-x  8 andrii  wheel   256 Mar 21 17:26 templates/
</code></pre>

<h3>Next step to build ChartBuilder instance to manipulate with Tiller::</h3>

<pre><code>from pyhelm.chartbuilder import ChartBuilder

chart = ChartBuilder({'name': 'mongodb', 'source': {'type': 'directory', 'location': '/tmp/pyhelm-kibwtj8d/mongodb'}})

# than we can get chart meta data etc
In [9]: chart.get_metadata()
Out[9]:
name: "mongodb"
version: "0.4.0"
description: "Chart for MongoDB"
</code></pre>

<h3>Install chart::</h3>

<pre><code>from pyhelm.chartbuilder import ChartBuilder
from pyhelm.tiller import Tiller

chart = ChartBuilder({'name': 'mongodb', 'source': {'type': 'directory', 'location': '/tmp/pyhelm-kibwtj8d/mongodb'}})
chart.install_release(chart.get_helm_chart(), dry_run=False, namespace='default')

Out[9]:
release {
  name: "fallacious-bronco"
  info {
    status {
      code: 6
    }
    first_deployed {
      seconds: 1521647335
      nanos: 746785000
    }
    last_deployed {
      seconds: 1521647335
      nanos: 746785000
    }
    Description: "Dry run complete"
  }
  chart {....
}
</code></pre>
