https://pulumi.com logo
Title
s

stale-nail-78326

07/07/2021, 7:00 PM
Hello folks, I have a quick question about how to install Grafana using its Helm chart. What I'm trying to do is to install Grafana with a datasource, but it fails to read the configuration when using Pulumi's
k8s.helm.v3.Chart
values
parameter. I suspect it happens because one of the keys is
datasources.yaml
which contains a
.
and may be expanded to something the helm chart does not understand. This YAML works when installing the chart not using Pulumi:
datasources:
  datasources.yaml:
    apiVersion: 1
    datasources:
      - name: "Cinnamon Prometheus"
        type: prometheus
        access: proxy
        url: <http://prometheus-server.default.svc.cluster.local>
        editable: true
But it fails when using Pulumi (typescript api):
new k8s.helm.v3.Chart(
  "grafana",
  {
    chart: "grafana",
    fetchOpts: {
      repo: "<https://grafana.github.io/helm-charts>",
    },
    values: {
      datasources: {
        "datasources.yaml": {
          apiVersion: 1,
          datasources: {
            name: "Cinnamon Prometheus",
            type: "prometheus",
            access: "proxy",
            url: "<http://prometheus-server.default.svc.cluster.local>",
            editable: true,
          },
        },
      },
    },
  },
  { provider: clusterProvider },
);
Is there a way to use the YAML directly? Or another way to list the
values
to replicate the YAML file?
I see the project uses
@pulumi/kubernetes
3.4.1
.
b

bored-table-20691

07/07/2021, 7:21 PM
@stale-nail-78326 what would this look like if you just used Helm normally and put it in the values file? I imagine that the YAML (or JSON in your case) would be a string (i.e. someting like
datasources.yaml: | ā€¦
FWIW, I have a similar thign for a different Helm chart and it works fine - you just put it there as a string (so you can do JSON.stringify(ā€¦) on your object)
s

stale-nail-78326

07/07/2021, 7:23 PM
Hey @bored-table-20691 thanks for answering. So the YAML that I use when installing using
helm install ... -f values.yml
is:
datasources:
  datasources.yaml:
    apiVersion: 1
    datasources:
      - name: "Cinnamon Prometheus"
        type: prometheus
        access: proxy
        url: <http://prometheus-server.default.svc.cluster.local>
        editable: true
I didn't get your suggestion about using
JSON.stringfy
though.
b

bored-table-20691

07/07/2021, 7:24 PM
Interesting. Iā€™m not quite sure how the Grafana helm chart is treating it, but if you try what I said (which is stringifying it in your code), I believe it shoudl work. My particular example is in Go, but it looks something like this:
"extraConfigs": map[string]interface{}{
			"datasources-init.yaml": pulumi.Sprintf(`
databases:
Where
extraConfigs
is part of my values object
Instead of:
"datasources.yaml": {
          apiVersion: 1,
          datasources: {
            name: "Cinnamon Prometheus",
            type: "prometheus",
            access: "proxy",
            url: "<http://prometheus-server.default.svc.cluster.local>",
            editable: true,
          },
        },
Try:
"datasources.yaml": JSON.stringify({
          apiVersion: 1,
          datasources: {
            name: "Cinnamon Prometheus",
            type: "prometheus",
            access: "proxy",
            url: "<http://prometheus-server.default.svc.cluster.local>",
            editable: true,
          },
        }),
s

stale-nail-78326

07/07/2021, 7:25 PM
Oh, I see what you mean. Let me give it a try now. šŸ™‚
Hey @bored-table-20691, that was actually an error in my yaml -> json translation that was causing the issue. šŸ¤¦ā€ā™‚ļø
b

bored-table-20691

07/07/2021, 11:55 PM
šŸ™‚ Glad you figured it out!
šŸ™Œ 1
s

stale-nail-78326

07/07/2021, 11:57 PM
This:
datasources:
  datasources.yaml:
    apiVersion: 1
    datasources:
      - name: "Cinnamon Prometheus"
        type: prometheus
        access: proxy
        url: <http://prometheus-server.default.svc.cluster.local>
        editable: true
Translate to:
{
    datasources: {
        "datasources.yaml": {
            datasources: [
                {
                    name: "Cinnamon Prometheus",
                    type: "prometheus",
                    access: "proxy",
                    url: "<http://prometheus-server.default.svc.cluster.local>",
                    editable: true
                }
            ]
        }
    }
}
The array in the inner
datasources
was missing.
Just in case someone goes through the same error.