helm-charts icon indicating copy to clipboard operation
helm-charts copied to clipboard

[grafana] Functionality remove datasource on helm chart

Open olahouze opened this issue 3 years ago • 5 comments
trafficstars

What would you like to be added:

During a redeployment of the chart I want to modify the datasources

Why is this needed: I can't delete a datasource when updating my helm (The new data sources are only added to the old ones) Indeed, as indicated in the documentation (https://grafana.com/docs/grafana/latest/administration/provisioning/#datasources) you have to add the following information in the datasource.yaml

deleteDatasources:
  - name: Graphite
    orgId: 1

But in the file https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml we have only the field "datasources: {}" which allows only the addition of datasource

Describe the solution you'd like

Can you implement the functionality to allow to add in the charts/blob/main/charts/grafana/values.yaml an entry "deleteDatasources" which would add this in the configmap containing datasource.yaml

olahouze avatar Mar 25 '22 08:03 olahouze

On the same level as datasources: [] you can also define a deleteDatasources: [].

tamcore avatar Jul 05 '22 12:07 tamcore

For anyone looking into this issue, it looks like the helm template does not support deleteDatasources, only datasources. What I had to do to delete a datasource was manually edit the configmap and add deleteDatasources before the datasources field, then restart your pod.

Realistically, this wouldn't take much work to add that into the template

dkamenov-fitted avatar Jul 31 '22 01:07 dkamenov-fitted

It does. Exactly as I had described above. No manual configMap editing needed.

tamcore avatar Jul 31 '22 04:07 tamcore

On the same level as datasources: [] you can also define a deleteDatasources: [].

Ok but can you add this element directly in the HELM Template that you put at the disposal of the community ? (as it is the case for datasources: [])

image

Best regards

olahouze avatar Aug 17 '22 11:08 olahouze

Opened a PR for it.

tamcore avatar Aug 17 '22 12:08 tamcore

Opened a PR for it.

where?

I have just been running into this issue ...

rdxmb avatar May 08 '23 21:05 rdxmb

Why was this closed? Apparently there was a PR,but it doesn't seem to have been merged. Is there a reason to prefer not to implement deleteDatasources? It's an essential part of Grafana config, I can't understand this decision.

joeloplot avatar Jul 25 '23 14:07 joeloplot

@tamcore what happened to this PR? any idea why it never got merged?

joeloplot avatar Jul 25 '23 14:07 joeloplot

@joeloplot No idea. I thought i had raised the PR, but apparently i didn't. Anyhow, did it now. Although, as you will see, this is really nothing special. You just have to place to deleteDatasources entry in the right spot. No fancy implementation needed.

tamcore avatar Jul 25 '23 18:07 tamcore

For anyone confused about how to remove a datasource that was added through a provisioning file, I'll try to give more details about what's likely happening.

If you are using Kubernetes and deploying Grafana tthrough the grafana helm chart in this repository, you may have enabled the functionality where there is a sidecar watching for configmaps labels with grafana_datasource=1 and then automatically adding that data to /etc/grafana/provisioning/datasources files. Once that happens, the datasource appears in Grafana and that's the end of it. Other charts like kube-prometheus-stack and loki-stack might have added their own datasources through the same mechanism (this is out of control by the grafana chart).

To remove datasources you have to:

  • Stop the helm chart(s) from adding configmaps with grafana_datasource=1 (investigate how your chart(s) do that)
  • Tell Grafana that it should delete the datasources from its database (just removing the datasource definition is NOT enough):
  • Manually: edit the configmap and add the deleteDatasources list
  • Through the grafana helm chart: add the deleteDatasources list to datasources['datasources.yaml].deleteDatasources and do a new release

Once the configmap is updated with deleteDatasources, the sidecar will pick this up and update the proper config file that Grafana pods use. They will see deleteDatasources and remove those datasources before adding new ones.

Why the grafana chart doesn't need any new functionality? Because it's simply passing whatever you have in the values.yaml file datasources to the configmap as-is. The PR by @tamcore only had to add a comment to help guide people but the functionality is actually built in Grafana. You just have to fill the proper YAML for it to work.

I've opted to edit the configmap manually because I didn't want to make two commits to remove some broken datasources that other charts added. One to add them to deleteDatasources and another commits to remove them from there (to avoid dead code).

gtirloni avatar Sep 08 '23 09:09 gtirloni