Skip to content

Commit

Permalink
Fix setting args for the telemetry-collector (#2224)
Browse files Browse the repository at this point in the history
* Fix setting args for the telemetry-collector

Either the docker container or the execution method for the
telemetry-collector is making the args not get included on the process.
Switch to putting it directly in the command so we can ensure this works
as expected

* Fix bats test
  • Loading branch information
clly committed Jun 1, 2023
1 parent ec98eca commit 98f9f15
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
19 changes: 13 additions & 6 deletions charts/consul/templates/telemetry-collector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,20 @@ spec:
- "/bin/sh"
- "-ec"
- |
consul-telemetry-collector agent
{{- if .Values.telemetryCollector.customExporterConfig }}
args:
- -config-file-path /consul/config/config.json
{{ end }}
{{- if .Values.telemetryCollector.customExporterConfig }}
{{- if .Values.global.trustedCAs }}
{{- range $i, $cert := .Values.global.trustedCAs }}
cat <<EOF > /trusted-cas/custom-ca-{{$i}}.pem
{{- $cert | nindent 10 }}
EOF
{{- end }}
{{- end }}
consul-telemetry-collector agent \
{{- if .Values.telemetryCollector.customExporterConfig }}
-config-file-path /consul/config/config.json \
{{ end }}
volumeMounts:
{{- if .Values.telemetryCollector.customExporterConfig }}
- name: config
mountPath: /consul/config
{{- end }}
Expand Down
14 changes: 14 additions & 0 deletions charts/consul/test/unit/connect-inject-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,20 @@ load _helpers
[ "${actual}" = "true" ]
}

@test "connectInject/Deployment: metrics.enableTelemetryCollector can be configured" {
cd `chart_dir`
local cmd=$(helm template \
-s templates/connect-inject-deployment.yaml \
--set 'connectInject.enabled=true' \
--set 'global.metrics.enableTelemetryCollector=true' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].command' | tee /dev/stderr)

local actual=$(echo "$cmd" |
yq 'any(contains("-enable-telemetry-collector=true"))' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# consul and consul-dataplane images

Expand Down
24 changes: 23 additions & 1 deletion charts/consul/test/unit/telemetry-collector-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ load _helpers
--set 'telemetryCollector.image=bar' \
--set 'telemetryCollector.customExporterConfig="foo"' \
. | tee /dev/stderr |
yq '.spec.template.spec.containers[0].args')
yq '.spec.template.spec.containers[0].command')

local actual=$(echo $flags | yq -r '. | any(contains("-config-file-path /consul/config/config.json"))')
[ "${actual}" = "true" ]
Expand Down Expand Up @@ -977,3 +977,25 @@ load _helpers
[ "${actualTemplateFoo}" = "bar" ]
[ "${actualTemplateBaz}" = "qux" ]
}

#--------------------------------------------------------------------
# extraEnvironmentVariables

@test "telemetryCollector/Deployment: extra environment variables" {
cd `chart_dir`
local object=$(helm template \
-s templates/telemetry-collector-deployment.yaml \
--set 'telemetryCollector.enabled=true' \
--set 'telemetryCollector.extraEnvironmentVars.HCP_AUTH_TLS=insecure' \
--set 'telemetryCollector.extraEnvironmentVars.foo=bar' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local actual=$(echo $object |
yq -r 'map(select(.name == "HCP_AUTH_TLS")) | .[0].value' | tee /dev/stderr)
[ "${actual}" = "insecure" ]

local actual=$(echo $object |
yq -r 'map(select(.name == "foo")) | .[0].value' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}

0 comments on commit 98f9f15

Please sign in to comment.