From 71e2fefc6217627e9890cad9bfcb3e446fa435e5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 8 Sep 2018 07:41:54 -0700 Subject: [PATCH] extraConfig support for consul clients --- templates/client-config-configmap.yaml | 16 ++++++++ templates/client-daemonset.yaml | 6 +++ test/unit/client-configmap.bats | 53 ++++++++++++++++++++++++++ values.yaml | 5 +++ 4 files changed, 80 insertions(+) create mode 100644 templates/client-config-configmap.yaml create mode 100755 test/unit/client-configmap.bats diff --git a/templates/client-config-configmap.yaml b/templates/client-config-configmap.yaml new file mode 100644 index 0000000..1bf88ba --- /dev/null +++ b/templates/client-config-configmap.yaml @@ -0,0 +1,16 @@ +# ConfigMap with extra configuration specified directly to the chart +# for client agents only. +{{- if (or (and (ne (.Values.client.enabled | toString) "-") .Values.client.enabled) (and (eq (.Values.client.enabled | toString) "-") .Values.global.enabled)) }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "consul.fullname" . }}-client-config + labels: + app: {{ template "consul.name" . }} + chart: {{ template "consul.chart" . }} + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} +data: + extra-from-values.json: |- +{{ tpl .Values.client.extraConfig . | indent 4 }} +{{- end }} diff --git a/templates/client-daemonset.yaml b/templates/client-daemonset.yaml index 8a37136..4adbac3 100644 --- a/templates/client-daemonset.yaml +++ b/templates/client-daemonset.yaml @@ -34,6 +34,9 @@ spec: volumes: - name: data emptyDir: {} + - name: config + configMap: + name: {{ template "consul.fullname" . }}-client-config containers: - name: consul @@ -57,6 +60,7 @@ spec: -advertise="${POD_IP}" \ -bind=0.0.0.0 \ -client=0.0.0.0 \ + -config-dir=/consul/config \ -datacenter={{ .Values.server.datacenter }} \ -data-dir=/consul/data \ {{- if (.Values.client.join) and (gt (len .Values.client.join) 0) }} @@ -74,6 +78,8 @@ spec: volumeMounts: - name: data mountPath: /consul/data + - name: config + mountPath: /consul/config lifecycle: preStop: exec: diff --git a/test/unit/client-configmap.bats b/test/unit/client-configmap.bats new file mode 100755 index 0000000..13cd654 --- /dev/null +++ b/test/unit/client-configmap.bats @@ -0,0 +1,53 @@ +#!/usr/bin/env bats + +load _helpers + +@test "client/ConfigMap: enabled by default" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/client-config-configmap.yaml \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "client/ConfigMap: enable with global.enabled false" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/client-config-configmap.yaml \ + --set 'global.enabled=false' \ + --set 'client.enabled=true' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "true" ] +} + +@test "client/ConfigMap: disable with client.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/client-config-configmap.yaml \ + --set 'client.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "client/ConfigMap: disable with global.enabled" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/client-config-configmap.yaml \ + --set 'global.enabled=false' \ + . | tee /dev/stderr | + yq 'length > 0' | tee /dev/stderr) + [ "${actual}" = "false" ] +} + +@test "client/ConfigMap: extraConfig is set" { + cd `chart_dir` + local actual=$(helm template \ + -x templates/client-config-configmap.yaml \ + --set 'client.extraConfig="{\"hello\": \"world\"}"' \ + . | tee /dev/stderr | + yq '.data["extra-from-values.json"] | match("world") | length' | tee /dev/stderr) + [ ! -z "${actual}" ] +} diff --git a/values.yaml b/values.yaml index 02cf217..a1889ed 100644 --- a/values.yaml +++ b/values.yaml @@ -68,6 +68,11 @@ client: image: null join: null + # extraConfig is a raw string of extra configuration to set with the + # server. This should be JSON or HCL. + extraConfig: | + {} + # ConnectInject will enable the automatic Connect sidecar injector. connectInject: enabled: false # "-" disable this by default for now until the image is public