Alerting: Receiver API (#89707)
This commit is contained in:
+5
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
type NotificationsV0alpha1Interface interface {
|
||||
RESTClient() rest.Interface
|
||||
ReceiversGetter
|
||||
TimeIntervalsGetter
|
||||
}
|
||||
|
||||
@@ -22,6 +23,10 @@ type NotificationsV0alpha1Client struct {
|
||||
restClient rest.Interface
|
||||
}
|
||||
|
||||
func (c *NotificationsV0alpha1Client) Receivers(namespace string) ReceiverInterface {
|
||||
return newReceivers(c, namespace)
|
||||
}
|
||||
|
||||
func (c *NotificationsV0alpha1Client) TimeIntervals(namespace string) TimeIntervalInterface {
|
||||
return newTimeIntervals(c, namespace)
|
||||
}
|
||||
|
||||
+4
@@ -14,6 +14,10 @@ type FakeNotificationsV0alpha1 struct {
|
||||
*testing.Fake
|
||||
}
|
||||
|
||||
func (c *FakeNotificationsV0alpha1) Receivers(namespace string) v0alpha1.ReceiverInterface {
|
||||
return &FakeReceivers{c, namespace}
|
||||
}
|
||||
|
||||
func (c *FakeNotificationsV0alpha1) TimeIntervals(namespace string) v0alpha1.TimeIntervalInterface {
|
||||
return &FakeTimeIntervals{c, namespace}
|
||||
}
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
// FakeReceivers implements ReceiverInterface
|
||||
type FakeReceivers struct {
|
||||
Fake *FakeNotificationsV0alpha1
|
||||
ns string
|
||||
}
|
||||
|
||||
var receiversResource = v0alpha1.SchemeGroupVersion.WithResource("receivers")
|
||||
|
||||
var receiversKind = v0alpha1.SchemeGroupVersion.WithKind("Receiver")
|
||||
|
||||
// Get takes name of the receiver, and returns the corresponding receiver object, and an error if there is any.
|
||||
func (c *FakeReceivers) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.Receiver, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewGetAction(receiversResource, c.ns, name), &v0alpha1.Receiver{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v0alpha1.Receiver), err
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of Receivers that match those selectors.
|
||||
func (c *FakeReceivers) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.ReceiverList, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewListAction(receiversResource, receiversKind, c.ns, opts), &v0alpha1.ReceiverList{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
||||
if label == nil {
|
||||
label = labels.Everything()
|
||||
}
|
||||
list := &v0alpha1.ReceiverList{ListMeta: obj.(*v0alpha1.ReceiverList).ListMeta}
|
||||
for _, item := range obj.(*v0alpha1.ReceiverList).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 receivers.
|
||||
func (c *FakeReceivers) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
||||
return c.Fake.
|
||||
InvokesWatch(testing.NewWatchAction(receiversResource, c.ns, opts))
|
||||
|
||||
}
|
||||
|
||||
// Create takes the representation of a receiver and creates it. Returns the server's representation of the receiver, and an error, if there is any.
|
||||
func (c *FakeReceivers) Create(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.CreateOptions) (result *v0alpha1.Receiver, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewCreateAction(receiversResource, c.ns, receiver), &v0alpha1.Receiver{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v0alpha1.Receiver), err
|
||||
}
|
||||
|
||||
// Update takes the representation of a receiver and updates it. Returns the server's representation of the receiver, and an error, if there is any.
|
||||
func (c *FakeReceivers) Update(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.UpdateOptions) (result *v0alpha1.Receiver, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewUpdateAction(receiversResource, c.ns, receiver), &v0alpha1.Receiver{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v0alpha1.Receiver), err
|
||||
}
|
||||
|
||||
// Delete takes name of the receiver and deletes it. Returns an error if one occurs.
|
||||
func (c *FakeReceivers) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
||||
_, err := c.Fake.
|
||||
Invokes(testing.NewDeleteActionWithOptions(receiversResource, c.ns, name, opts), &v0alpha1.Receiver{})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *FakeReceivers) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
||||
action := testing.NewDeleteCollectionAction(receiversResource, c.ns, listOpts)
|
||||
|
||||
_, err := c.Fake.Invokes(action, &v0alpha1.ReceiverList{})
|
||||
return err
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched receiver.
|
||||
func (c *FakeReceivers) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.Receiver, err error) {
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceAction(receiversResource, c.ns, name, pt, data, subresources...), &v0alpha1.Receiver{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v0alpha1.Receiver), err
|
||||
}
|
||||
|
||||
// Apply takes the given apply declarative configuration, applies it and returns the applied receiver.
|
||||
func (c *FakeReceivers) Apply(ctx context.Context, receiver *alertingnotificationsv0alpha1.ReceiverApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.Receiver, err error) {
|
||||
if receiver == nil {
|
||||
return nil, fmt.Errorf("receiver provided to Apply must not be nil")
|
||||
}
|
||||
data, err := json.Marshal(receiver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name := receiver.Name
|
||||
if name == nil {
|
||||
return nil, fmt.Errorf("receiver.Name must be provided to Apply")
|
||||
}
|
||||
obj, err := c.Fake.
|
||||
Invokes(testing.NewPatchSubresourceAction(receiversResource, c.ns, *name, types.ApplyPatchType, data), &v0alpha1.Receiver{})
|
||||
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*v0alpha1.Receiver), err
|
||||
}
|
||||
+2
@@ -4,4 +4,6 @@
|
||||
|
||||
package v0alpha1
|
||||
|
||||
type ReceiverExpansion interface{}
|
||||
|
||||
type TimeIntervalExpansion interface{}
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
// Code generated by client-gen. DO NOT EDIT.
|
||||
|
||||
package v0alpha1
|
||||
|
||||
import (
|
||||
"context"
|
||||
json "encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
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"
|
||||
rest "k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
// ReceiversGetter has a method to return a ReceiverInterface.
|
||||
// A group's client should implement this interface.
|
||||
type ReceiversGetter interface {
|
||||
Receivers(namespace string) ReceiverInterface
|
||||
}
|
||||
|
||||
// ReceiverInterface has methods to work with Receiver resources.
|
||||
type ReceiverInterface interface {
|
||||
Create(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.CreateOptions) (*v0alpha1.Receiver, error)
|
||||
Update(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.UpdateOptions) (*v0alpha1.Receiver, 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.Receiver, error)
|
||||
List(ctx context.Context, opts v1.ListOptions) (*v0alpha1.ReceiverList, 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.Receiver, err error)
|
||||
Apply(ctx context.Context, receiver *alertingnotificationsv0alpha1.ReceiverApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.Receiver, err error)
|
||||
ReceiverExpansion
|
||||
}
|
||||
|
||||
// receivers implements ReceiverInterface
|
||||
type receivers struct {
|
||||
client rest.Interface
|
||||
ns string
|
||||
}
|
||||
|
||||
// newReceivers returns a Receivers
|
||||
func newReceivers(c *NotificationsV0alpha1Client, namespace string) *receivers {
|
||||
return &receivers{
|
||||
client: c.RESTClient(),
|
||||
ns: namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// Get takes name of the receiver, and returns the corresponding receiver object, and an error if there is any.
|
||||
func (c *receivers) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.Receiver, err error) {
|
||||
result = &v0alpha1.Receiver{}
|
||||
err = c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
Name(name).
|
||||
VersionedParams(&options, scheme.ParameterCodec).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// List takes label and field selectors, and returns the list of Receivers that match those selectors.
|
||||
func (c *receivers) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.ReceiverList, err error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
result = &v0alpha1.ReceiverList{}
|
||||
err = c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Watch returns a watch.Interface that watches the requested receivers.
|
||||
func (c *receivers) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
opts.Watch = true
|
||||
return c.client.Get().
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Watch(ctx)
|
||||
}
|
||||
|
||||
// Create takes the representation of a receiver and creates it. Returns the server's representation of the receiver, and an error, if there is any.
|
||||
func (c *receivers) Create(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.CreateOptions) (result *v0alpha1.Receiver, err error) {
|
||||
result = &v0alpha1.Receiver{}
|
||||
err = c.client.Post().
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(receiver).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Update takes the representation of a receiver and updates it. Returns the server's representation of the receiver, and an error, if there is any.
|
||||
func (c *receivers) Update(ctx context.Context, receiver *v0alpha1.Receiver, opts v1.UpdateOptions) (result *v0alpha1.Receiver, err error) {
|
||||
result = &v0alpha1.Receiver{}
|
||||
err = c.client.Put().
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
Name(receiver.Name).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(receiver).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete takes name of the receiver and deletes it. Returns an error if one occurs.
|
||||
func (c *receivers) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
|
||||
return c.client.Delete().
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
Name(name).
|
||||
Body(&opts).
|
||||
Do(ctx).
|
||||
Error()
|
||||
}
|
||||
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *receivers) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
|
||||
var timeout time.Duration
|
||||
if listOpts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
return c.client.Delete().
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
VersionedParams(&listOpts, scheme.ParameterCodec).
|
||||
Timeout(timeout).
|
||||
Body(&opts).
|
||||
Do(ctx).
|
||||
Error()
|
||||
}
|
||||
|
||||
// Patch applies the patch and returns the patched receiver.
|
||||
func (c *receivers) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.Receiver, err error) {
|
||||
result = &v0alpha1.Receiver{}
|
||||
err = c.client.Patch(pt).
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
Name(name).
|
||||
SubResource(subresources...).
|
||||
VersionedParams(&opts, scheme.ParameterCodec).
|
||||
Body(data).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Apply takes the given apply declarative configuration, applies it and returns the applied receiver.
|
||||
func (c *receivers) Apply(ctx context.Context, receiver *alertingnotificationsv0alpha1.ReceiverApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.Receiver, err error) {
|
||||
if receiver == nil {
|
||||
return nil, fmt.Errorf("receiver provided to Apply must not be nil")
|
||||
}
|
||||
patchOpts := opts.ToPatchOptions()
|
||||
data, err := json.Marshal(receiver)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name := receiver.Name
|
||||
if name == nil {
|
||||
return nil, fmt.Errorf("receiver.Name must be provided to Apply")
|
||||
}
|
||||
result = &v0alpha1.Receiver{}
|
||||
err = c.client.Patch(types.ApplyPatchType).
|
||||
Namespace(c.ns).
|
||||
Resource("receivers").
|
||||
Name(*name).
|
||||
VersionedParams(&patchOpts, scheme.ParameterCodec).
|
||||
Body(data).
|
||||
Do(ctx).
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user