Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Variable Interpolation within Helm chart #1006

Closed
devilmind81 opened this issue Jun 24, 2021 · 7 comments · Fixed by hashicorp/consul#10510
Closed

Variable Interpolation within Helm chart #1006

devilmind81 opened this issue Jun 24, 2021 · 7 comments · Fixed by hashicorp/consul#10510

Comments

@devilmind81
Copy link

Hi all,
using helm 0.31.1 chart to setup consul on gke cluster I have two issues:

Consul command I run:
helm install consul hashicorp/consul -f /home/user/test-consul/k8s/consul/config.yaml --version 0.31.1 -n consul

  1. when I insert in the config.yaml file the following lines:
...
server:
  replicas: 1
  bootstrapExpect: 1
  extraConfig: |
    {
      "ui_config": {
        "enabled": true,
        "metrics_provider": "prometheus",
        "metrics_proxy": {
          "base_url": "http://prometheus-server"
        },
        "dashboard_url_templates": {
          "service" : "http://myvirtualmachine:3000/d/4Z9CWegnz/test-consul?orgId=1&var-service={{Service.Name}}&var-namespace={{Service.Namespace}}&var-dc={{Datacenter}}"
        }
      }
    }
	
...

helm command failing with the folloqing error:

Error: template: consul/templates/server-statefulset.yaml:48:51: executing "consul/templates/server-statefulset.yaml" at <include (print $.Template.BasePath "/server-config-configmap.yaml") .>: error calling include: template: consul/templates/server-config-configmap.yaml:15:3: executing "consul/templates/server-config-configmap.yaml" at <tpl .Values.server.extraConfig .>: error calling tpl: error during tpl function execution for "\n{\n \"ui_config\": {\n \"enabled\": true,\n \"metrics_provider\": \"prometheus\",\n \"metrics_proxy\": {\n \"base_url\": \"http://prometheus-server\"\n },\n \"dashboard_url_templates\": {\n \"service\" : \"http://myvirtualmachine:3000/d/4Z9CWegnz/poc-consul?orgId=1&var-service={{Service.Name}}&var-namespace={{Service.Namespace}}&var-dc={{Datacenter}}\"\n }\n }\n}\n": parse error at (consul/templates/server-statefulset.yaml:10): function "Service" not defined

How can I solve it?

  1. I have noticed that if I change the service url removing statement within the {{ }} the k8s configmap cannot updated as expected but I must edit it directly from the cluster with kubectl.

Can you please support here?

Thank you!

@david-yu
Copy link
Contributor

Hi @devilmind81 could you post your entire Helm values file? I assume you are using the built-in prometheus instance with Consul?

@david-yu david-yu transferred this issue from hashicorp/consul Jun 25, 2021
@david-yu david-yu changed the title UI Visualizzation UI Visualization Jun 25, 2021
@devilmind81
Copy link
Author

devilmind81 commented Jun 25, 2021

Hi @david-yu ,
thank you for replying, helm value file attached as requested.
Really I have been set up prometheus in the cluster (same namespace) using prometheus helm chart and seems the metrics are working as expected. Are you suggest to use built-in one for a specific reason instead?
config.yaml.txt

Waiting your feedback.
Thank you!

@ndhanushkodi
Copy link
Contributor

hey @devilmind81, could you tell us a little more about what you're trying to do with the {{Service.Name}} {{Service.Namespace}} in that "dashboard_url_templates"? I am not sure that Helm supports interpolation with the {{}} notation within the values. At what point were you hoping for those variables to be interpolated with real values? Where would you expect Service.Name to come from? Thanks so much!

@david-yu david-yu changed the title UI Visualization Variable Interpolation within Helm chart Jun 26, 2021
@lkysow
Copy link
Member

lkysow commented Jun 27, 2021

hey @devilmind81, could you tell us a little more about what you're trying to do with the {{Service.Name}} {{Service.Namespace}} in that "dashboard_url_templates"? I am not sure that Helm supports interpolation with the {{}} notation within the values. At what point were you hoping for those variables to be interpolated with real values? Where would you expect Service.Name to come from? Thanks so much!

That comes from https://www.consul.io/docs/connect/observability/ui-visualization. Consul will fill that in when it's generating its dashboard URLs in the UI so it's not Helm that is expected to fill it in.

@lkysow
Copy link
Member

lkysow commented Jun 27, 2021

From helm/helm#2798

You need to escape the {{ characters via {{ "{{" }}:

          "service" : "http://myvirtualmachine:3000/d/4Z9CWegnz/poc-consul?orgId=1&var-service={{ "{{" }}Service.Name}}&var-namespace={{ "{{" }}Service.Namespace}}&var-dc={{ "{{" }}Datacenter}}"

@devilmind81
Copy link
Author

Hi @lkysow,
thank you for the feedback.
I have a prometheus federeted with one in the cluster. The external prometheus is configured to be a datasource of a grafana so in that way I'm able to collect all gke and consul metrics in a dedicated dashboard that using variables to filter my services.
With the config above I'm able to reach grafana and filter by service dynamically but during my automation test related to create all enviroment with helm from scratch I have encountered the issue.
I will try again following your suggestion and let you know, thank you!

@devilmind81
Copy link
Author

Hi,
I have tested the suggestion using the escapes and I confirm that the dynamic configuration of UI working directly from helm value file as expected.
Thank you for the support!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants