Skip to content

Commit dede77b

Browse files
fix: dont override whole Grafana notification policy tree (#18041)
1 parent a7c859b commit dede77b

File tree

8 files changed

+1207
-25
lines changed

8 files changed

+1207
-25
lines changed

infra/runtime/grafana-manifests/kustomization.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ resources:
44
- alert-rules
55
- contact-points
66
- dashboards
7-
- notification-policies
87
- service-accounts

infra/runtime/grafana-manifests/notification-policies/altinn.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

infra/runtime/grafana-manifests/notification-policies/kustomization.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/Runtime/operator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ See [/CONTRIBUTING.md](/CONTRIBUTING.md).
1515

1616
- `maskinporten`: Reconciles `MaskinportenClient` resources and related secrets.
1717
- `secretsync`: Syncs selected secrets between namespaces.
18+
- `grafanapolicysync`: Upserts the Altinn Grafana notification route via Grafana API without replacing unrelated policy branches.
1819
- `azurekeyvaultsync`: Syncs selected Key Vault secrets to Kubernetes.
1920
- `cnpgsync`: Provisions CNPG resources via Flux in selected environments.
2021
- `inactivityscaler`: Scales selected workloads up/down based on environment, service owner, app presence, and workhours (`Europe/Oslo`, weekdays 06-18).

src/Runtime/operator/cmd/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"altinn.studio/operator/internal"
2727
"altinn.studio/operator/internal/controller/azurekeyvaultsync"
2828
"altinn.studio/operator/internal/controller/cnpgsync"
29+
"altinn.studio/operator/internal/controller/grafanapolicysync"
2930
"altinn.studio/operator/internal/controller/inactivityscaler"
3031
"altinn.studio/operator/internal/controller/maskinporten"
3132
"altinn.studio/operator/internal/controller/secretsync"
@@ -175,6 +176,13 @@ func main() {
175176
}
176177
// +kubebuilder:scaffold:builder
177178

179+
grafanaPolicySyncController := grafanapolicysync.NewReconciler(rt, mgr.GetClient())
180+
if err = mgr.Add(grafanaPolicySyncController); err != nil {
181+
setupLog.Error(err, "unable to add GrafanaPolicySync controller to manager")
182+
span.End()
183+
os.Exit(1)
184+
}
185+
178186
kvSyncController, err := azurekeyvaultsync.NewReconciler(
179187
ctx,
180188
rt,
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
2+
[TestReconciler_SyncAll_AppendsManagedRouteAndPreservesUnrelated - 1]
3+
{
4+
"receiver": "grafana-default-email",
5+
"routes": [
6+
{
7+
"object_matchers": [
8+
[
9+
"Type",
10+
"=",
11+
"Unrelated"
12+
]
13+
],
14+
"receiver": "team-a"
15+
},
16+
{
17+
"object_matchers": [
18+
[
19+
"Type",
20+
"=",
21+
"Altinn"
22+
]
23+
],
24+
"receiver": "altinn-studio-gateway",
25+
"repeat_interval": "5m"
26+
}
27+
]
28+
}
29+
---
30+
31+
[TestReconciler_SyncAll_PreservesUnknownFieldsOnRoundTrip - 1]
32+
{
33+
"group_by": [
34+
"grafana_folder",
35+
"alertname"
36+
],
37+
"receiver": "grafana-default-email",
38+
"routes": [
39+
{
40+
"continue": true,
41+
"object_matchers": [
42+
[
43+
"Type",
44+
"=",
45+
"Unrelated"
46+
]
47+
],
48+
"receiver": "team-a"
49+
},
50+
{
51+
"object_matchers": [
52+
[
53+
"Type",
54+
"=",
55+
"Altinn"
56+
]
57+
],
58+
"receiver": "altinn-studio-gateway",
59+
"repeat_interval": "5m"
60+
}
61+
]
62+
}
63+
---
64+
65+
[TestReconciler_SyncAll_UpdatesManagedRoute - 1]
66+
{
67+
"receiver": "grafana-default-email",
68+
"routes": [
69+
{
70+
"object_matchers": [
71+
[
72+
"Type",
73+
"=",
74+
"Altinn"
75+
]
76+
],
77+
"receiver": "altinn-studio-gateway",
78+
"repeat_interval": "5m"
79+
}
80+
]
81+
}
82+
---
83+
84+
[TestReconciler_SyncAll_DoesNotOverwriteUnmanagedAltinnMatcherRoute - 1]
85+
{
86+
"receiver": "grafana-default-email",
87+
"routes": [
88+
{
89+
"object_matchers": [
90+
[
91+
"Type",
92+
"=",
93+
"Altinn"
94+
]
95+
],
96+
"receiver": "team-a",
97+
"repeat_interval": "10m"
98+
},
99+
{
100+
"object_matchers": [
101+
[
102+
"Type",
103+
"=",
104+
"Altinn"
105+
]
106+
],
107+
"receiver": "altinn-studio-gateway",
108+
"repeat_interval": "5m"
109+
}
110+
]
111+
}
112+
---
113+
114+
[TestReconciler_SyncAll_RemovesDuplicateManagedRoutes - 1]
115+
{
116+
"receiver": "grafana-default-email",
117+
"routes": [
118+
{
119+
"object_matchers": [
120+
[
121+
"Type",
122+
"=",
123+
"Altinn"
124+
]
125+
],
126+
"receiver": "altinn-studio-gateway",
127+
"repeat_interval": "5m"
128+
}
129+
]
130+
}
131+
---
132+
133+
[TestReconciler_SyncAll_AppendsManagedRouteWhenRoutesMissing - 1]
134+
{
135+
"receiver": "grafana-default-email",
136+
"routes": [
137+
{
138+
"object_matchers": [
139+
[
140+
"Type",
141+
"=",
142+
"Altinn"
143+
]
144+
],
145+
"receiver": "altinn-studio-gateway",
146+
"repeat_interval": "5m"
147+
}
148+
]
149+
}
150+
---
151+
152+
[TestReconciler_SyncAll_OverwritesSameReceiverWithOtherMatcher - 1]
153+
{
154+
"receiver": "grafana-default-email",
155+
"routes": [
156+
{
157+
"object_matchers": [
158+
[
159+
"Type",
160+
"=",
161+
"Altinn"
162+
]
163+
],
164+
"receiver": "altinn-studio-gateway",
165+
"repeat_interval": "5m"
166+
}
167+
]
168+
}
169+
---

0 commit comments

Comments
 (0)