Skip to content

Commit

Permalink
add in server-statefulset bats test for extraConfig validation testing
Browse files Browse the repository at this point in the history
  • Loading branch information
natemollica-nm committed Feb 7, 2024
1 parent cac598b commit b9cfe7c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 24 deletions.
29 changes: 5 additions & 24 deletions charts/consul/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}

{{/*
Expand Down
77 changes: 77 additions & 0 deletions charts/consul/test/unit/server-statefulset.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b9cfe7c

Please sign in to comment.