Skip to content

Commit 5521342

Browse files
committed
fix: Make all fields present on root route, but invalidate them CEL rules
1 parent e80f328 commit 5521342

File tree

5 files changed

+225
-112
lines changed

5 files changed

+225
-112
lines changed

api/v1beta1/grafananotificationpolicy_types.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type GrafanaNotificationPolicySpec struct {
2929
GrafanaCommonSpec `json:",inline"`
3030

3131
// Routes for alerts to match against
32-
Route *PartialRoute `json:"route"`
32+
Route *RootRoute `json:"route"`
3333

3434
// Whether to enable or disable editing of the notification policy in Grafana UI
3535
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
@@ -67,6 +67,34 @@ type PartialRoute struct {
6767
Provenance models.Provenance `json:"provenance,omitempty"`
6868
}
6969

70+
// +kubebuilder:validation:XValidation:rule="!has(self.continue)", message="continue is invalid on the top level route node"
71+
// +kubebuilder:validation:XValidation:rule="!has(self.match_re)", message="match_re is invalid on the top level route node"
72+
// +kubebuilder:validation:XValidation:rule="!has(self.matchers)", message="matchers is invalid on the top level route node"
73+
// +kubebuilder:validation:XValidation:rule="!has(self.object_matchers)", message="object_matchers is invalid on the top level route node"
74+
// +kubebuilder:validation:XValidation:rule="!has(self.mute_time_intervals)", message="mute_time_intervals is invalid on the top level route node"
75+
// +kubebuilder:validation:XValidation:rule="!has(self.active_time_intervals)", message="active_time_intervals is invalid on the top level route node"
76+
type RootRoute struct {
77+
PartialRoute `json:",inline"`
78+
79+
// Deprecated: Never worked on the top level route node
80+
Continue bool `json:"continue,omitempty"`
81+
82+
// Deprecated: Never worked on the top level route node
83+
MatchRe models.MatchRegexps `json:"match_re,omitempty"`
84+
85+
// Deprecated: Never worked on the top level route node
86+
Matchers Matchers `json:"matchers,omitempty"`
87+
88+
// Deprecated: Never worked on the top level route node
89+
ObjectMatchers models.ObjectMatchers `json:"object_matchers,omitempty"`
90+
91+
// Deprecated: Never worked on the top level route node
92+
MuteTimeIntervals []string `json:"mute_time_intervals,omitempty"`
93+
94+
// Deprecated: Never worked on the top level route node
95+
ActiveTimeIntervals []string `json:"active_time_intervals,omitempty"`
96+
}
97+
7098
type Route struct {
7199
PartialRoute `json:",inline"`
72100

@@ -140,7 +168,7 @@ func (r *Route) ToModelRoute() *models.Route {
140168
return out
141169
}
142170

143-
func (r *PartialRoute) ToModelRoute() *models.Route {
171+
func (r *RootRoute) ToModelRoute() *models.Route {
144172
out := &models.Route{
145173
GroupBy: r.GroupBy,
146174
GroupInterval: r.GroupInterval,

api/v1beta1/grafananotificationpolicy_types_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ func newNotificationPolicy(name string, editable *bool) *GrafanaNotificationPoli
3939
},
4040
},
4141
},
42-
Route: &PartialRoute{
43-
Receiver: "grafana-default-email",
44-
GroupBy: []string{"group_name", "alert_name"},
45-
Routes: []*Route{},
42+
Route: &RootRoute{
43+
PartialRoute: PartialRoute{
44+
Receiver: "grafana-default-email",
45+
GroupBy: []string{"group_name", "alert_name"},
46+
Routes: []*Route{},
47+
},
4648
},
4749
},
4850
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 56 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/notificationpolicy_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func assembleNotificationPolicyRoutes(ctx context.Context, k8sClient client.Clie
259259
}
260260

261261
// Start with Spec.Route
262-
if err := assembleRoute(cr.Spec.Route); err != nil {
262+
if err := assembleRoute(&cr.Spec.Route.PartialRoute); err != nil {
263263
return nil, err
264264
}
265265

0 commit comments

Comments
 (0)