K8s: Fix hack/update-codegen (#91867)

This commit is contained in:
Todd Treece
2024-08-14 08:17:05 +03:00
committed by GitHub
parent e90b272299
commit dacf11b048
36 changed files with 296 additions and 670 deletions
@@ -5,6 +5,7 @@
package fake
import (
applyconfiguration "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration"
clientset "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned"
aggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1"
fakeaggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/clientset/versioned/typed/aggregation/v0alpha1/fake"
@@ -17,8 +18,12 @@ import (
// NewSimpleClientset returns a clientset that will respond with the provided objects.
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
// without applying any validations and/or defaults. It shouldn't be considered a replacement
// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement
// for a real clientset and is mostly useful in simple unit tests.
//
// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves
// server side apply testing. NewClientset is only available when apply configurations are generated (e.g.
// via --with-applyconfig).
func NewSimpleClientset(objects ...runtime.Object) *Clientset {
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
for _, obj := range objects {
@@ -60,6 +65,38 @@ func (c *Clientset) Tracker() testing.ObjectTracker {
return c.tracker
}
// NewClientset returns a clientset that will respond with the provided objects.
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
// without applying any validations and/or defaults. It shouldn't be considered a replacement
// for a real clientset and is mostly useful in simple unit tests.
func NewClientset(objects ...runtime.Object) *Clientset {
o := testing.NewFieldManagedObjectTracker(
scheme,
codecs.UniversalDecoder(),
applyconfiguration.NewTypeConverter(scheme),
)
for _, obj := range objects {
if err := o.Add(obj); err != nil {
panic(err)
}
}
cs := &Clientset{tracker: o}
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
cs.AddReactor("*", "*", testing.ObjectReaction(o))
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
gvr := action.GetResource()
ns := action.GetNamespace()
watch, err := o.Watch(gvr, ns)
if err != nil {
return false, nil, err
}
return true, watch, nil
})
return cs
}
var (
_ clientset.Interface = &Clientset{}
_ testing.FakeClient = &Clientset{}
@@ -6,9 +6,6 @@ package v0alpha1
import (
"context"
json "encoding/json"
"fmt"
"time"
v0alpha1 "github.com/grafana/grafana/pkg/aggregator/apis/aggregation/v0alpha1"
aggregationv0alpha1 "github.com/grafana/grafana/pkg/aggregator/generated/applyconfiguration/aggregation/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"
)
// DataPlaneServicesGetter has a method to return a DataPlaneServiceInterface.
@@ -29,6 +26,7 @@ type DataPlaneServicesGetter interface {
type DataPlaneServiceInterface interface {
Create(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.CreateOptions) (*v0alpha1.DataPlaneService, error)
Update(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (*v0alpha1.DataPlaneService, error)
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (*v0alpha1.DataPlaneService, error)
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
@@ -37,193 +35,25 @@ type DataPlaneServiceInterface interface {
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.DataPlaneService, err error)
Apply(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error)
// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus().
ApplyStatus(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error)
DataPlaneServiceExpansion
}
// dataPlaneServices implements DataPlaneServiceInterface
type dataPlaneServices struct {
client rest.Interface
*gentype.ClientWithListAndApply[*v0alpha1.DataPlaneService, *v0alpha1.DataPlaneServiceList, *aggregationv0alpha1.DataPlaneServiceApplyConfiguration]
}
// newDataPlaneServices returns a DataPlaneServices
func newDataPlaneServices(c *AggregationV0alpha1Client) *dataPlaneServices {
return &dataPlaneServices{
client: c.RESTClient(),
gentype.NewClientWithListAndApply[*v0alpha1.DataPlaneService, *v0alpha1.DataPlaneServiceList, *aggregationv0alpha1.DataPlaneServiceApplyConfiguration](
"dataplaneservices",
c.RESTClient(),
scheme.ParameterCodec,
"",
func() *v0alpha1.DataPlaneService { return &v0alpha1.DataPlaneService{} },
func() *v0alpha1.DataPlaneServiceList { return &v0alpha1.DataPlaneServiceList{} }),
}
}
// Get takes name of the dataPlaneService, and returns the corresponding dataPlaneService object, and an error if there is any.
func (c *dataPlaneServices) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.DataPlaneService, err error) {
result = &v0alpha1.DataPlaneService{}
err = c.client.Get().
Resource("dataplaneservices").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of DataPlaneServices that match those selectors.
func (c *dataPlaneServices) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.DataPlaneServiceList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v0alpha1.DataPlaneServiceList{}
err = c.client.Get().
Resource("dataplaneservices").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested dataPlaneServices.
func (c *dataPlaneServices) 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().
Resource("dataplaneservices").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a dataPlaneService and creates it. Returns the server's representation of the dataPlaneService, and an error, if there is any.
func (c *dataPlaneServices) Create(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.CreateOptions) (result *v0alpha1.DataPlaneService, err error) {
result = &v0alpha1.DataPlaneService{}
err = c.client.Post().
Resource("dataplaneservices").
VersionedParams(&opts, scheme.ParameterCodec).
Body(dataPlaneService).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a dataPlaneService and updates it. Returns the server's representation of the dataPlaneService, and an error, if there is any.
func (c *dataPlaneServices) Update(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (result *v0alpha1.DataPlaneService, err error) {
result = &v0alpha1.DataPlaneService{}
err = c.client.Put().
Resource("dataplaneservices").
Name(dataPlaneService.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(dataPlaneService).
Do(ctx).
Into(result)
return
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *dataPlaneServices) UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (result *v0alpha1.DataPlaneService, err error) {
result = &v0alpha1.DataPlaneService{}
err = c.client.Put().
Resource("dataplaneservices").
Name(dataPlaneService.Name).
SubResource("status").
VersionedParams(&opts, scheme.ParameterCodec).
Body(dataPlaneService).
Do(ctx).
Into(result)
return
}
// Delete takes name of the dataPlaneService and deletes it. Returns an error if one occurs.
func (c *dataPlaneServices) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
return c.client.Delete().
Resource("dataplaneservices").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *dataPlaneServices) 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().
Resource("dataplaneservices").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched dataPlaneService.
func (c *dataPlaneServices) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.DataPlaneService, err error) {
result = &v0alpha1.DataPlaneService{}
err = c.client.Patch(pt).
Resource("dataplaneservices").
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 dataPlaneService.
func (c *dataPlaneServices) Apply(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error) {
if dataPlaneService == nil {
return nil, fmt.Errorf("dataPlaneService provided to Apply must not be nil")
}
patchOpts := opts.ToPatchOptions()
data, err := json.Marshal(dataPlaneService)
if err != nil {
return nil, err
}
name := dataPlaneService.Name
if name == nil {
return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply")
}
result = &v0alpha1.DataPlaneService{}
err = c.client.Patch(types.ApplyPatchType).
Resource("dataplaneservices").
Name(*name).
VersionedParams(&patchOpts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}
// ApplyStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus().
func (c *dataPlaneServices) ApplyStatus(ctx context.Context, dataPlaneService *aggregationv0alpha1.DataPlaneServiceApplyConfiguration, opts v1.ApplyOptions) (result *v0alpha1.DataPlaneService, err error) {
if dataPlaneService == nil {
return nil, fmt.Errorf("dataPlaneService provided to Apply must not be nil")
}
patchOpts := opts.ToPatchOptions()
data, err := json.Marshal(dataPlaneService)
if err != nil {
return nil, err
}
name := dataPlaneService.Name
if name == nil {
return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply")
}
result = &v0alpha1.DataPlaneService{}
err = c.client.Patch(types.ApplyPatchType).
Resource("dataplaneservices").
Name(*name).
SubResource("status").
VersionedParams(&patchOpts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}
@@ -29,20 +29,22 @@ var dataplaneservicesKind = v0alpha1.SchemeGroupVersion.WithKind("DataPlaneServi
// Get takes name of the dataPlaneService, and returns the corresponding dataPlaneService object, and an error if there is any.
func (c *FakeDataPlaneServices) Get(ctx context.Context, name string, options v1.GetOptions) (result *v0alpha1.DataPlaneService, err error) {
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake.
Invokes(testing.NewRootGetAction(dataplaneservicesResource, name), &v0alpha1.DataPlaneService{})
Invokes(testing.NewRootGetActionWithOptions(dataplaneservicesResource, name, options), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.DataPlaneService), err
}
// List takes label and field selectors, and returns the list of DataPlaneServices that match those selectors.
func (c *FakeDataPlaneServices) List(ctx context.Context, opts v1.ListOptions) (result *v0alpha1.DataPlaneServiceList, err error) {
emptyResult := &v0alpha1.DataPlaneServiceList{}
obj, err := c.Fake.
Invokes(testing.NewRootListAction(dataplaneservicesResource, dataplaneservicesKind, opts), &v0alpha1.DataPlaneServiceList{})
Invokes(testing.NewRootListActionWithOptions(dataplaneservicesResource, dataplaneservicesKind, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
@@ -61,36 +63,39 @@ func (c *FakeDataPlaneServices) List(ctx context.Context, opts v1.ListOptions) (
// Watch returns a watch.Interface that watches the requested dataPlaneServices.
func (c *FakeDataPlaneServices) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewRootWatchAction(dataplaneservicesResource, opts))
InvokesWatch(testing.NewRootWatchActionWithOptions(dataplaneservicesResource, opts))
}
// Create takes the representation of a dataPlaneService and creates it. Returns the server's representation of the dataPlaneService, and an error, if there is any.
func (c *FakeDataPlaneServices) Create(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.CreateOptions) (result *v0alpha1.DataPlaneService, err error) {
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake.
Invokes(testing.NewRootCreateAction(dataplaneservicesResource, dataPlaneService), &v0alpha1.DataPlaneService{})
Invokes(testing.NewRootCreateActionWithOptions(dataplaneservicesResource, dataPlaneService, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.DataPlaneService), err
}
// Update takes the representation of a dataPlaneService and updates it. Returns the server's representation of the dataPlaneService, and an error, if there is any.
func (c *FakeDataPlaneServices) Update(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (result *v0alpha1.DataPlaneService, err error) {
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake.
Invokes(testing.NewRootUpdateAction(dataplaneservicesResource, dataPlaneService), &v0alpha1.DataPlaneService{})
Invokes(testing.NewRootUpdateActionWithOptions(dataplaneservicesResource, dataPlaneService, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.DataPlaneService), err
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *FakeDataPlaneServices) UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (*v0alpha1.DataPlaneService, error) {
func (c *FakeDataPlaneServices) UpdateStatus(ctx context.Context, dataPlaneService *v0alpha1.DataPlaneService, opts v1.UpdateOptions) (result *v0alpha1.DataPlaneService, err error) {
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake.
Invokes(testing.NewRootUpdateSubresourceAction(dataplaneservicesResource, "status", dataPlaneService), &v0alpha1.DataPlaneService{})
Invokes(testing.NewRootUpdateSubresourceActionWithOptions(dataplaneservicesResource, "status", dataPlaneService, opts), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.DataPlaneService), err
}
@@ -104,7 +109,7 @@ func (c *FakeDataPlaneServices) Delete(ctx context.Context, name string, opts v1
// DeleteCollection deletes a collection of objects.
func (c *FakeDataPlaneServices) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
action := testing.NewRootDeleteCollectionAction(dataplaneservicesResource, listOpts)
action := testing.NewRootDeleteCollectionActionWithOptions(dataplaneservicesResource, opts, listOpts)
_, err := c.Fake.Invokes(action, &v0alpha1.DataPlaneServiceList{})
return err
@@ -112,10 +117,11 @@ func (c *FakeDataPlaneServices) DeleteCollection(ctx context.Context, opts v1.De
// Patch applies the patch and returns the patched dataPlaneService.
func (c *FakeDataPlaneServices) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v0alpha1.DataPlaneService, err error) {
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake.
Invokes(testing.NewRootPatchSubresourceAction(dataplaneservicesResource, name, pt, data, subresources...), &v0alpha1.DataPlaneService{})
Invokes(testing.NewRootPatchSubresourceActionWithOptions(dataplaneservicesResource, name, pt, data, opts, subresources...), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.DataPlaneService), err
}
@@ -133,10 +139,11 @@ func (c *FakeDataPlaneServices) Apply(ctx context.Context, dataPlaneService *agg
if name == nil {
return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply")
}
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake.
Invokes(testing.NewRootPatchSubresourceAction(dataplaneservicesResource, *name, types.ApplyPatchType, data), &v0alpha1.DataPlaneService{})
Invokes(testing.NewRootPatchSubresourceActionWithOptions(dataplaneservicesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions()), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.DataPlaneService), err
}
@@ -155,10 +162,11 @@ func (c *FakeDataPlaneServices) ApplyStatus(ctx context.Context, dataPlaneServic
if name == nil {
return nil, fmt.Errorf("dataPlaneService.Name must be provided to Apply")
}
emptyResult := &v0alpha1.DataPlaneService{}
obj, err := c.Fake.
Invokes(testing.NewRootPatchSubresourceAction(dataplaneservicesResource, *name, types.ApplyPatchType, data, "status"), &v0alpha1.DataPlaneService{})
Invokes(testing.NewRootPatchSubresourceActionWithOptions(dataplaneservicesResource, *name, types.ApplyPatchType, data, opts.ToPatchOptions(), "status"), emptyResult)
if obj == nil {
return nil, err
return emptyResult, err
}
return obj.(*v0alpha1.DataPlaneService), err
}