Skip to content

Commit

Permalink
Add new value ui.dashboardURLTemplates (#937)
Browse files Browse the repository at this point in the history
* Add new value ui.dashboardURLTemplates

This value is used to set Consul's `ui_config.dashboard_url_templates`
config. I'm pulling it out as its own value rather than getting users
to just use `server.extraConfig` because these template strings always
use the characters `{{` and when used within `server.extraConfig`,
users need to escape those characters.

Before:

```yaml
server:
  extraConfig: |
    {
      "ui_config": {
        "dashboard_url_templates": {
          "service": "http://grafana/service/{{ "{{" }}Service.Name}}"
        }
      }
    }
```

Now:

```yaml
ui:
  dashboardURLTemplates:
    service: "http://grafana/service/{{Service.Name}}"
```
  • Loading branch information
lkysow authored Jan 19, 2022
1 parent 0666932 commit d0d2371
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ FEATURES:
IMPROVEMENTS:
* Helm
* Allow customization of `terminationGracePeriodSeconds` on the ingress gateways. [[GH-947](https://github.com/hashicorp/consul-k8s/pull/947)]
* Support `ui.dashboardURLTemplates.service` value for setting [dashboard URL templates](https://www.consul.io/docs/agent/options#ui_config_dashboard_url_templates_service). [[GH-937](https://github.com/hashicorp/consul-k8s/pull/937)]

BUG FIXES:
* Helm
Expand Down
3 changes: 3 additions & 0 deletions charts/consul/templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ spec:
{{- end }}
{{- if .Values.ui.enabled }}
-ui \
{{- if .Values.ui.dashboardURLTemplates.service }}
-hcl='ui_config { dashboard_url_templates { service = "{{ .Values.ui.dashboardURLTemplates.service }}" } }' \
{{- end }}
{{- end }}
{{- $serverSerfLANPort := .Values.server.ports.serflan.port -}}
{{- range $index := until (.Values.server.replicas | int) }}
Expand Down
28 changes: 28 additions & 0 deletions charts/consul/test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1785,3 +1785,31 @@ load _helpers
yq -r '.containers[0].volumeMounts[] | select(.name == "consul-ca-key")' | tee /dev/stderr)
[ "${actual}" = "" ]
}

#--------------------------------------------------------------------
# ui.dashboardURLTemplates.service

@test "server/StatefulSet: dashboard_url_templates not set by default" {
cd `chart_dir`

local actual=$(helm template \
-s templates/server-statefulset.yaml \
. | tee /dev/stderr |
yq -r ".spec.template.spec.containers[0].command | any(contains(\"dashboard_url_templates\"))" | tee /dev/stderr)

[ "${actual}" = "false" ]
}

@test "server/StatefulSet: ui.dashboardURLTemplates.service sets the template" {
cd `chart_dir`

local expected='-hcl='\''ui_config { dashboard_url_templates { service = \"http://localhost:3000/d/WkFEBmF7z/services?orgId=1&var-Service={{Service.Name}}\" } }'

local actual=$(helm template \
-s templates/server-statefulset.yaml \
--set 'ui.dashboardURLTemplates.service=http://localhost:3000/d/WkFEBmF7z/services?orgId=1&var-Service={{Service.Name}}' \
. | tee /dev/stderr |
yq -r ".spec.template.spec.containers[0].command | any(contains(\"$expected\"))" | tee /dev/stderr)

[ "${actual}" = "true" ]
}
5 changes: 5 additions & 0 deletions charts/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,11 @@ ui:
# @type: string
baseURL: http://prometheus-server

# Corresponds to https://www.consul.io/docs/agent/options#ui_config_dashboard_url_templates configuration.
dashboardURLTemplates:
# Sets https://www.consul.io/docs/agent/options#ui_config_dashboard_url_templates_service.
service: ""

# Configure the catalog sync process to sync K8S with Consul
# services. This can run bidirectional (default) or unidirectionally (Consul
# to K8S or K8S to Consul only).
Expand Down

0 comments on commit d0d2371

Please sign in to comment.