Alerting: Notifications Routes API (#91550)

* Introduce new models RoutingTree, RouteDefaults and Route and api-server to serve them that is backed by provisioning notification policy service.

* update method UpdatePolicyTree of notification policy service to return route and new version

* declare new actions alert.notifications.routes:read and alert.notifications.routes:write and two corresponding fixed roles.

---------

Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
Co-authored-by: Matthew Jacobson <matthew.jacobson@grafana.com>
This commit is contained in:
Yuri Tseretyan
2024-10-24 13:53:03 -04:00
committed by GitHub
co-authored by Tom Ratcliffe Matthew Jacobson
parent fb0221d561
commit 2deced7d40
41 changed files with 2809 additions and 54 deletions
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by applyconfiguration-gen. DO NOT EDIT.
package v0alpha1
import (
v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1"
)
// MatcherApplyConfiguration represents a declarative configuration of the Matcher type for use
// with apply.
type MatcherApplyConfiguration struct {
Label *string `json:"label,omitempty"`
Type *v0alpha1.MatcherType `json:"type,omitempty"`
Value *string `json:"value,omitempty"`
}
// MatcherApplyConfiguration constructs a declarative configuration of the Matcher type for use with
// apply.
func Matcher() *MatcherApplyConfiguration {
return &MatcherApplyConfiguration{}
}
// WithLabel sets the Label field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Label field is set to the value of the last call.
func (b *MatcherApplyConfiguration) WithLabel(value string) *MatcherApplyConfiguration {
b.Label = &value
return b
}
// WithType sets the Type field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Type field is set to the value of the last call.
func (b *MatcherApplyConfiguration) WithType(value v0alpha1.MatcherType) *MatcherApplyConfiguration {
b.Type = &value
return b
}
// WithValue sets the Value field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Value field is set to the value of the last call.
func (b *MatcherApplyConfiguration) WithValue(value string) *MatcherApplyConfiguration {
b.Value = &value
return b
}
@@ -0,0 +1,111 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by applyconfiguration-gen. DO NOT EDIT.
package v0alpha1
// RouteApplyConfiguration represents a declarative configuration of the Route type for use
// with apply.
type RouteApplyConfiguration struct {
Continue *bool `json:"continue,omitempty"`
GroupBy []string `json:"group_by,omitempty"`
GroupInterval *string `json:"group_interval,omitempty"`
GroupWait *string `json:"group_wait,omitempty"`
Matchers []MatcherApplyConfiguration `json:"matchers,omitempty"`
MuteTimeIntervals []string `json:"mute_time_intervals,omitempty"`
Receiver *string `json:"receiver,omitempty"`
RepeatInterval *string `json:"repeat_interval,omitempty"`
Routes []RouteApplyConfiguration `json:"routes,omitempty"`
}
// RouteApplyConfiguration constructs a declarative configuration of the Route type for use with
// apply.
func Route() *RouteApplyConfiguration {
return &RouteApplyConfiguration{}
}
// WithContinue sets the Continue field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Continue field is set to the value of the last call.
func (b *RouteApplyConfiguration) WithContinue(value bool) *RouteApplyConfiguration {
b.Continue = &value
return b
}
// WithGroupBy adds the given value to the GroupBy field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the GroupBy field.
func (b *RouteApplyConfiguration) WithGroupBy(values ...string) *RouteApplyConfiguration {
for i := range values {
b.GroupBy = append(b.GroupBy, values[i])
}
return b
}
// WithGroupInterval sets the GroupInterval field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the GroupInterval field is set to the value of the last call.
func (b *RouteApplyConfiguration) WithGroupInterval(value string) *RouteApplyConfiguration {
b.GroupInterval = &value
return b
}
// WithGroupWait sets the GroupWait field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the GroupWait field is set to the value of the last call.
func (b *RouteApplyConfiguration) WithGroupWait(value string) *RouteApplyConfiguration {
b.GroupWait = &value
return b
}
// WithMatchers adds the given value to the Matchers field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the Matchers field.
func (b *RouteApplyConfiguration) WithMatchers(values ...*MatcherApplyConfiguration) *RouteApplyConfiguration {
for i := range values {
if values[i] == nil {
panic("nil value passed to WithMatchers")
}
b.Matchers = append(b.Matchers, *values[i])
}
return b
}
// WithMuteTimeIntervals adds the given value to the MuteTimeIntervals field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the MuteTimeIntervals field.
func (b *RouteApplyConfiguration) WithMuteTimeIntervals(values ...string) *RouteApplyConfiguration {
for i := range values {
b.MuteTimeIntervals = append(b.MuteTimeIntervals, values[i])
}
return b
}
// WithReceiver sets the Receiver field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Receiver field is set to the value of the last call.
func (b *RouteApplyConfiguration) WithReceiver(value string) *RouteApplyConfiguration {
b.Receiver = &value
return b
}
// WithRepeatInterval sets the RepeatInterval field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the RepeatInterval field is set to the value of the last call.
func (b *RouteApplyConfiguration) WithRepeatInterval(value string) *RouteApplyConfiguration {
b.RepeatInterval = &value
return b
}
// WithRoutes adds the given value to the Routes field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the Routes field.
func (b *RouteApplyConfiguration) WithRoutes(values ...*RouteApplyConfiguration) *RouteApplyConfiguration {
for i := range values {
if values[i] == nil {
panic("nil value passed to WithRoutes")
}
b.Routes = append(b.Routes, *values[i])
}
return b
}
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by applyconfiguration-gen. DO NOT EDIT.
package v0alpha1
// RouteDefaultsApplyConfiguration represents a declarative configuration of the RouteDefaults type for use
// with apply.
type RouteDefaultsApplyConfiguration struct {
GroupBy []string `json:"group_by,omitempty"`
GroupInterval *string `json:"group_interval,omitempty"`
GroupWait *string `json:"group_wait,omitempty"`
Receiver *string `json:"receiver,omitempty"`
RepeatInterval *string `json:"repeat_interval,omitempty"`
}
// RouteDefaultsApplyConfiguration constructs a declarative configuration of the RouteDefaults type for use with
// apply.
func RouteDefaults() *RouteDefaultsApplyConfiguration {
return &RouteDefaultsApplyConfiguration{}
}
// WithGroupBy adds the given value to the GroupBy field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the GroupBy field.
func (b *RouteDefaultsApplyConfiguration) WithGroupBy(values ...string) *RouteDefaultsApplyConfiguration {
for i := range values {
b.GroupBy = append(b.GroupBy, values[i])
}
return b
}
// WithGroupInterval sets the GroupInterval field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the GroupInterval field is set to the value of the last call.
func (b *RouteDefaultsApplyConfiguration) WithGroupInterval(value string) *RouteDefaultsApplyConfiguration {
b.GroupInterval = &value
return b
}
// WithGroupWait sets the GroupWait field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the GroupWait field is set to the value of the last call.
func (b *RouteDefaultsApplyConfiguration) WithGroupWait(value string) *RouteDefaultsApplyConfiguration {
b.GroupWait = &value
return b
}
// WithReceiver sets the Receiver field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Receiver field is set to the value of the last call.
func (b *RouteDefaultsApplyConfiguration) WithReceiver(value string) *RouteDefaultsApplyConfiguration {
b.Receiver = &value
return b
}
// WithRepeatInterval sets the RepeatInterval field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the RepeatInterval field is set to the value of the last call.
func (b *RouteDefaultsApplyConfiguration) WithRepeatInterval(value string) *RouteDefaultsApplyConfiguration {
b.RepeatInterval = &value
return b
}
@@ -0,0 +1,202 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by applyconfiguration-gen. DO NOT EDIT.
package v0alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
v1 "k8s.io/client-go/applyconfigurations/meta/v1"
)
// RoutingTreeApplyConfiguration represents a declarative configuration of the RoutingTree type for use
// with apply.
type RoutingTreeApplyConfiguration struct {
v1.TypeMetaApplyConfiguration `json:",inline"`
*v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"`
Spec *RoutingTreeSpecApplyConfiguration `json:"spec,omitempty"`
}
// RoutingTree constructs a declarative configuration of the RoutingTree type for use with
// apply.
func RoutingTree(name, namespace string) *RoutingTreeApplyConfiguration {
b := &RoutingTreeApplyConfiguration{}
b.WithName(name)
b.WithNamespace(namespace)
b.WithKind("RoutingTree")
b.WithAPIVersion("notifications.alerting.grafana.app/v0alpha1")
return b
}
// WithKind sets the Kind field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Kind field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithKind(value string) *RoutingTreeApplyConfiguration {
b.Kind = &value
return b
}
// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the APIVersion field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithAPIVersion(value string) *RoutingTreeApplyConfiguration {
b.APIVersion = &value
return b
}
// WithName sets the Name field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Name field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithName(value string) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.Name = &value
return b
}
// WithGenerateName sets the GenerateName field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the GenerateName field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithGenerateName(value string) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.GenerateName = &value
return b
}
// WithNamespace sets the Namespace field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Namespace field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithNamespace(value string) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.Namespace = &value
return b
}
// WithUID sets the UID field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the UID field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithUID(value types.UID) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.UID = &value
return b
}
// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the ResourceVersion field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithResourceVersion(value string) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.ResourceVersion = &value
return b
}
// WithGeneration sets the Generation field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Generation field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithGeneration(value int64) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.Generation = &value
return b
}
// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the CreationTimestamp field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.CreationTimestamp = &value
return b
}
// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the DeletionTimestamp field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.DeletionTimestamp = &value
return b
}
// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
b.DeletionGracePeriodSeconds = &value
return b
}
// WithLabels puts the entries into the Labels field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, the entries provided by each call will be put on the Labels field,
// overwriting an existing map entries in Labels field with the same key.
func (b *RoutingTreeApplyConfiguration) WithLabels(entries map[string]string) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
if b.Labels == nil && len(entries) > 0 {
b.Labels = make(map[string]string, len(entries))
}
for k, v := range entries {
b.Labels[k] = v
}
return b
}
// WithAnnotations puts the entries into the Annotations field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, the entries provided by each call will be put on the Annotations field,
// overwriting an existing map entries in Annotations field with the same key.
func (b *RoutingTreeApplyConfiguration) WithAnnotations(entries map[string]string) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
if b.Annotations == nil && len(entries) > 0 {
b.Annotations = make(map[string]string, len(entries))
}
for k, v := range entries {
b.Annotations[k] = v
}
return b
}
// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the OwnerReferences field.
func (b *RoutingTreeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
for i := range values {
if values[i] == nil {
panic("nil value passed to WithOwnerReferences")
}
b.OwnerReferences = append(b.OwnerReferences, *values[i])
}
return b
}
// WithFinalizers adds the given value to the Finalizers field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the Finalizers field.
func (b *RoutingTreeApplyConfiguration) WithFinalizers(values ...string) *RoutingTreeApplyConfiguration {
b.ensureObjectMetaApplyConfigurationExists()
for i := range values {
b.Finalizers = append(b.Finalizers, values[i])
}
return b
}
func (b *RoutingTreeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() {
if b.ObjectMetaApplyConfiguration == nil {
b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{}
}
}
// WithSpec sets the Spec field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Spec field is set to the value of the last call.
func (b *RoutingTreeApplyConfiguration) WithSpec(value *RoutingTreeSpecApplyConfiguration) *RoutingTreeApplyConfiguration {
b.Spec = value
return b
}
// GetName retrieves the value of the Name field in the declarative configuration.
func (b *RoutingTreeApplyConfiguration) GetName() *string {
b.ensureObjectMetaApplyConfigurationExists()
return b.Name
}
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by applyconfiguration-gen. DO NOT EDIT.
package v0alpha1
// RoutingTreeSpecApplyConfiguration represents a declarative configuration of the RoutingTreeSpec type for use
// with apply.
type RoutingTreeSpecApplyConfiguration struct {
Defaults *RouteDefaultsApplyConfiguration `json:"defaults,omitempty"`
Routes []RouteApplyConfiguration `json:"routes,omitempty"`
}
// RoutingTreeSpecApplyConfiguration constructs a declarative configuration of the RoutingTreeSpec type for use with
// apply.
func RoutingTreeSpec() *RoutingTreeSpecApplyConfiguration {
return &RoutingTreeSpecApplyConfiguration{}
}
// WithDefaults sets the Defaults field in the declarative configuration to the given value
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
// If called multiple times, the Defaults field is set to the value of the last call.
func (b *RoutingTreeSpecApplyConfiguration) WithDefaults(value *RouteDefaultsApplyConfiguration) *RoutingTreeSpecApplyConfiguration {
b.Defaults = value
return b
}
// WithRoutes adds the given value to the Routes field in the declarative configuration
// and returns the receiver, so that objects can be build by chaining "With" function invocations.
// If called multiple times, values provided by each call will be appended to the Routes field.
func (b *RoutingTreeSpecApplyConfiguration) WithRoutes(values ...*RouteApplyConfiguration) *RoutingTreeSpecApplyConfiguration {
for i := range values {
if values[i] == nil {
panic("nil value passed to WithRoutes")
}
b.Routes = append(b.Routes, *values[i])
}
return b
}
+10
View File
@@ -24,10 +24,20 @@ func ForKind(kind schema.GroupVersionKind) interface{} {
return &alertingnotificationsv0alpha1.IntegrationApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("Interval"):
return &alertingnotificationsv0alpha1.IntervalApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("Matcher"):
return &alertingnotificationsv0alpha1.MatcherApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("Receiver"):
return &alertingnotificationsv0alpha1.ReceiverApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("ReceiverSpec"):
return &alertingnotificationsv0alpha1.ReceiverSpecApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("Route"):
return &alertingnotificationsv0alpha1.RouteApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("RouteDefaults"):
return &alertingnotificationsv0alpha1.RouteDefaultsApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("RoutingTree"):
return &alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("RoutingTreeSpec"):
return &alertingnotificationsv0alpha1.RoutingTreeSpecApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("TemplateGroup"):
return &alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration{}
case v0alpha1.SchemeGroupVersion.WithKind("TemplateGroupSpec"):