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:
co-authored by
Tom Ratcliffe
Matthew Jacobson
parent
fb0221d561
commit
2deced7d40
@@ -12,6 +12,8 @@ import (
|
||||
type Interface interface {
|
||||
// Receivers returns a ReceiverInformer.
|
||||
Receivers() ReceiverInformer
|
||||
// RoutingTrees returns a RoutingTreeInformer.
|
||||
RoutingTrees() RoutingTreeInformer
|
||||
// TemplateGroups returns a TemplateGroupInformer.
|
||||
TemplateGroups() TemplateGroupInformer
|
||||
// TimeIntervals returns a TimeIntervalInformer.
|
||||
@@ -34,6 +36,11 @@ func (v *version) Receivers() ReceiverInformer {
|
||||
return &receiverInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
||||
}
|
||||
|
||||
// RoutingTrees returns a RoutingTreeInformer.
|
||||
func (v *version) RoutingTrees() RoutingTreeInformer {
|
||||
return &routingTreeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
||||
}
|
||||
|
||||
// TemplateGroups returns a TemplateGroupInformer.
|
||||
func (v *version) TemplateGroups() TemplateGroupInformer {
|
||||
return &templateGroupInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
// Code generated by informer-gen. DO NOT EDIT.
|
||||
|
||||
package v0alpha1
|
||||
|
||||
import (
|
||||
"context"
|
||||
time "time"
|
||||
|
||||
alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1"
|
||||
versioned "github.com/grafana/grafana/pkg/generated/clientset/versioned"
|
||||
internalinterfaces "github.com/grafana/grafana/pkg/generated/informers/externalversions/internalinterfaces"
|
||||
v0alpha1 "github.com/grafana/grafana/pkg/generated/listers/alerting_notifications/v0alpha1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
cache "k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
// RoutingTreeInformer provides access to a shared informer and lister for
|
||||
// RoutingTrees.
|
||||
type RoutingTreeInformer interface {
|
||||
Informer() cache.SharedIndexInformer
|
||||
Lister() v0alpha1.RoutingTreeLister
|
||||
}
|
||||
|
||||
type routingTreeInformer struct {
|
||||
factory internalinterfaces.SharedInformerFactory
|
||||
tweakListOptions internalinterfaces.TweakListOptionsFunc
|
||||
namespace string
|
||||
}
|
||||
|
||||
// NewRoutingTreeInformer constructs a new informer for RoutingTree type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewRoutingTreeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
|
||||
return NewFilteredRoutingTreeInformer(client, namespace, resyncPeriod, indexers, nil)
|
||||
}
|
||||
|
||||
// NewFilteredRoutingTreeInformer constructs a new informer for RoutingTree type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewFilteredRoutingTreeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
|
||||
return cache.NewSharedIndexInformer(
|
||||
&cache.ListWatch{
|
||||
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.NotificationsV0alpha1().RoutingTrees(namespace).List(context.TODO(), options)
|
||||
},
|
||||
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.NotificationsV0alpha1().RoutingTrees(namespace).Watch(context.TODO(), options)
|
||||
},
|
||||
},
|
||||
&alertingnotificationsv0alpha1.RoutingTree{},
|
||||
resyncPeriod,
|
||||
indexers,
|
||||
)
|
||||
}
|
||||
|
||||
func (f *routingTreeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
|
||||
return NewFilteredRoutingTreeInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
|
||||
}
|
||||
|
||||
func (f *routingTreeInformer) Informer() cache.SharedIndexInformer {
|
||||
return f.factory.InformerFor(&alertingnotificationsv0alpha1.RoutingTree{}, f.defaultInformer)
|
||||
}
|
||||
|
||||
func (f *routingTreeInformer) Lister() v0alpha1.RoutingTreeLister {
|
||||
return v0alpha1.NewRoutingTreeLister(f.Informer().GetIndexer())
|
||||
}
|
||||
@@ -42,6 +42,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource
|
||||
// Group=notifications.alerting.grafana.app, Version=v0alpha1
|
||||
case v0alpha1.SchemeGroupVersion.WithResource("receivers"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Notifications().V0alpha1().Receivers().Informer()}, nil
|
||||
case v0alpha1.SchemeGroupVersion.WithResource("routingtrees"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Notifications().V0alpha1().RoutingTrees().Informer()}, nil
|
||||
case v0alpha1.SchemeGroupVersion.WithResource("templategroups"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.Notifications().V0alpha1().TemplateGroups().Informer()}, nil
|
||||
case v0alpha1.SchemeGroupVersion.WithResource("timeintervals"):
|
||||
|
||||
Reference in New Issue
Block a user