I want to re-use string constant like "KubeDeploymentReplicasMismatch|KubeHpaReplicasMismatch|KubePodNotReady|KubeContainerWaiting" in several Alertmanager template definitions.
let me illustrate by example (I know the below wouldn't work):
{{ $myAlertGroup := "KubeDeploymentReplicasMismatch|KubeHpaReplicasMismatch|KubePodNotReady|KubeContainerWaiting" }}
{{ define "__alert_message_title" -}}
{{ if match .GroupLabels.alertname $myAlertGroup -}}
{{ .CommonAnnotations.message }}
{{- end }}
{{ define "__alert_message_body" -}}
{{ if match .GroupLabels.alertname $myAlertGroup -}}
{{- range .Alerts.Firing }}
• `{{ .Labels.namespace -}}`/`{{ .Labels.pod -}}`
{{- end }}
{{- end }}
Is there a way to achieve this?
It's possible to move variable definition inside {{ define .. }} block but then I need to define the same value twice, once per template definition. I want to manage the value in one place.