how to use OR || in helm yaml chart

143 views Asked by At

Team,

I have created an alert and it is working but I need to use it for two values. any hint how can i use the OR operator in between message? when i remove the condition then it works as expected.

working expression

message: 'Node {{ `{{ $labels.nodename }}` }} was rebooted'

not working expression

message: 'Node {{- if or `{{ $labels.nodename }}` `{{ $labels.node }}` }} was rebooted {{- end }}'
    - alert: NodeReboot
      annotations:
        message: 'Node {{- if or `{{ $labels.nodename }}` `{{ $labels.node }}` }} was rebooted {{- end }}'
        runbook_url: TODO
      expr: (time() - node_boot_time_seconds)/60 < 15
      for: {{ .Values.genericAlerts.alertDefinitions.NodeReboot.for }}
      {{- if .Values.genericAlerts.alertDefinitions.NodeReboot.labels }}
      labels:
{{ toYaml .Values.genericAlerts.alertDefinitions.NodeReboot.labels | indent 8 }}
      {{- end }}
    {{- end }}
    {{- if .Values.genericAlerts.alertDefinitions.GpuNodeMissingPowerLabel.enabled }}

output:

- alert: NodeReboot
    annotations:
    message: 'Node was rebooted'

expected

- alert: NodeReboot
    annotations:
    message: 'Node test-node1 was rebooted'
1

There are 1 answers

0
Rafał Leszko On

If you want to print only one of them, use the following condition.

message: 'Node {{ if $labels.nodename }}{{ $labels.nodename }}{{ else if $labels.node }}{{ $labels.node }}{{ end }} was rebooted'

If you don't want to print was rebooted if none of them is set, then add the following IF condition.

message: 'Node {{ if $labels.nodename }}{{ $labels.nodename }}{{ else if $labels.node }}{{ $labels.node }}{{ end }}{{ if or $labels.nodename $labels.node }} was rebooted{{ end }}'