Alerting: Notifications Templates API (#91349)

This commit is contained in:
Yuri Tseretyan
2024-09-25 09:31:57 -04:00
committed by GitHub
parent 5472478ee8
commit 10582e48f7
28 changed files with 2046 additions and 16 deletions
@@ -15,6 +15,7 @@ import (
type NotificationsV0alpha1Interface interface {
RESTClient() rest.Interface
ReceiversGetter
TemplateGroupsGetter
TimeIntervalsGetter
}
@@ -27,6 +28,10 @@ func (c *NotificationsV0alpha1Client) Receivers(namespace string) ReceiverInterf
return newReceivers(c, namespace)
}
func (c *NotificationsV0alpha1Client) TemplateGroups(namespace string) TemplateGroupInterface {
return newTemplateGroups(c, namespace)
}
func (c *NotificationsV0alpha1Client) TimeIntervals(namespace string) TimeIntervalInterface {
return newTimeIntervals(c, namespace)
}
@@ -18,6 +18,10 @@ func (c *FakeNotificationsV0alpha1) Receivers(namespace string) v0alpha1.Receive
return &FakeReceivers{c, namespace}
}
func (c *FakeNotificationsV0alpha1) TemplateGroups(namespace string) v0alpha1.TemplateGroupInterface {
return &FakeTemplateGroups{c, namespace}
}
func (c *FakeNotificationsV0alpha1) TimeIntervals(namespace string) v0alpha1.TimeIntervalInterface {
return &FakeTimeIntervals{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"
)
// FakeTemplateGroups implements TemplateGroupInterface
type FakeTemplateGroups struct {
Fake *FakeNotificationsV0alpha1
ns string
}
var templategroupsResource = v0alpha1.SchemeGroupVersion.WithResource("templategroups")
var templategroupsKind = v0alpha1.SchemeGroupVersion.WithKind("TemplateGroup")
// Get takes name of the templateGroup, and returns the corresponding templateGroup object, and an error if there is any.
func (c *FakeTemplateGroups) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.TemplateGroup, err error) {
emptyResult := &v0alpha1.TemplateGroup{}
obj, err := c.Fake.
Invokes(testing.NewGetActionWithOptions(templategroupsResource, c.ns, name, options), emptyResult)
if obj == nil {
return emptyResult, err
}
return obj.(*v0alpha1.TemplateGroup), err
}
// List takes label and field selectors, and returns the list of TemplateGroups that match those selectors.
func (c *FakeTemplateGroups) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.TemplateGroupList, err error) {
emptyResult := &v0alpha1.TemplateGroupList{}
obj, err := c.Fake.
Invokes(testing.NewListActionWithOptions(templategroupsResource, templategroupsKind, c.ns, opts), emptyResult)
if obj == nil {
return emptyResult, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v0alpha1.TemplateGroupList{ListMeta: obj.(*v0alpha1.TemplateGroupList).ListMeta}
for _, item := range obj.(*v0alpha1.TemplateGroupList).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 templateGroups.
func (c *FakeTemplateGroups) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchActionWithOptions(templategroupsResource, c.ns, opts))
}
// Create takes the representation of a templateGroup and creates it. Returns the server's representation of the templateGroup, and an error, if there is any.
func (c *FakeTemplateGroups) Create(ctx context.Context, templateGroup *v0alpha1.TemplateGroup, opts v1.CreateOptions) (result *v0alpha1.TemplateGroup, err error) {
emptyResult := &v0alpha1.TemplateGroup{}
obj, err := c.Fake.
Invokes(testing.NewCreateActionWithOptions(templategroupsResource, c.ns, templateGroup, opts), emptyResult)
if obj == nil {
return emptyResult, err
}
return obj.(*v0alpha1.TemplateGroup), err
}
// Update takes the representation of a templateGroup and updates it. Returns the server's representation of the templateGroup, and an error, if there is any.
func (c *FakeTemplateGroups) Update(ctx context.Context, templateGroup *v0alpha1.TemplateGroup, opts v1.UpdateOptions) (result *v0alpha1.TemplateGroup, err error) {
emptyResult := &v0alpha1.TemplateGroup{}
obj, err := c.Fake.
Invokes(testing.NewUpdateActionWithOptions(templategroupsResource, c.ns, templateGroup, opts), emptyResult)
if obj == nil {
return emptyResult, err
}
return obj.(*v0alpha1.TemplateGroup), err
}
// Delete takes name of the templateGroup and deletes it. Returns an error if one occurs.
func (c *FakeTemplateGroups) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteActionWithOptions(templategroupsResource, c.ns, name, opts), &v0alpha1.TemplateGroup{})
return err
}
// DeleteCollection deletes a collection of objects.
func (c *FakeTemplateGroups) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
action := testing.NewDeleteCollectionActionWithOptions(templategroupsResource, c.ns, opts, listOpts)
_, err := c.Fake.Invokes(action, &v0alpha1.TemplateGroupList{})
return err
}
// Patch applies the patch and returns the patched templateGroup.
func (c *FakeTemplateGroups) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.TemplateGroup, err error) {
emptyResult := &v0alpha1.TemplateGroup{}
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceActionWithOptions(templategroupsResource, c.ns, name, pt, data, opts, subresources...), emptyResult)
if obj == nil {
return emptyResult, err
}
return obj.(*v0alpha1.TemplateGroup), err
}
// Apply takes the given apply declarative configuration, applies it and returns the applied templateGroup.
func (c *FakeTemplateGroups) Apply(ctx context.Context, templateGroup *alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.TemplateGroup, err error) {
if templateGroup == nil {
return nil, fmt.Errorf("templateGroup provided to Apply must not be nil")
}
data, err := json.Marshal(templateGroup)
if err != nil {
return nil, err
}
name := templateGroup.Name
if name == nil {
return nil, fmt.Errorf("templateGroup.Name must be provided to Apply")
}
emptyResult := &v0alpha1.TemplateGroup{}
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceActionWithOptions(templategroupsResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult)
if obj == nil {
return emptyResult, err
}
return obj.(*v0alpha1.TemplateGroup), err
}
@@ -6,4 +6,6 @@ package v0alpha1
type ReceiverExpansion 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"
)
// TemplateGroupsGetter has a method to return a TemplateGroupInterface.
// A group's client should implement this interface.
type TemplateGroupsGetter interface {
TemplateGroups(namespace string) TemplateGroupInterface
}
// TemplateGroupInterface has methods to work with TemplateGroup resources.
type TemplateGroupInterface interface {
Create(ctx context.Context, templateGroup *v0alpha1.TemplateGroup, opts v1.CreateOptions) (*v0alpha1.TemplateGroup, error)
Update(ctx context.Context, templateGroup *v0alpha1.TemplateGroup, opts v1.UpdateOptions) (*v0alpha1.TemplateGroup, 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.TemplateGroup, error)
List(ctx context.Context, opts v1.ListOptions) (*v0alpha1.TemplateGroupList, 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.TemplateGroup, err error)
Apply(ctx context.Context, templateGroup *alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.TemplateGroup, err error)
TemplateGroupExpansion
}
// templateGroups implements TemplateGroupInterface
type templateGroups struct {
*gentype.ClientWithListAndApply[*v0alpha1.TemplateGroup, *v0alpha1.TemplateGroupList, *alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration]
}
// newTemplateGroups returns a TemplateGroups
func newTemplateGroups(c *NotificationsV0alpha1Client, namespace string) *templateGroups {
return &templateGroups{
gentype.NewClientWithListAndApply[*v0alpha1.TemplateGroup, *v0alpha1.TemplateGroupList, *alertingnotificationsv0alpha1.TemplateGroupApplyConfiguration](
"templategroups",
c.RESTClient(),
scheme.ParameterCodec,
namespace,
func() *v0alpha1.TemplateGroup { return &v0alpha1.TemplateGroup{} },
func() *v0alpha1.TemplateGroupList { return &v0alpha1.TemplateGroupList{} }),
}
}