jiralert
jiralert copied to clipboard
Remove need to template file
We're looking to deploy jiralert into Kubernetes via Helm, however the current configuration setup fails linting in Helm due to the templating that goes on. Helm tries to resolve things like .Status and .Alerts when it lints/deploys and it fails (for obvious reasons).
I understand that templating offers a lot of nice things, especially in the way that you want to format your description and summary -- but it would be ideal if templating was optional and the summary/description fields defaulted to what you have now in the template file. In other words, if you provide a template file, then great we'll use it, otherwise we're going to set the "default" style.
What do you think? The current configuration prevents us from being able to install this into Kubernetes with Helm. We're going to fork the project and attempt to make these changes.
IHey, :wave:
Hopefully we can start more movement on this.
IMO valid request, fixed here: https://github.com/free/jiralert/pull/25 PTAL @ealexhaywood
I'm sorry to be a PITA (and I've never used Helm), but are you saying that Helm can't deploy any file that contains .Status and .Alerts without processing it first? What about binaries?
At first sight this looks like a pretty significant change for (what I'm hoping is) a non-existent issue.
Yea I agree this issue is kind of weird - do you mean @ealexhaywood that essentially you cannot have Go templates in the configuration itself, right? I think yes - this is rather Helm issue as jiralert bases on this quite heavily.
I did the fix mostly to simplify setup (increase adoption) as template file is not really required AFAIK. You really that for multiline, complex templates. I am fine with leaving it required though, not strong opinion.
Yes @free and @bwplotka that is correct. Essentially you can't template within a template. Helm is entirely based off of Go templating, just how the template configuration for jiralert is.
We ended up modifying our own fork (although not on GitHub) of jiralert and made the template optional similar to what you did in https://github.com/free/jiralert/pull/25. The whole goal was simply to allow us to deploy jiralert via Helm to a k8s cluster.
Essentially you can't template within a template. Helm is entirely based off of Go templating, just how the template configuration for jiralert is.
The simple workaround for that is to "designate" the template file as "binary" rather than "configuration". No idea what that means in terms of Helm, but if it can deploy the jiralert binary without attempting to do template replacement, you can use the same mechanism to deploy the template file.
And for the record, Prometheus also comes with a console_libraries directory containing a couple of template definition files. I am not aware of a Prometheus issue asking to remove them because they break deployment via Helm. I'm pretty sure that is where I "borrowed" the idea from.
Yes, but no one uses it and we Prometheus does not require to specify console_libraries files as they are optional.
I think you are right, that no fork is needed - just don't use templating.
However I also believe https://github.com/free/jiralert/pull/25 might solve some annoyance, plus it fixes couple of other problems (lack of tests, not isolated package and struct leaking an internal details).
This can be avoided by using fields as is in yaml, example:
in values.yaml:
template: |
{{ define "jira.summary" }}
[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }} for {{ if .CommonLabels.cluster_name }}{{ .CommonLabels.cluster_name }}{{ else }}{{ .CommonLabels.job }}{{ end }}
{{ end }}
{{ define "jira.description" }}{{ range .Alerts.Firing }}Labels:
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}
Annotations:
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
{{ end }}
Source: {{ .GeneratorURL }}
{{ end }}{{ end }}
in chart templates:
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "jiralert.fullname" . }}-template
labels:
app.kubernetes.io/name: {{ include "jiralert.name" . }}
helm.sh/chart: {{ include "jiralert.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app: {{ template "jiralert.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
jiralert.tmpl: |
{{ .Values.template | indent 4 }}
and this way the code is not parsed