K8s: Add k8s codegen PR check (#91903)

This commit is contained in:
Todd Treece
2024-08-14 11:06:37 -04:00
committed by GitHub
parent 44290ddf32
commit da6b02a2b0
27 changed files with 363 additions and 456 deletions
@@ -5,20 +5,20 @@
package v0alpha1
import (
json "encoding/json"
v0alpha1 "github.com/grafana/grafana/pkg/apimachinery/apis/common/v0alpha1"
)
// IntegrationApplyConfiguration represents an declarative configuration of the Integration type for use
// IntegrationApplyConfiguration represents a declarative configuration of the Integration type for use
// with apply.
type IntegrationApplyConfiguration struct {
DisableResolveMessage *bool `json:"disableResolveMessage,omitempty"`
SecureFields map[string]bool `json:"SecureFields,omitempty"`
Settings *json.RawMessage `json:"settings,omitempty"`
Type *string `json:"type,omitempty"`
Uid *string `json:"uid,omitempty"`
DisableResolveMessage *bool `json:"disableResolveMessage,omitempty"`
SecureFields map[string]bool `json:"secureFields,omitempty"`
Settings *v0alpha1.Unstructured `json:"settings,omitempty"`
Type *string `json:"type,omitempty"`
Uid *string `json:"uid,omitempty"`
}
// IntegrationApplyConfiguration constructs an declarative configuration of the Integration type for use with
// IntegrationApplyConfiguration constructs a declarative configuration of the Integration type for use with
// apply.
func Integration() *IntegrationApplyConfiguration {
return &IntegrationApplyConfiguration{}
@@ -49,7 +49,7 @@ func (b *IntegrationApplyConfiguration) WithSecureFields(entries map[string]bool
// WithSettings sets the Settings 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 Settings field is set to the value of the last call.
func (b *IntegrationApplyConfiguration) WithSettings(value json.RawMessage) *IntegrationApplyConfiguration {
func (b *IntegrationApplyConfiguration) WithSettings(value v0alpha1.Unstructured) *IntegrationApplyConfiguration {
b.Settings = &value
return b
}
@@ -4,7 +4,7 @@
package v0alpha1
// IntervalApplyConfiguration represents an declarative configuration of the Interval type for use
// IntervalApplyConfiguration represents a declarative configuration of the Interval type for use
// with apply.
type IntervalApplyConfiguration struct {
DaysOfMonth []string `json:"days_of_month,omitempty"`
@@ -15,7 +15,7 @@ type IntervalApplyConfiguration struct {
Years []string `json:"years,omitempty"`
}
// IntervalApplyConfiguration constructs an declarative configuration of the Interval type for use with
// IntervalApplyConfiguration constructs a declarative configuration of the Interval type for use with
// apply.
func Interval() *IntervalApplyConfiguration {
return &IntervalApplyConfiguration{}
@@ -10,7 +10,7 @@ import (
v1 "k8s.io/client-go/applyconfigurations/meta/v1"
)
// ReceiverApplyConfiguration represents an declarative configuration of the Receiver type for use
// ReceiverApplyConfiguration represents a declarative configuration of the Receiver type for use
// with apply.
type ReceiverApplyConfiguration struct {
v1.TypeMetaApplyConfiguration `json:",inline"`
@@ -18,7 +18,7 @@ type ReceiverApplyConfiguration struct {
Spec *ReceiverSpecApplyConfiguration `json:"spec,omitempty"`
}
// Receiver constructs an declarative configuration of the Receiver type for use with
// Receiver constructs a declarative configuration of the Receiver type for use with
// apply.
func Receiver(name, namespace string) *ReceiverApplyConfiguration {
b := &ReceiverApplyConfiguration{}
@@ -194,3 +194,9 @@ func (b *ReceiverApplyConfiguration) WithSpec(value *ReceiverSpecApplyConfigurat
b.Spec = value
return b
}
// GetName retrieves the value of the Name field in the declarative configuration.
func (b *ReceiverApplyConfiguration) GetName() *string {
b.ensureObjectMetaApplyConfigurationExists()
return b.Name
}
@@ -4,14 +4,14 @@
package v0alpha1
// ReceiverSpecApplyConfiguration represents an declarative configuration of the ReceiverSpec type for use
// ReceiverSpecApplyConfiguration represents a declarative configuration of the ReceiverSpec type for use
// with apply.
type ReceiverSpecApplyConfiguration struct {
Integrations []IntegrationApplyConfiguration `json:"integrations,omitempty"`
Title *string `json:"title,omitempty"`
}
// ReceiverSpecApplyConfiguration constructs an declarative configuration of the ReceiverSpec type for use with
// ReceiverSpecApplyConfiguration constructs a declarative configuration of the ReceiverSpec type for use with
// apply.
func ReceiverSpec() *ReceiverSpecApplyConfiguration {
return &ReceiverSpecApplyConfiguration{}
@@ -10,7 +10,7 @@ import (
v1 "k8s.io/client-go/applyconfigurations/meta/v1"
)
// TimeIntervalApplyConfiguration represents an declarative configuration of the TimeInterval type for use
// TimeIntervalApplyConfiguration represents a declarative configuration of the TimeInterval type for use
// with apply.
type TimeIntervalApplyConfiguration struct {
v1.TypeMetaApplyConfiguration `json:",inline"`
@@ -18,7 +18,7 @@ type TimeIntervalApplyConfiguration struct {
Spec *TimeIntervalSpecApplyConfiguration `json:"spec,omitempty"`
}
// TimeInterval constructs an declarative configuration of the TimeInterval type for use with
// TimeInterval constructs a declarative configuration of the TimeInterval type for use with
// apply.
func TimeInterval(name, namespace string) *TimeIntervalApplyConfiguration {
b := &TimeIntervalApplyConfiguration{}
@@ -194,3 +194,9 @@ func (b *TimeIntervalApplyConfiguration) WithSpec(value *TimeIntervalSpecApplyCo
b.Spec = value
return b
}
// GetName retrieves the value of the Name field in the declarative configuration.
func (b *TimeIntervalApplyConfiguration) GetName() *string {
b.ensureObjectMetaApplyConfigurationExists()
return b.Name
}
@@ -4,14 +4,14 @@
package v0alpha1
// TimeIntervalSpecApplyConfiguration represents an declarative configuration of the TimeIntervalSpec type for use
// TimeIntervalSpecApplyConfiguration represents a declarative configuration of the TimeIntervalSpec type for use
// with apply.
type TimeIntervalSpecApplyConfiguration struct {
Name *string `json:"name,omitempty"`
TimeIntervals []IntervalApplyConfiguration `json:"time_intervals,omitempty"`
}
// TimeIntervalSpecApplyConfiguration constructs an declarative configuration of the TimeIntervalSpec type for use with
// TimeIntervalSpecApplyConfiguration constructs a declarative configuration of the TimeIntervalSpec type for use with
// apply.
func TimeIntervalSpec() *TimeIntervalSpecApplyConfiguration {
return &TimeIntervalSpecApplyConfiguration{}
@@ -4,14 +4,14 @@
package v0alpha1
// TimeRangeApplyConfiguration represents an declarative configuration of the TimeRange type for use
// TimeRangeApplyConfiguration represents a declarative configuration of the TimeRange type for use
// with apply.
type TimeRangeApplyConfiguration struct {
EndTime *string `json:"end_time,omitempty"`
StartTime *string `json:"start_time,omitempty"`
}
// TimeRangeApplyConfiguration constructs an declarative configuration of the TimeRange type for use with
// TimeRangeApplyConfiguration constructs a declarative configuration of the TimeRange type for use with
// apply.
func TimeRange() *TimeRangeApplyConfiguration {
return &TimeRangeApplyConfiguration{}
@@ -30,22 +30,24 @@ 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) {
emptyResult := &v0alpha1.Receiver{}
obj, err := c.Fake.
Invokes(testing.NewGetAction(receiversResource, c.ns, name), &v0alpha1.Receiver{})
Invokes(testing.NewGetActionWithOptions(receiversResource, c.ns, name, options), emptyResult)
if obj == nil {
return nil, err
return emptyResult, 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) {
emptyResult := &v0alpha1.ReceiverList{}
obj, err := c.Fake.
Invokes(testing.NewListAction(receiversResource, receiversKind, c.ns, opts), &v0alpha1.ReceiverList{})
Invokes(testing.NewListActionWithOptions(receiversResource, receiversKind, c.ns, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
@@ -64,28 +66,30 @@ func (c *FakeReceivers) List(ctx context.Context, opts v1.ListOptions) (result *
// 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))
InvokesWatch(testing.NewWatchActionWithOptions(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) {
emptyResult := &v0alpha1.Receiver{}
obj, err := c.Fake.
Invokes(testing.NewCreateAction(receiversResource, c.ns, receiver), &v0alpha1.Receiver{})
Invokes(testing.NewCreateActionWithOptions(receiversResource, c.ns, receiver, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, 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) {
emptyResult := &v0alpha1.Receiver{}
obj, err := c.Fake.
Invokes(testing.NewUpdateAction(receiversResource, c.ns, receiver), &v0alpha1.Receiver{})
Invokes(testing.NewUpdateActionWithOptions(receiversResource, c.ns, receiver, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.Receiver), err
}
@@ -100,7 +104,7 @@ func (c *FakeReceivers) Delete(ctx context.Context, name string, opts v1.DeleteO
// 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)
action := testing.NewDeleteCollectionActionWithOptions(receiversResource, c.ns, opts, listOpts)
_, err := c.Fake.Invokes(action, &v0alpha1.ReceiverList{})
return err
@@ -108,11 +112,12 @@ func (c *FakeReceivers) DeleteCollection(ctx context.Context, opts v1.DeleteOpti
// 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) {
emptyResult := &v0alpha1.Receiver{}
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(receiversResource, c.ns, name, pt, data, subresources...), &v0alpha1.Receiver{})
Invokes(testing.NewPatchSubresourceActionWithOptions(receiversResource, c.ns, name, pt, data, opts, subresources...), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.Receiver), err
}
@@ -130,11 +135,12 @@ func (c *FakeReceivers) Apply(ctx context.Context, receiver *alertingnotificatio
if name == nil {
return nil, fmt.Errorf("receiver.Name must be provided to Apply")
}
emptyResult := &v0alpha1.Receiver{}
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(receiversResource, c.ns, *name, types.ApplyPatchType, data), &v0alpha1.Receiver{})
Invokes(testing.NewPatchSubresourceActionWithOptions(receiversResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.Receiver), err
}
@@ -30,22 +30,24 @@ var timeintervalsKind = v0alpha1.SchemeGroupVersion.WithKind("TimeInterval")
// Get takes name of the timeInterval, and returns the corresponding timeInterval object, and an error if there is any.
func (c *FakeTimeIntervals) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.TimeInterval, err error) {
emptyResult := &v0alpha1.TimeInterval{}
obj, err := c.Fake.
Invokes(testing.NewGetAction(timeintervalsResource, c.ns, name), &v0alpha1.TimeInterval{})
Invokes(testing.NewGetActionWithOptions(timeintervalsResource, c.ns, name, options), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.TimeInterval), err
}
// List takes label and field selectors, and returns the list of TimeIntervals that match those selectors.
func (c *FakeTimeIntervals) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.TimeIntervalList, err error) {
emptyResult := &v0alpha1.TimeIntervalList{}
obj, err := c.Fake.
Invokes(testing.NewListAction(timeintervalsResource, timeintervalsKind, c.ns, opts), &v0alpha1.TimeIntervalList{})
Invokes(testing.NewListActionWithOptions(timeintervalsResource, timeintervalsKind, c.ns, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
@@ -64,28 +66,30 @@ func (c *FakeTimeIntervals) List(ctx context.Context, opts v1.ListOptions) (resu
// Watch returns a watch.Interface that watches the requested timeIntervals.
func (c *FakeTimeIntervals) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(timeintervalsResource, c.ns, opts))
InvokesWatch(testing.NewWatchActionWithOptions(timeintervalsResource, c.ns, opts))
}
// Create takes the representation of a timeInterval and creates it. Returns the server's representation of the timeInterval, and an error, if there is any.
func (c *FakeTimeIntervals) Create(ctx context.Context, timeInterval *v0alpha1.TimeInterval, opts v1.CreateOptions) (result *v0alpha1.TimeInterval, err error) {
emptyResult := &v0alpha1.TimeInterval{}
obj, err := c.Fake.
Invokes(testing.NewCreateAction(timeintervalsResource, c.ns, timeInterval), &v0alpha1.TimeInterval{})
Invokes(testing.NewCreateActionWithOptions(timeintervalsResource, c.ns, timeInterval, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.TimeInterval), err
}
// Update takes the representation of a timeInterval and updates it. Returns the server's representation of the timeInterval, and an error, if there is any.
func (c *FakeTimeIntervals) Update(ctx context.Context, timeInterval *v0alpha1.TimeInterval, opts v1.UpdateOptions) (result *v0alpha1.TimeInterval, err error) {
emptyResult := &v0alpha1.TimeInterval{}
obj, err := c.Fake.
Invokes(testing.NewUpdateAction(timeintervalsResource, c.ns, timeInterval), &v0alpha1.TimeInterval{})
Invokes(testing.NewUpdateActionWithOptions(timeintervalsResource, c.ns, timeInterval, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.TimeInterval), err
}
@@ -100,7 +104,7 @@ func (c *FakeTimeIntervals) Delete(ctx context.Context, name string, opts v1.Del
// DeleteCollection deletes a collection of objects.
func (c *FakeTimeIntervals) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
action := testing.NewDeleteCollectionAction(timeintervalsResource, c.ns, listOpts)
action := testing.NewDeleteCollectionActionWithOptions(timeintervalsResource, c.ns, opts, listOpts)
_, err := c.Fake.Invokes(action, &v0alpha1.TimeIntervalList{})
return err
@@ -108,11 +112,12 @@ func (c *FakeTimeIntervals) DeleteCollection(ctx context.Context, opts v1.Delete
// Patch applies the patch and returns the patched timeInterval.
func (c *FakeTimeIntervals) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.TimeInterval, err error) {
emptyResult := &v0alpha1.TimeInterval{}
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(timeintervalsResource, c.ns, name, pt, data, subresources...), &v0alpha1.TimeInterval{})
Invokes(testing.NewPatchSubresourceActionWithOptions(timeintervalsResource, c.ns, name, pt, data, opts, subresources...), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.TimeInterval), err
}
@@ -130,11 +135,12 @@ func (c *FakeTimeIntervals) Apply(ctx context.Context, timeInterval *alertingnot
if name == nil {
return nil, fmt.Errorf("timeInterval.Name must be provided to Apply")
}
emptyResult := &v0alpha1.TimeInterval{}
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(timeintervalsResource, c.ns, *name, types.ApplyPatchType, data), &v0alpha1.TimeInterval{})
Invokes(testing.NewPatchSubresourceActionWithOptions(timeintervalsResource, c.ns, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.TimeInterval), err
}
@@ -6,9 +6,6 @@ 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"
@@ -16,7 +13,7 @@ import (
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"
gentype "k8s.io/client-go/gentype"
)
// ReceiversGetter has a method to return a ReceiverInterface.
@@ -41,154 +38,18 @@ type ReceiverInterface interface {
// receivers implements ReceiverInterface
type receivers struct {
client rest.Interface
ns string
*gentype.ClientWithListAndApply[*v0alpha1.Receiver, *v0alpha1.ReceiverList, *alertingnotificationsv0alpha1.ReceiverApplyConfiguration]
}
// newReceivers returns a Receivers
func newReceivers(c *NotificationsV0alpha1Client, namespace string) *receivers {
return &receivers{
client: c.RESTClient(),
ns: namespace,
gentype.NewClientWithListAndApply[*v0alpha1.Receiver, *v0alpha1.ReceiverList, *alertingnotificationsv0alpha1.ReceiverApplyConfiguration](
"receivers",
c.RESTClient(),
scheme.ParameterCodec,
namespace,
func() *v0alpha1.Receiver { return &v0alpha1.Receiver{} },
func() *v0alpha1.ReceiverList { return &v0alpha1.ReceiverList{} }),
}
}
// 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
}
@@ -6,9 +6,6 @@ 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"
@@ -16,7 +13,7 @@ import (
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"
gentype "k8s.io/client-go/gentype"
)
// TimeIntervalsGetter has a method to return a TimeIntervalInterface.
@@ -41,154 +38,18 @@ type TimeIntervalInterface interface {
// timeIntervals implements TimeIntervalInterface
type timeIntervals struct {
client rest.Interface
ns string
*gentype.ClientWithListAndApply[*v0alpha1.TimeInterval, *v0alpha1.TimeIntervalList, *alertingnotificationsv0alpha1.TimeIntervalApplyConfiguration]
}
// newTimeIntervals returns a TimeIntervals
func newTimeIntervals(c *NotificationsV0alpha1Client, namespace string) *timeIntervals {
return &timeIntervals{
client: c.RESTClient(),
ns: namespace,
gentype.NewClientWithListAndApply[*v0alpha1.TimeInterval, *v0alpha1.TimeIntervalList, *alertingnotificationsv0alpha1.TimeIntervalApplyConfiguration](
"timeintervals",
c.RESTClient(),
scheme.ParameterCodec,
namespace,
func() *v0alpha1.TimeInterval { return &v0alpha1.TimeInterval{} },
func() *v0alpha1.TimeIntervalList { return &v0alpha1.TimeIntervalList{} }),
}
}
// Get takes name of the timeInterval, and returns the corresponding timeInterval object, and an error if there is any.
func (c *timeIntervals) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.TimeInterval, err error) {
result = &v0alpha1.TimeInterval{}
err = c.client.Get().
Namespace(c.ns).
Resource("timeintervals").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of TimeIntervals that match those selectors.
func (c *timeIntervals) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.TimeIntervalList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v0alpha1.TimeIntervalList{}
err = c.client.Get().
Namespace(c.ns).
Resource("timeintervals").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested timeIntervals.
func (c *timeIntervals) 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("timeintervals").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a timeInterval and creates it. Returns the server's representation of the timeInterval, and an error, if there is any.
func (c *timeIntervals) Create(ctx context.Context, timeInterval *v0alpha1.TimeInterval, opts v1.CreateOptions) (result *v0alpha1.TimeInterval, err error) {
result = &v0alpha1.TimeInterval{}
err = c.client.Post().
Namespace(c.ns).
Resource("timeintervals").
VersionedParams(&opts, scheme.ParameterCodec).
Body(timeInterval).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a timeInterval and updates it. Returns the server's representation of the timeInterval, and an error, if there is any.
func (c *timeIntervals) Update(ctx context.Context, timeInterval *v0alpha1.TimeInterval, opts v1.UpdateOptions) (result *v0alpha1.TimeInterval, err error) {
result = &v0alpha1.TimeInterval{}
err = c.client.Put().
Namespace(c.ns).
Resource("timeintervals").
Name(timeInterval.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(timeInterval).
Do(ctx).
Into(result)
return
}
// Delete takes name of the timeInterval and deletes it. Returns an error if one occurs.
func (c *timeIntervals) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("timeintervals").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *timeIntervals) 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("timeintervals").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched timeInterval.
func (c *timeIntervals) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.TimeInterval, err error) {
result = &v0alpha1.TimeInterval{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("timeintervals").
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 timeInterval.
func (c *timeIntervals) Apply(ctx context.Context, timeInterval *alertingnotificationsv0alpha1.TimeIntervalApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.TimeInterval, err error) {
if timeInterval == nil {
return nil, fmt.Errorf("timeInterval provided to Apply must not be nil")
}
patchOpts := opts.ToPatchOptions()
data, err := json.Marshal(timeInterval)
if err != nil {
return nil, err
}
name := timeInterval.Name
if name == nil {
return nil, fmt.Errorf("timeInterval.Name must be provided to Apply")
}
result = &v0alpha1.TimeInterval{}
err = c.client.Patch(types.ApplyPatchType).
Namespace(c.ns).
Resource("timeintervals").
Name(*name).
VersionedParams(&patchOpts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}
@@ -6,8 +6,8 @@ package v0alpha1
import (
v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/listers"
"k8s.io/client-go/tools/cache"
)
@@ -24,25 +24,17 @@ type ReceiverLister interface {
// receiverLister implements the ReceiverLister interface.
type receiverLister struct {
indexer cache.Indexer
listers.ResourceIndexer[*v0alpha1.Receiver]
}
// NewReceiverLister returns a new ReceiverLister.
func NewReceiverLister(indexer cache.Indexer) ReceiverLister {
return &receiverLister{indexer: indexer}
}
// List lists all Receivers in the indexer.
func (s *receiverLister) List(selector labels.Selector) (ret []*v0alpha1.Receiver, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v0alpha1.Receiver))
})
return ret, err
return &receiverLister{listers.New[*v0alpha1.Receiver](indexer, v0alpha1.Resource("receiver"))}
}
// Receivers returns an object that can list and get Receivers.
func (s *receiverLister) Receivers(namespace string) ReceiverNamespaceLister {
return receiverNamespaceLister{indexer: s.indexer, namespace: namespace}
return receiverNamespaceLister{listers.NewNamespaced[*v0alpha1.Receiver](s.ResourceIndexer, namespace)}
}
// ReceiverNamespaceLister helps list and get Receivers.
@@ -60,26 +52,5 @@ type ReceiverNamespaceLister interface {
// receiverNamespaceLister implements the ReceiverNamespaceLister
// interface.
type receiverNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all Receivers in the indexer for a given namespace.
func (s receiverNamespaceLister) List(selector labels.Selector) (ret []*v0alpha1.Receiver, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v0alpha1.Receiver))
})
return ret, err
}
// Get retrieves the Receiver from the indexer for a given namespace and name.
func (s receiverNamespaceLister) Get(name string) (*v0alpha1.Receiver, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v0alpha1.Resource("receiver"), name)
}
return obj.(*v0alpha1.Receiver), nil
listers.ResourceIndexer[*v0alpha1.Receiver]
}
@@ -6,8 +6,8 @@ package v0alpha1
import (
v0alpha1 "github.com/grafana/grafana/pkg/apis/alerting_notifications/v0alpha1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/listers"
"k8s.io/client-go/tools/cache"
)
@@ -24,25 +24,17 @@ type TimeIntervalLister interface {
// timeIntervalLister implements the TimeIntervalLister interface.
type timeIntervalLister struct {
indexer cache.Indexer
listers.ResourceIndexer[*v0alpha1.TimeInterval]
}
// NewTimeIntervalLister returns a new TimeIntervalLister.
func NewTimeIntervalLister(indexer cache.Indexer) TimeIntervalLister {
return &timeIntervalLister{indexer: indexer}
}
// List lists all TimeIntervals in the indexer.
func (s *timeIntervalLister) List(selector labels.Selector) (ret []*v0alpha1.TimeInterval, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v0alpha1.TimeInterval))
})
return ret, err
return &timeIntervalLister{listers.New[*v0alpha1.TimeInterval](indexer, v0alpha1.Resource("timeinterval"))}
}
// TimeIntervals returns an object that can list and get TimeIntervals.
func (s *timeIntervalLister) TimeIntervals(namespace string) TimeIntervalNamespaceLister {
return timeIntervalNamespaceLister{indexer: s.indexer, namespace: namespace}
return timeIntervalNamespaceLister{listers.NewNamespaced[*v0alpha1.TimeInterval](s.ResourceIndexer, namespace)}
}
// TimeIntervalNamespaceLister helps list and get TimeIntervals.
@@ -60,26 +52,5 @@ type TimeIntervalNamespaceLister interface {
// timeIntervalNamespaceLister implements the TimeIntervalNamespaceLister
// interface.
type timeIntervalNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all TimeIntervals in the indexer for a given namespace.
func (s timeIntervalNamespaceLister) List(selector labels.Selector) (ret []*v0alpha1.TimeInterval, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v0alpha1.TimeInterval))
})
return ret, err
}
// Get retrieves the TimeInterval from the indexer for a given namespace and name.
func (s timeIntervalNamespaceLister) Get(name string) (*v0alpha1.TimeInterval, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v0alpha1.Resource("timeinterval"), name)
}
return obj.(*v0alpha1.TimeInterval), nil
listers.ResourceIndexer[*v0alpha1.TimeInterval]
}