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

add hostIP as env to server-statefulset and substitute env variables in extraConfig #1042

Merged
merged 12 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

IMPROVEMENTS:
* Substitute `HOST_IP/POD_IP/HOSTNAME` variables in `server.extraConfig` and `client.extraConfig` so they are passed in to server/client config already evaluated at runtime. [[GH-1042](https://github.com/hashicorp/consul-helm/pull/1042)]
* Set failurePolicy to Fail for connectInject mutating webhook so that pods fail to schedule when the webhook is offline. This can be controlled via `connectInject.failurePolicy`. [[GH-1024](https://github.com/hashicorp/consul-helm/pull/1024)]
* Allow setting global.logLevel and global.logJSON and propogate this to all consul-k8s commands. [[GH-980](https://github.com/hashicorp/consul-helm/pull/980)]
* Allow setting `connectInject.replicas` to control number of replicas of webhook injector. [[GH-1029](https://github.com/hashicorp/consul-helm/pull/1029)]
Expand Down
14 changes: 14 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ as well as the global.name setting.
{{- end -}}
{{- end -}}

{{/*
Sets up the extra-from-values config file passed to consul and then uses sed to do any necessary
substitution for HOST_IP/POD_IP/HOSTNAME. Useful for dogstats telemetry. The output file
is passed to consul as a -config-file param on command line.
*/}}
{{- define "consul.extraconfig" -}}
mkdir -p /consul/extra-config
cp /consul/config/extra-from-values.json /consul/extra-config/extra-from-values.json
[ -n "${HOST_IP}" ] && sed -Ei "s|HOST_IP|${HOST_IP?}|g" /consul/extra-config/extra-from-values.json
[ -n "${POD_IP}" ] && sed -Ei "s|POD_IP|${POD_IP?}|g" /consul/extra-config/extra-from-values.json
[ -n "${HOSTNAME}" ] && sed -Ei "s|HOSTNAME|${HOSTNAME?}|g" /consul/extra-config/extra-from-values.json
{{- end -}}


{{/*
Create chart name and version as used by the chart label.
*/}}
Expand Down
3 changes: 3 additions & 0 deletions templates/client-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ spec:
- |
CONSUL_FULLNAME="{{template "consul.fullname" . }}"

{{ template "consul.extraconfig" }}

exec /bin/consul agent \
-node="${NODE}" \
-advertise="${ADVERTISE_IP}" \
Expand Down Expand Up @@ -261,6 +263,7 @@ spec:
{{- range $value := .Values.global.recursors }}
-recursor={{ quote $value }} \
{{- end }}
-config-file=/consul/extra-config/extra-from-values.json \
-domain={{ .Values.global.domain }}
volumeMounts:
- name: data
Expand Down
7 changes: 7 additions & 0 deletions templates/server-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ spec:
{{- else }}
fieldPath: status.podIP
{{- end }}
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: POD_IP
valueFrom:
fieldRef:
Expand Down Expand Up @@ -176,6 +180,8 @@ spec:
- |
CONSUL_FULLNAME="{{template "consul.fullname" . }}"

{{ template "consul.extraconfig" }}

exec /bin/consul agent \
-advertise="${ADVERTISE_IP}" \
-bind=0.0.0.0 \
Expand Down Expand Up @@ -236,6 +242,7 @@ spec:
{{- range $value := .Values.global.recursors }}
-recursor={{ quote $value }} \
{{- end }}
-config-file=/consul/extra-config/extra-from-values.json \
-server
volumeMounts:
- name: data-{{ .Release.Namespace }}
Expand Down
8 changes: 4 additions & 4 deletions test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -837,19 +837,19 @@ load _helpers
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.[3].name' | tee /dev/stderr)
yq -r '.[4].name' | tee /dev/stderr)
[ "${actual}" = "custom_proxy" ]

local actual=$(echo $object |
yq -r '.[3].value' | tee /dev/stderr)
yq -r '.[4].value' | tee /dev/stderr)
[ "${actual}" = "fakeproxy" ]

local actual=$(echo $object |
yq -r '.[4].name' | tee /dev/stderr)
yq -r '.[5].name' | tee /dev/stderr)
[ "${actual}" = "no_proxy" ]

local actual=$(echo $object |
yq -r '.[4].value' | tee /dev/stderr)
yq -r '.[5].value' | tee /dev/stderr)
[ "${actual}" = "custom_no_proxy" ]
}

Expand Down