2

I'm using the prometheus stack project to implement via helm with kubernetes, but I would like to customize some rules. I'm trying to use the additionalPrometheusRules parameter for this, but I'm facing syntax errors inside it, here's my structure:

../module-prometheus-helm
├── Chart.yaml
├── charts
├── rules
│   └── customrules.yaml
├── templates
│   └── configmap.yaml
└── values.yaml

File: customrules.yaml

additionalPrometheusRules:
 - name: my-rule-file
   groups:
     - name: my_group
       rules:
       - record: my_record
         expr: 100 * my_record

File: configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-receiver-configmap
data:
    {{ $currentScope := . }}
    {{ range $path, $_ :=  .Files.Glob  "rules/**.yaml" }}
    {{- with $currentScope}}
{{ base $path }}: |-
{{ .Files.Get $path | indent 2 }}
    {{- end }}
    {{ end }}

File values.yaml is default helm.

Output Error

Error: INSTALLATION FAILED: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(ConfigMap): unknown field "customrules.yaml" in io.k8s.api.core.v1.ConfigMap
helm.go:84: [debug] error validating "": error validating data: ValidationError(ConfigMap): unknown field "customrules.yaml" in io.k8s.api.core.v1.ConfigMap

How can I independently import the additional rules into the repository without polluting the values.yaml file?

Jyothi Kiranmayi
  • 2,090
  • 5
  • 14
Luis Henrique
  • 701
  • 15
  • 36
  • 1
    This is a very common helm-ism; you have your `{{` flush with the leading edge of the file but the generated file must still be legal yaml after the template is done with it. You almost have it with your `| indent 2` but that will merely indent the _value_, nothing is indenting the _key_. Then, after you fix the key indent, you'll need to up that `indent` value to be 2 more than whatever you indent the key by. – mdaniel Apr 19 '22 at 01:44
  • 1
    For the `additionalPrometheusRules` you are trying to set, I noticed this in the docs "## Deprecated way to provide custom recording or alerting rules to be deployed into the cluster.". It seems you should be using `additionalPrometheusRulesMap` now. – jordanm Apr 19 '22 at 01:53
  • 1
    I am not really understanding the expecrtation where the configmap becomes `additionalPrometheusRules` as values for a different helm chart? flux has this support but default helm does not. – jordanm Apr 19 '22 at 01:55
  • I'm thinking of using terraform, it seems that the helm is not prepared to receive this in this parameter – Luis Henrique Apr 19 '22 at 14:58

0 Answers0