Skip to content

Commit

Permalink
Fix newlines / whitespace trimming if opsrecipe is *not* specified or…
Browse files Browse the repository at this point in the history
… a dashboard *is* specified (#1411)
  • Loading branch information
AndiDog authored Oct 11, 2023
1 parent c11309f commit b84b570
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Support absolute Grafana dashboard URLs.
- Fix api server url in case the CAPI provider sets https prefix in the CAPI CR status.
- Alert template: fix newlines / whitespace trimming if opsrecipe is *not* specified or a dashboard *is* specified

## [4.48.0] - 2023-09-19

Expand Down
8 changes: 6 additions & 2 deletions files/templates/alertmanager/notification-template.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@

---

{{ if (index .Alerts 0).Annotations.opsrecipe }}📗 Runbook: {{ template "__runbookurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.opsrecipe -}}
📗 Runbook: {{ template "__runbookurl" . }}
{{ end -}}
🔔 Alertmanager {{ template "__alertmanagerurl" . }}
{{- if (index .Alerts 0).Annotations.dashboard }}📈 Dashboard: {{ template "__dashboardurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.dashboard -}}
📈 Dashboard: {{ template "__dashboardurl" . }}
{{ end -}}
👀 Prometheus: {{ (index .Alerts 0).GeneratorURL }}

---
Expand Down
11 changes: 6 additions & 5 deletions pkg/unittest/unittest.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func NewRunner(config Config) (*Runner, error) {
func (r *Runner) Run() error {
for _, file := range r.files {
r.T.Run(file.Name(), func(t *testing.T) {
input, err := inputValue(filepath.Join(r.inputDir, file.Name()))
inputFilePath := filepath.Join(r.inputDir, file.Name())
input, err := inputValue(inputFilePath)
if err != nil {
t.Fatal(err)
}
Expand All @@ -126,21 +127,21 @@ func (r *Runner) Run() error {
}
}

outputFile := filepath.Join(r.OutputDir, file.Name())
outputFilePath := filepath.Join(r.OutputDir, file.Name())
if r.Update {
err := os.WriteFile(outputFile, testResult, 0644) // #nosec
err := os.WriteFile(outputFilePath, testResult, 0644) // #nosec
if err != nil {
t.Fatal(err)
}
}

output, err := os.ReadFile(outputFile)
output, err := os.ReadFile(outputFilePath)
if err != nil {
t.Fatal(err)
}

if !bytes.Equal(testResult, output) {
t.Fatalf("\n\n%s\n", cmp.Diff(string(output), string(testResult)))
t.Fatalf("Rendered output does not match (input: %s, expected output: %s)\n\n%s\n", inputFilePath, outputFilePath, cmp.Diff(string(output), string(testResult)))
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@

---

{{ if (index .Alerts 0).Annotations.opsrecipe }}📗 Runbook: {{ template "__runbookurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.opsrecipe -}}
📗 Runbook: {{ template "__runbookurl" . }}
{{ end -}}
🔔 Alertmanager {{ template "__alertmanagerurl" . }}
{{- if (index .Alerts 0).Annotations.dashboard }}📈 Dashboard: {{ template "__dashboardurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.dashboard -}}
📈 Dashboard: {{ template "__dashboardurl" . }}
{{ end -}}
👀 Prometheus: {{ (index .Alerts 0).GeneratorURL }}

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@

---

{{ if (index .Alerts 0).Annotations.opsrecipe }}📗 Runbook: {{ template "__runbookurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.opsrecipe -}}
📗 Runbook: {{ template "__runbookurl" . }}
{{ end -}}
🔔 Alertmanager {{ template "__alertmanagerurl" . }}
{{- if (index .Alerts 0).Annotations.dashboard }}📈 Dashboard: {{ template "__dashboardurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.dashboard -}}
📈 Dashboard: {{ template "__dashboardurl" . }}
{{ end -}}
👀 Prometheus: {{ (index .Alerts 0).GeneratorURL }}

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@

---

{{ if (index .Alerts 0).Annotations.opsrecipe }}📗 Runbook: {{ template "__runbookurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.opsrecipe -}}
📗 Runbook: {{ template "__runbookurl" . }}
{{ end -}}
🔔 Alertmanager {{ template "__alertmanagerurl" . }}
{{- if (index .Alerts 0).Annotations.dashboard }}📈 Dashboard: {{ template "__dashboardurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.dashboard -}}
📈 Dashboard: {{ template "__dashboardurl" . }}
{{ end -}}
👀 Prometheus: {{ (index .Alerts 0).GeneratorURL }}

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@

---

{{ if (index .Alerts 0).Annotations.opsrecipe }}📗 Runbook: {{ template "__runbookurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.opsrecipe -}}
📗 Runbook: {{ template "__runbookurl" . }}
{{ end -}}
🔔 Alertmanager {{ template "__alertmanagerurl" . }}
{{- if (index .Alerts 0).Annotations.dashboard }}📈 Dashboard: {{ template "__dashboardurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.dashboard -}}
📈 Dashboard: {{ template "__dashboardurl" . }}
{{ end -}}
👀 Prometheus: {{ (index .Alerts 0).GeneratorURL }}

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@

---

{{ if (index .Alerts 0).Annotations.opsrecipe }}📗 Runbook: {{ template "__runbookurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.opsrecipe -}}
📗 Runbook: {{ template "__runbookurl" . }}
{{ end -}}
🔔 Alertmanager {{ template "__alertmanagerurl" . }}
{{- if (index .Alerts 0).Annotations.dashboard }}📈 Dashboard: {{ template "__dashboardurl" . }}{{- end }}
{{ if (index .Alerts 0).Annotations.dashboard -}}
📈 Dashboard: {{ template "__dashboardurl" . }}
{{ end -}}
👀 Prometheus: {{ (index .Alerts 0).GeneratorURL }}

---
Expand Down

0 comments on commit b84b570

Please sign in to comment.