https://pulumi.com logo
#general
Title
# general
a

acoustic-leather-88378

03/18/2020, 3:53 PM
Hi all, I'm trying to install a Helm chart with Pulumi that is the equivalent of:
Copy code
$ helm install postgres-operator <https://opensource.zalando.com/postgres-operator/charts/postgres-operator/postgres-operator-1.4.0.tgz> -f <https://opensource.zalando.com/postgres-operator/charts/postgres-operator/values-crd.yaml>
however, looking at https://www.pulumi.com/docs/guides/adopting/from_kubernetes/#provisioning-a-helm-chart and the available options I'm not sure how to achieve that? (Using the direct
.tgz
reference) The chart is not in a repo, see https://github.com/zalando/postgres-operator/issues/552#issuecomment-521193807
b

billowy-army-68599

03/18/2020, 4:45 PM
You can use
LocalChartsOpts
to point to a
Chart.yaml
https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/kubernetes/helm/v2/#LocalChartOpts You'll need to unpack the
tgz
file first though
I actually just used this for some python, here's how it looks
Copy code
Chart("local-volume-provisioner", LocalChartOpts(
    path="charts/provisioner",
    namespace="kube-system",
    values={
        "classes": [
            {
                "name": 'local',
                "hostDir": "/mnt/",
                "volumeMode": "Filesystem",
                "fsType": "ext4",
            }
        ]
    }
))
a

acoustic-leather-88378

03/18/2020, 6:16 PM
Thanks, will give a try 👍
I ended up with this which works:
Copy code
import * as k8s from "@pulumi/kubernetes";
import * as kx from "@pulumi/kubernetesx";
import * as fs from "fs";
import * as path from "path";
import * as nodepath from "path";

const chartDir = path.resolve( "/tmp" );
// Fetch the Zalando Postgres Operator chart if it hasn't been fetched
if (!fs.existsSync(nodepath.join(chartDir, "postgres-operator"))) {
    k8s.helm.v3.fetch("<https://opensource.zalando.com/postgres-operator/charts/postgres-operator/postgres-operator-1.4.0.tgz>",
        {
            destination: chartDir,
            untar: true,
        });
}

// Install the CRD's manually
new k8s.yaml.ConfigGroup("postgres-operator-crds", {
    files: [ path.join(nodepath.join(chartDir, "postgres-operator/crds", "*.yaml")) ],
});

// Apply the templated Helm chart
const postgresOperator = new k8s.helm.v3.Chart("postgres-operator", {
    path: nodepath.join(chartDir, "postgres-operator"),
    values: crdValues(),
});

function crdValues(): any {
    let fileContents = fs.readFileSync(nodepath.join(chartDir,
        "postgres-operator/values-crd.yaml"));
    return require("js-yaml").safeLoad(fileContents);
}
Some annoying things: • I had to check if the
.tgz
had already been downloaded and untarred as it tried to do it again after preview or next run and would fail because it already existed • Using
k8s.yaml.ConfigGroup
it seems that the state is tied to the directory location of the
files
. If the location of the
files
changes it's seen as a state update. Is this by design or am I missing something? Doesn't that force a consistent location for the manifests? • As above, I had to install the CRD's separately as
helm template
obviously doesn't install CRD's. Is there support for a more elegant way of achieving this? Perhaps as part of
k8s.helm.v3.Chart
? • I had to use a pre-existing values file (see original Helm install
... -f <https://opensource.zalando.com/postgres-operator/charts/postgres-operator/values-crd.yaml>
) so I had to read it and parse it as yaml (thanks to hint from https://github.com/pulumi/pulumi-kubernetes/issues/659#issuecomment-515701898) but built in support as described in that issue would have been welcome
5 Views