Hello folks, I have a quick question about how to ...
# kubernetes
s
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:
Copy code
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):
Copy code
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
@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
Hey @bored-table-20691 thanks for answering. So the YAML that I use when installing using
helm install ... -f values.yml
is:
Copy code
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
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:
Copy code
"extraConfigs": map[string]interface{}{
			"datasources-init.yaml": pulumi.Sprintf(`
databases:
Where
extraConfigs
is part of my values object
Instead of:
Copy code
"datasources.yaml": {
          apiVersion: 1,
          datasources: {
            name: "Cinnamon Prometheus",
            type: "prometheus",
            access: "proxy",
            url: "<http://prometheus-server.default.svc.cluster.local>",
            editable: true,
          },
        },
Try:
Copy code
"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
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
šŸ™‚ Glad you figured it out!
šŸ™Œ 1
s
This:
Copy code
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:
Copy code
{
    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.