Skip to content

Commit

Permalink
Default prometheusRules.rules should be an empty list
Browse files Browse the repository at this point in the history
Support for prometheus-operator was added in #772 and a default empty set of rules was defined as an empty map `{}`. However, as evidenced by the commented out rule examples below that very same values.yaml, this is expected to be a list, so `rules:` value should be set to an empty list `[]`.

Because of this Helm issues a warning if you actually define rules and pass them with a --values <filename>:

```
coalesce.go:220: warning: cannot overwrite table with non table for vault.serverTelemetry.prometheusRules.rules (map[])
```

Co-authored-by: Marc 'risson' Schmitt <[email protected]>
  • Loading branch information
vitaliyf and rissson committed May 11, 2023
1 parent 14585a1 commit febbe10
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
14 changes: 7 additions & 7 deletions test/unit/prometheus-prometheusrules.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load _helpers
cd `chart_dir`
local actual=$( (helm template \
--show-only templates/prometheus-prometheusrules.yaml \
--set 'serverTelemetry.prometheusRules.rules.foo=bar' \
--set 'serverTelemetry.prometheusRules.rules[0].foo=bar' \
. || echo "---") | tee /dev/stderr |
yq 'length > 0' | tee /dev/stderr)
[ "${actual}" = "false" ]
Expand All @@ -26,24 +26,24 @@ load _helpers
local output=$( (helm template \
--show-only templates/prometheus-prometheusrules.yaml \
--set 'serverTelemetry.prometheusRules.enabled=true' \
--set 'serverTelemetry.prometheusRules.rules.foo=bar' \
--set 'serverTelemetry.prometheusRules.rules.baz=qux' \
--set 'serverTelemetry.prometheusRules.rules[0].foo=bar' \
--set 'serverTelemetry.prometheusRules.rules[1].baz=qux' \
.) | tee /dev/stderr )

[ "$(echo "$output" | yq -r '.spec.groups | length')" = "1" ]
[ "$(echo "$output" | yq -r '.spec.groups[0] | length')" = "2" ]
[ "$(echo "$output" | yq -r '.spec.groups[0].name')" = "release-name-vault" ]
[ "$(echo "$output" | yq -r '.spec.groups[0].rules | length')" = "2" ]
[ "$(echo "$output" | yq -r '.spec.groups[0].rules.foo')" = "bar" ]
[ "$(echo "$output" | yq -r '.spec.groups[0].rules.baz')" = "qux" ]
[ "$(echo "$output" | yq -r '.spec.groups[0].rules[0].foo')" = "bar" ]
[ "$(echo "$output" | yq -r '.spec.groups[0].rules[1].baz')" = "qux" ]
}

@test "prometheus/PrometheusRules-server: assertSelectors default" {
cd `chart_dir`
local output=$( (helm template \
--show-only templates/prometheus-prometheusrules.yaml \
--set 'serverTelemetry.prometheusRules.enabled=true' \
--set 'serverTelemetry.prometheusRules.rules.foo=bar' \
--set 'serverTelemetry.prometheusRules.rules[0].foo=bar' \
. ) | tee /dev/stderr)

[ "$(echo "$output" | yq -r '.metadata.labels | length')" = "5" ]
Expand All @@ -55,7 +55,7 @@ load _helpers
local output=$( (helm template \
--show-only templates/prometheus-prometheusrules.yaml \
--set 'serverTelemetry.prometheusRules.enabled=true' \
--set 'serverTelemetry.prometheusRules.rules.foo=bar' \
--set 'serverTelemetry.prometheusRules.rules[0].foo=bar' \
--set 'serverTelemetry.prometheusRules.selectors.baz=qux' \
--set 'serverTelemetry.prometheusRules.selectors.bar=foo' \
. ) | tee /dev/stderr)
Expand Down
19 changes: 19 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,25 @@
}
}
},
"serverTelemetry": {
"type": "object",
"properties": {
"prometheusRules": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"rules": {
"type": "array"
},
"selectors": {
"type": "object"
}
}
}
}
},
"ui": {
"type": "object",
"properties": {
Expand Down
2 changes: 1 addition & 1 deletion values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ serverTelemetry:
selectors: {}

# Some example rules.
rules: {}
rules: []
# - alert: vault-HighResponseTime
# annotations:
# message: The response time of Vault is over 500ms on average over the last 5 minutes.
Expand Down

0 comments on commit febbe10

Please sign in to comment.