From 85abcc840b91df8742577c5b1899acfbe25424ab Mon Sep 17 00:00:00 2001 From: natemollica-dev Date: Tue, 6 Feb 2024 15:00:00 -0800 Subject: [PATCH] add in server-statefulset bats test for extraConfig validation testing --- charts/consul/templates/_helpers.tpl | 29 ++----- .../consul/test/unit/server-statefulset.bats | 77 +++++++++++++++++++ 2 files changed, 82 insertions(+), 24 deletions(-) diff --git a/charts/consul/templates/_helpers.tpl b/charts/consul/templates/_helpers.tpl index 7962aaff43..ca87485a78 100644 --- a/charts/consul/templates/_helpers.tpl +++ b/charts/consul/templates/_helpers.tpl @@ -167,30 +167,11 @@ Cleanup server.extraConfig entries to avoid conflicting entries: Usage: {{ template "consul.validateExtraConfig" . }} */}} {{- define "consul.validateExtraConfig" -}} -{{- if (and .Values.global.metrics.enabled .Values.global.metrics.enableAgentMetrics) }} -{{- if (contains "enable_debug" .Values.server.extraConfig) }} -{{ fail "The 'enable_debug' key is present in extra-from-values.json. Use 'server.enableAgentDebug' to set this value." }} -{{- end }} -{{- if (contains "disable_hostname" .Values.server.extraConfig) }} -{{ fail "The 'disable_hostname' key is present in extra-from-values.json. Use 'global.metrics.disableAgentHostName' to set this value." }} -{{- end }} -{{- if (contains "enable_host_metrics" .Values.server.extraConfig) }} -{{ fail "The 'enable_host_metrics' key is present in extra-from-values.json. Use 'global.metrics.enableHostMetrics' to set this value." }} -{{- end }} -{{- if (contains "prefix_filter" .Values.server.extraConfig) }} -{{ fail "The 'prefix_filter' key is present in extra-from-values.json. Use 'global.metrics.prefix_filter' to set this value." }} -{{- end }} -{{- if (and .Values.global.metrics.datadog.dogstatsd.enabled) }} -{{- if (contains "dogstatsd_tags" .Values.server.extraConfig) }} -{{ fail "The 'dogstatsd_tags' key is present in extra-from-values.json. Use 'global.metrics.datadog.dogstatsd.dogstatsdTags' to set this value." }} -{{- end }} -{{- end }} -{{- if (and .Values.global.metrics.datadog.dogstatsd.enabled) }} -{{- if (contains "dogstatsd_addr" .Values.server.extraConfig) }} -{{ fail "The 'dogstatsd_addr' key is present in extra-from-values.json. Use 'global.metrics.datadog.dogstatsd.dogstatsd_addr' to set this value." }} -{{- end }} -{{- end }} -{{- end }} +{{- if (contains "enable_debug" .Values.server.extraConfig) }}{{ fail "The enable_debug key is present in extra-from-values.json. Use server.enableAgentDebug to set this value." }}{{- end }} +{{- if (contains "disable_hostname" .Values.server.extraConfig) }}{{ fail "The disable_hostname key is present in extra-from-values.json. Use global.metrics.disableAgentHostName to set this value." }}{{- end }} +{{- if (contains "enable_host_metrics" .Values.server.extraConfig) }}{{ fail "The enable_host_metrics key is present in extra-from-values.json. Use global.metrics.enableHostMetrics to set this value." }}{{- end }} +{{- if (contains "prefix_filter" .Values.server.extraConfig) }}{{ fail "The prefix_filter key is present in extra-from-values.json. Use global.metrics.prefix_filter to set this value." }}{{- end }} +{{- if (and .Values.global.metrics.enabled .Values.global.metrics.enableAgentMetrics) }}{{- if (and .Values.global.metrics.datadog.dogstatsd.enabled) }}{{- if (contains "dogstatsd_tags" .Values.server.extraConfig) }}{{ fail "The dogstatsd_tags key is present in extra-from-values.json. Use global.metrics.datadog.dogstatsd.dogstatsdTags to set this value." }}{{- end }}{{- end }}{{- if (and .Values.global.metrics.datadog.dogstatsd.enabled) }}{{- if (contains "dogstatsd_addr" .Values.server.extraConfig) }}{{ fail "The dogstatsd_addr key is present in extra-from-values.json. Use global.metrics.datadog.dogstatsd.dogstatsd_addr to set this value." }}{{- end }}{{- end }}{{- end }} {{- end -}} {{/* diff --git a/charts/consul/test/unit/server-statefulset.bats b/charts/consul/test/unit/server-statefulset.bats index 14f4a8a6e4..8fceb5c474 100755 --- a/charts/consul/test/unit/server-statefulset.bats +++ b/charts/consul/test/unit/server-statefulset.bats @@ -1102,6 +1102,83 @@ load _helpers [ "${actual}" = 576044232d6181bca69628af87c12f15311ebd3f0ab700e112b3e1dea9225125 ] } +#-------------------------------------------------------------------- +# server extraConfig validation + +@test "server/Statefulset: Validate enable_debug extraConfig for Consul Helm chart" { + cd `chart_dir` + run helm template \ + -s templates/server-statefulset.yaml \ + --set global.metrics.enabled=true \ + --set global.metrics.enableAgentMetrics=true \ + --set server.extraConfig=enable_debug=true \ + . + [ "$status" -eq 1 ] + [[ "$output" =~ "The enable_debug key is present in extra-from-values.json. Use server.enableAgentDebug to set this value." ]] +} + +@test "server/Statefulset: Validate disable_hostname extraConfig for Consul Helm chart" { + cd `chart_dir` + run helm template \ + -s templates/server-statefulset.yaml \ + --set global.metrics.enabled=true \ + --set global.metrics.enableAgentMetrics=true \ + --set server.extraConfig=telemetry.disable_hostname=true \ + . + [ "$status" -eq 1 ] + [[ "$output" =~ "The disable_hostname key is present in extra-from-values.json. Use global.metrics.disableAgentHostName to set this value." ]] +} + +@test "server/Statefulset: Validate enable_host_metrics extraConfig for Consul Helm chart" { + cd `chart_dir` + run helm template \ + -s templates/server-statefulset.yaml \ + --set global.metrics.enabled=true \ + --set global.metrics.enableAgentMetrics=true \ + --set server.extraConfig=telemetry.enable_host_metrics=true \ + . + [ "$status" -eq 1 ] + [[ "$output" =~ "The enable_host_metrics key is present in extra-from-values.json. Use global.metrics.enableHostMetrics to set this value." ]] +} + +@test "server/Statefulset: Validate prefix_filter extraConfig for Consul Helm chart" { + cd `chart_dir` + run helm template \ + -s templates/server-statefulset.yaml \ + --set global.metrics.enabled=true \ + --set global.metrics.enableAgentMetrics=true \ + --set server.extraConfig=telemetry.prefix_filter=["+consul.rpc.server.call"] \ + . + [ "$status" -eq 1 ] + [[ "$output" =~ "The prefix_filter key is present in extra-from-values.json. Use global.metrics.prefix_filter to set this value." ]] +} + +@test "server/Statefulset: Validate dogstatsd_tags extraConfig for Consul Helm chart" { + cd `chart_dir` + run helm template \ + -s templates/server-statefulset.yaml \ + --set global.metrics.enabled=true \ + --set global.metrics.enableAgentMetrics=true \ + --set global.metrics.datadog.dogstatsd.enabled=true \ + --set server.extraConfig=telemetry.dogstatsd_tags='[\"source:consul-server\"\,\"consul_service:consul\"]' \ + . + [ "$status" -eq 1 ] + [[ "$output" =~ "The dogstatsd_tags key is present in extra-from-values.json. Use global.metrics.datadog.dogstatsd.dogstatsdTags to set this value." ]] +} + +@test "server/Statefulset: Validate dogstatsd_addr extraConfig for Consul Helm chart" { + cd `chart_dir` + run helm template \ + -s templates/server-statefulset.yaml \ + --set global.metrics.enabled=true \ + --set global.metrics.enableAgentMetrics=true \ + --set global.metrics.datadog.dogstatsd.enabled=true \ + --set server.extraConfig=telemetry.dogstatsd_addr="localhost:8125" \ + . + [ "$status" -eq 1 ] + [[ "$output" =~ "The dogstatsd_addr key is present in extra-from-values.json. Use global.metrics.datadog.dogstatsd.dogstatsd_addr to set this value." ]] +} + #-------------------------------------------------------------------- # tolerations