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
+5
@@ -15,6 +15,7 @@ import (
|
||||
type NotificationsV0alpha1Interface interface {
|
||||
RESTClient() rest.Interface
|
||||
ReceiversGetter
|
||||
RoutingTreesGetter
|
||||
TemplateGroupsGetter
|
||||
TimeIntervalsGetter
|
||||
}
|
||||
@@ -28,6 +29,10 @@ func (c *NotificationsV0alpha1Client) Receivers(namespace string) ReceiverInterf
|
||||
return newReceivers(c, namespace)
|
||||
}
|
||||
|
||||
func (c *NotificationsV0alpha1Client) RoutingTrees(namespace string) RoutingTreeInterface {
|
||||
return newRoutingTrees(c, namespace)
|
||||
}
|
||||
|
||||
func (c *NotificationsV0alpha1Client) TemplateGroups(namespace string) TemplateGroupInterface {
|
||||
return newTemplateGroups(c, namespace)
|
||||
}
|
||||
|
||||
+4
@@ -18,6 +18,10 @@ func (c *FakeNotificationsV0alpha1) Receivers(namespace string) v0alpha1.Receive
|
||||
return &FakeReceivers{c, namespace}
|
||||
}
|
||||
|
||||
func (c *FakeNotificationsV0alpha1) RoutingTrees(namespace string) v0alpha1.RoutingTreeInterface {
|
||||
return &FakeRoutingTrees{c, namespace}
|
||||
}
|
||||
|
||||
func (c *FakeNotificationsV0alpha1) TemplateGroups(namespace string) v0alpha1.TemplateGroupInterface {
|
||||
return &FakeTemplateGroups{c, namespace}
|
||||
}
|
||||
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package fake
|
||||
|
||||
import (
|
||||
"context"
|
||||
json "encoding/json"
|
||||
"fmt"
|
||||
|
||||
v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1"
|
||||
alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
labels "k8s.io/apimachinery/pkg/labels"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
testing "k8s.io/client-go/testing"
|
||||
)
|
||||
|
||||
// FakeRoutingTrees implements RoutingTreeInterface
|
||||
type FakeRoutingTrees struct {
|
||||
Fake *FakeNotificationsV0alpha1
|
||||
ns string
|
||||
}
|
||||
|
||||
var routingtreesResource = v0alpha1.SchemeGroupVersion.WithResource("routingtrees")
|
||||
|
||||
var routingtreesKind = v0alpha1.SchemeGroupVersion.WithKind("RoutingTree")
|
||||
|
||||
// Get takes name of the routingTree, and returns the corresponding routingTree object, and an error if there is any.
|
||||
func (c *FakeRoutingTrees) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.RoutingTree, err error) {
|
||||
emptyResult := &v0alpha1.RoutingTree{}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewGetActionWithOptions(routingtreesResource, c.ns, name, options), emptyResult)
|
||||
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(*v0alpha1.RoutingTree), err
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of RoutingTrees that match those selectors.
|
||||
func (c *FakeRoutingTrees) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.RoutingTreeList, err error) {
|
||||
emptyResult := &v0alpha1.RoutingTreeList{}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewListActionWithOptions(routingtreesResource, routingtreesKind, c.ns, opts), emptyResult)
|
||||
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
|
||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
||||
if label == nil {
|
||||
label = labels.Everything()
|
||||
}
|
||||
list := &v0alpha1.RoutingTreeList{ListMeta: obj.(*v0alpha1.RoutingTreeList).ListMeta}
|
||||
for _, item := range obj.(*v0alpha1.RoutingTreeList).Items {
|
||||
if label.Matches(labels.Set(item.Labels)) {
|
||||
list.Items = append(list.Items, item)
|
||||
}
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested routingTrees.
|
||||
func (c *FakeRoutingTrees) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
||||
return c.Fake.
|
||||
InvokesWatch(testing.NewWatchActionWithOptions(routingtreesResource, c.ns, opts))
|
||||
|
||||
}
|
||||
|
||||
// Create takes the representation of a routingTree and creates it. Returns the server's representation of the routingTree, and an error, if there is any.
|
||||
func (c *FakeRoutingTrees) Create(ctx context.Context, routingTree *v0alpha1.RoutingTree, opts v1.CreateOptions) (result *v0alpha1.RoutingTree, err error) {
|
||||
emptyResult := &v0alpha1.RoutingTree{}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewCreateActionWithOptions(routingtreesResource, c.ns, routingTree, opts), emptyResult)
|
||||
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(*v0alpha1.RoutingTree), err
|
||||
}
|
||||
|
||||
// Update takes the representation of a routingTree and updates it. Returns the server's representation of the routingTree, and an error, if there is any.
|
||||
func (c *FakeRoutingTrees) Update(ctx context.Context, routingTree *v0alpha1.RoutingTree, opts v1.UpdateOptions) (result *v0alpha1.RoutingTree, err error) {
|
||||
emptyResult := &v0alpha1.RoutingTree{}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateActionWithOptions(routingtreesResource, c.ns, routingTree, opts), emptyResult)
|
||||
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(*v0alpha1.RoutingTree), err
|
||||
}
|
||||
|
||||
// Delete takes name of the routingTree and deletes it. Returns an error if one occurs.
|
||||
func (c *FakeRoutingTrees) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
||||
_, err := c.Fake.
|
||||
Invokes(testing.NewDeleteActionWithOptions(routingtreesResource, c.ns, name, opts), &v0alpha1.RoutingTree{})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *FakeRoutingTrees) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
||||
action := testing.NewDeleteCollectionActionWithOptions(routingtreesResource, c.ns, opts, listOpts)
|
||||
|
||||
_, err := c.Fake.Invokes(action, &v0alpha1.RoutingTreeList{})
|
||||
return err
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched routingTree.
|
||||
func (c *FakeRoutingTrees) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.RoutingTree, err error) {
|
||||
emptyResult := &v0alpha1.RoutingTree{}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceActionWithOptions(routingtreesResource, c.ns, name, pt, data, opts, subresources...), emptyResult)
|
||||
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(*v0alpha1.RoutingTree), err
|
||||
}
|
||||
|
||||
// Apply takes the given apply declarative configuration, applies it and returns the applied routingTree.
|
||||
func (c *FakeRoutingTrees) Apply(ctx context.Context, routingTree *alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.RoutingTree, err error) {
|
||||
if routingTree == nil {
|
||||
return nil, fmt.Errorf("routingTree provided to Apply must not be nil")
|
||||
}
|
||||
data, err := json.Marshal(routingTree)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name := routingTree.Name
|
||||
if name == nil {
|
||||
return nil, fmt.Errorf("routingTree.Name must be provided to Apply")
|
||||
}
|
||||
emptyResult := &v0alpha1.RoutingTree{}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceActionWithOptions(routingtreesResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult)
|
||||
|
||||
if obj == nil {
|
||||
return emptyResult, err
|
||||
}
|
||||
return obj.(*v0alpha1.RoutingTree), err
|
||||
}
|
||||
+2
@@ -6,6 +6,8 @@ package v0alpha1
|
||||
|
||||
type ReceiverExpansion interface{}
|
||||
|
||||
type RoutingTreeExpansion interface{}
|
||||
|
||||
type TemplateGroupExpansion interface{}
|
||||
|
||||
type TimeIntervalExpansion interface{}
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package v0alpha1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1"
|
||||
alertingnotificationsv0alpha1 "github.com/grafana/grafana/pkg/generated/applyconfiguration/alerting_notifications/v0alpha1"
|
||||
scheme "github.com/grafana/grafana/pkg/generated/clientset/versioned/scheme"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
types "k8s.io/apimachinery/pkg/types"
|
||||
watch "k8s.io/apimachinery/pkg/watch"
|
||||
gentype "k8s.io/client-go/gentype"
|
||||
)
|
||||
|
||||
// RoutingTreesGetter has a method to return a RoutingTreeInterface.
|
||||
// A group's client should implement this interface.
|
||||
type RoutingTreesGetter interface {
|
||||
RoutingTrees(namespace string) RoutingTreeInterface
|
||||
}
|
||||
|
||||
// RoutingTreeInterface has methods to work with RoutingTree resources.
|
||||
type RoutingTreeInterface interface {
|
||||
Create(ctx context.Context, routingTree *v0alpha1.RoutingTree, opts v1.CreateOptions) (*v0alpha1.RoutingTree, error)
|
||||
Update(ctx context.Context, routingTree *v0alpha1.RoutingTree, opts v1.UpdateOptions) (*v0alpha1.RoutingTree, error)
|
||||
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
|
||||
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
|
||||
Get(ctx context.Context, name string, opts v1.GetOptions) (*v0alpha1.RoutingTree, error)
|
||||
List(ctx context.Context, opts v1.ListOptions) (*v0alpha1.RoutingTreeList, error)
|
||||
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
|
||||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.RoutingTree, err error)
|
||||
Apply(ctx context.Context, routingTree *alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.RoutingTree, err error)
|
||||
RoutingTreeExpansion
|
||||
}
|
||||
|
||||
// routingTrees implements RoutingTreeInterface
|
||||
type routingTrees struct {
|
||||
*gentype.ClientWithListAndApply[*v0alpha1.RoutingTree, *v0alpha1.RoutingTreeList, *alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration]
|
||||
}
|
||||
|
||||
// newRoutingTrees returns a RoutingTrees
|
||||
func newRoutingTrees(c *NotificationsV0alpha1Client, namespace string) *routingTrees {
|
||||
return &routingTrees{
|
||||
gentype.NewClientWithListAndApply[*v0alpha1.RoutingTree, *v0alpha1.RoutingTreeList, *alertingnotificationsv0alpha1.RoutingTreeApplyConfiguration](
|
||||
"routingtrees",
|
||||
c.RESTClient(),
|
||||
scheme.ParameterCodec,
|
||||
namespace,
|
||||
func() *v0alpha1.RoutingTree { return &v0alpha1.RoutingTree{} },
|
||||
func() *v0alpha1.RoutingTreeList { return &v0alpha1.RoutingTreeList{} }),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user