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"):
@@ -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)
}
@@ -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}
}
@@ -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
}
@@ -6,6 +6,8 @@ package v0alpha1
type ReceiverExpansion interface{}
type RoutingTreeExpansion interface{}
type TemplateGroupExpansion interface{}
type TimeIntervalExpansion interface{}
@@ -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{} }),
}
}
@@ -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}
@@ -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"):
@@ -12,6 +12,14 @@ type ReceiverListerExpansion interface{}
// ReceiverNamespaceLister.
type ReceiverNamespaceListerExpansion interface{}
// RoutingTreeListerExpansion allows custom methods to be added to
// RoutingTreeLister.
type RoutingTreeListerExpansion interface{}
// RoutingTreeNamespaceListerExpansion allows custom methods to be added to
// RoutingTreeNamespaceLister.
type RoutingTreeNamespaceListerExpansion interface{}
// TemplateGroupListerExpansion allows custom methods to be added to
// TemplateGroupLister.
type TemplateGroupListerExpansion interface{}
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Code generated by lister-gen. DO NOT EDIT.
package v0alpha1
import (
v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/listers"
"k8s.io/client-go/tools/cache"
)
// RoutingTreeLister helps list RoutingTrees.
// All objects returned here must be treated as read-only.
type RoutingTreeLister interface {
// List lists all RoutingTrees in the indexer.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v0alpha1.RoutingTree, err error)
// RoutingTrees returns an object that can list and get RoutingTrees.
RoutingTrees(namespace string) RoutingTreeNamespaceLister
RoutingTreeListerExpansion
}
// routingTreeLister implements the RoutingTreeLister interface.
type routingTreeLister struct {
listers.ResourceIndexer[*v0alpha1.RoutingTree]
}
// NewRoutingTreeLister returns a new RoutingTreeLister.
func NewRoutingTreeLister(indexer cache.Indexer) RoutingTreeLister {
return &routingTreeLister{listers.New[*v0alpha1.RoutingTree](indexer, v0alpha1.Resource("routingtree"))}
}
// RoutingTrees returns an object that can list and get RoutingTrees.
func (s *routingTreeLister) RoutingTrees(namespace string) RoutingTreeNamespaceLister {
return routingTreeNamespaceLister{listers.NewNamespaced[*v0alpha1.RoutingTree](s.ResourceIndexer, namespace)}
}
// RoutingTreeNamespaceLister helps list and get RoutingTrees.
// All objects returned here must be treated as read-only.
type RoutingTreeNamespaceLister interface {
// List lists all RoutingTrees in the indexer for a given namespace.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v0alpha1.RoutingTree, err error)
// Get retrieves the RoutingTree from the indexer for a given namespace and name.
// Objects returned here must be treated as read-only.
Get(name string) (*v0alpha1.RoutingTree, error)
RoutingTreeNamespaceListerExpansion
}
// routingTreeNamespaceLister implements the RoutingTreeNamespaceLister
// interface.
type routingTreeNamespaceLister struct {
listers.ResourceIndexer[*v0alpha1.RoutingTree]
}