I want to reduce copy/paste and have my environments (where I use kustomize) get an alerting rule from the base and then just provide the value.
base/prometheus-alerts.yaml
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
release: kube-prometheus-stack
role: app-rules
test: $(VAL_A) # This works
name: xx
namespace: monitoring
spec:
groups:
- name: xx
rules:
- alert: xx
annotations:
description: 'xx'
expr: sum(rate(xx[5m])) by (container) < $(VAL_A) # This does not
In my testing env I have the following
kustomization.yml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
vars:
- name: VAL_A
objref:
kind: PrometheusRule
name: connectors-taz-tcp-alerts
apiVersion: monitoring.coreos.com/v1
fieldref:
fieldpath: data.VAL_A
And then the patch-prometheus-alerts.yaml
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: connectors-taz-tcp-alerts
namespace: monitoring
data:
VAL_A: "hello-world"
Whenever I run kubectl kustomize .
I will get the following:
apiVersion: monitoring.coreos.com/v1
data:
VAL_A: hello-world
kind: PrometheusRule
metadata:
labels:
release: kube-prometheus-stack
role: app-rules
test: hello-world
name: xx
namespace: xx
spec:
groups:
- name: xx
rules:
- alert: xx
annotations:
[..]
expr: sum(rate(xx[5m])) by (container) < $(VAL_A)
Why is the label test
changed to “hello-world” but not the $(VAL_A)
in the expression?