From 2fe6941f9c56c5e5d00bbc8db9f2c9194a1226d0 Mon Sep 17 00:00:00 2001 From: Tyler Schade Date: Tue, 10 Sep 2024 12:27:35 -0400 Subject: [PATCH] gen --- ci/oss_compliance/osa_provided.md | 4 +- codegen/test/api/things.test.io/v1/clients.go | 349 +++++----- .../v1/controller/event_handlers.go | 244 +++---- .../v1/controller/multicluster_reconcilers.go | 2 - .../v1/controller/reconcilers.go | 228 ++++--- .../test/api/things.test.io/v1/json.gen.go | 17 +- .../api/things.test.io/v1/proto_deepcopy.go | 47 +- .../v1/providers/client_providers.go | 50 +- .../test/api/things.test.io/v1/register.go | 19 +- .../test/api/things.test.io/v1/sets/sets.go | 618 +++++++++--------- .../test/api/things.test.io/v1/test_api.pb.go | 5 +- .../api/things.test.io/v1/type_helpers.go | 3 - codegen/test/api/things.test.io/v1/types.go | 51 +- .../v1/zz_generated.deepcopy.go | 151 +++-- pkg/api/core.skv2.solo.io/v1/core.pb.go | 5 +- .../v1alpha1/cluster.pb.go | 5 +- 16 files changed, 892 insertions(+), 906 deletions(-) diff --git a/ci/oss_compliance/osa_provided.md b/ci/oss_compliance/osa_provided.md index 55703c559..6abca766a 100644 --- a/ci/oss_compliance/osa_provided.md +++ b/ci/oss_compliance/osa_provided.md @@ -18,10 +18,10 @@ Name|Version|License [cmp/internal](https://github.com/google/go-cmp)|v0.6.0|BSD 3-clause "New" or "Revised" License [gofuzz/bytesource](https://github.com/google/gofuzz)|v1.2.0|Apache License 2.0 [google/uuid](https://github.com/google/uuid)|v1.6.0|BSD 3-clause "New" or "Revised" License -[pyroscope-go/godeltaprof](https://github.com/grafana/pyroscope-go)|v0.1.6|Apache License 2.0 +[pyroscope-go/godeltaprof](https://github.com/grafana/pyroscope-go)|v0.1.8|Apache License 2.0 [josharian/intern](https://github.com/josharian/intern)|v1.0.0|MIT License [json-iterator/go](https://github.com/json-iterator/go)|v1.1.12|MIT License -[klauspost/compress](https://github.com/klauspost/compress)|v1.17.3|Apache License 2.0 +[klauspost/compress](https://github.com/klauspost/compress)|v1.17.8|Apache License 2.0 [mailru/easyjson](https://github.com/mailru/easyjson)|v0.7.7|MIT License [modern-go/concurrent](https://github.com/modern-go/concurrent)|v0.0.0-20180306012644-bacd9c7ef1dd|Apache License 2.0 [modern-go/reflect2](https://github.com/modern-go/reflect2)|v1.0.2|Apache License 2.0 diff --git a/codegen/test/api/things.test.io/v1/clients.go b/codegen/test/api/things.test.io/v1/clients.go index 1f54aadb5..9f7c889c8 100644 --- a/codegen/test/api/things.test.io/v1/clients.go +++ b/codegen/test/api/things.test.io/v1/clients.go @@ -4,89 +4,86 @@ package v1 - - - import ( - "context" - - "github.com/solo-io/skv2/pkg/controllerutils" - "github.com/solo-io/skv2/pkg/multicluster" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" + "context" + + "github.com/solo-io/skv2/pkg/controllerutils" + "github.com/solo-io/skv2/pkg/multicluster" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" ) // MulticlusterClientset for the things.test.io/v1 APIs type MulticlusterClientset interface { - // Cluster returns a Clientset for the given cluster - Cluster(cluster string) (Clientset, error) + // Cluster returns a Clientset for the given cluster + Cluster(cluster string) (Clientset, error) } type multiclusterClientset struct { - client multicluster.Client + client multicluster.Client } func NewMulticlusterClientset(client multicluster.Client) MulticlusterClientset { - return &multiclusterClientset{client: client} + return &multiclusterClientset{client: client} } func (m *multiclusterClientset) Cluster(cluster string) (Clientset, error) { - client, err := m.client.Cluster(cluster) - if err != nil { - return nil, err - } - return NewClientset(client), nil + client, err := m.client.Cluster(cluster) + if err != nil { + return nil, err + } + return NewClientset(client), nil } // clienset for the things.test.io/v1 APIs type Clientset interface { - // clienset for the things.test.io/v1/v1 APIs - Paints() PaintClient - // clienset for the things.test.io/v1/v1 APIs - ClusterResources() ClusterResourceClient + // clienset for the things.test.io/v1/v1 APIs + Paints() PaintClient + // clienset for the things.test.io/v1/v1 APIs + ClusterResources() ClusterResourceClient } type clientSet struct { - client client.Client + client client.Client } func NewClientsetFromConfig(cfg *rest.Config) (Clientset, error) { - scheme := scheme.Scheme - if err := SchemeBuilder.AddToScheme(scheme); err != nil{ - return nil, err - } - client, err := client.New(cfg, client.Options{ - Scheme: scheme, - }) - if err != nil { - return nil, err - } - return NewClientset(client), nil + scheme := scheme.Scheme + if err := SchemeBuilder.AddToScheme(scheme); err != nil { + return nil, err + } + client, err := client.New(cfg, client.Options{ + Scheme: scheme, + }) + if err != nil { + return nil, err + } + return NewClientset(client), nil } func NewClientset(client client.Client) Clientset { - return &clientSet{client: client} + return &clientSet{client: client} } // clienset for the things.test.io/v1/v1 APIs func (c *clientSet) Paints() PaintClient { - return NewPaintClient(c.client) + return NewPaintClient(c.client) } // clienset for the things.test.io/v1/v1 APIs func (c *clientSet) ClusterResources() ClusterResourceClient { - return NewClusterResourceClient(c.client) + return NewClusterResourceClient(c.client) } // Reader knows how to read and list Paints. type PaintReader interface { - // Get retrieves a Paint for the given object key - GetPaint(ctx context.Context, key client.ObjectKey) (*Paint, error) + // Get retrieves a Paint for the given object key + GetPaint(ctx context.Context, key client.ObjectKey) (*Paint, error) - // List retrieves list of Paints for a given namespace and list options. - ListPaint(ctx context.Context, opts ...client.ListOption) (*PaintList, error) + // List retrieves list of Paints for a given namespace and list options. + ListPaint(ctx context.Context, opts ...client.ListOption) (*PaintList, error) } // PaintTransitionFunction instructs the PaintWriter how to transition between an existing @@ -95,142 +92,140 @@ type PaintTransitionFunction func(existing, desired *Paint) error // Writer knows how to create, delete, and update Paints. type PaintWriter interface { - // Create saves the Paint object. - CreatePaint(ctx context.Context, obj *Paint, opts ...client.CreateOption) error + // Create saves the Paint object. + CreatePaint(ctx context.Context, obj *Paint, opts ...client.CreateOption) error - // Delete deletes the Paint object. - DeletePaint(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error + // Delete deletes the Paint object. + DeletePaint(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error - // Update updates the given Paint object. - UpdatePaint(ctx context.Context, obj *Paint, opts ...client.UpdateOption) error + // Update updates the given Paint object. + UpdatePaint(ctx context.Context, obj *Paint, opts ...client.UpdateOption) error - // Patch patches the given Paint object. - PatchPaint(ctx context.Context, obj *Paint, patch client.Patch, opts ...client.PatchOption) error + // Patch patches the given Paint object. + PatchPaint(ctx context.Context, obj *Paint, patch client.Patch, opts ...client.PatchOption) error - // DeleteAllOf deletes all Paint objects matching the given options. - DeleteAllOfPaint(ctx context.Context, opts ...client.DeleteAllOfOption) error + // DeleteAllOf deletes all Paint objects matching the given options. + DeleteAllOfPaint(ctx context.Context, opts ...client.DeleteAllOfOption) error - // Create or Update the Paint object. - UpsertPaint(ctx context.Context, obj *Paint, transitionFuncs ...PaintTransitionFunction) error + // Create or Update the Paint object. + UpsertPaint(ctx context.Context, obj *Paint, transitionFuncs ...PaintTransitionFunction) error } // StatusWriter knows how to update status subresource of a Paint object. type PaintStatusWriter interface { - // Update updates the fields corresponding to the status subresource for the - // given Paint object. - UpdatePaintStatus(ctx context.Context, obj *Paint, opts ...client.SubResourceUpdateOption) error + // Update updates the fields corresponding to the status subresource for the + // given Paint object. + UpdatePaintStatus(ctx context.Context, obj *Paint, opts ...client.SubResourceUpdateOption) error - // Patch patches the given Paint object's subresource. - PatchPaintStatus(ctx context.Context, obj *Paint, patch client.Patch, opts ...client.SubResourcePatchOption) error + // Patch patches the given Paint object's subresource. + PatchPaintStatus(ctx context.Context, obj *Paint, patch client.Patch, opts ...client.SubResourcePatchOption) error } // Client knows how to perform CRUD operations on Paints. type PaintClient interface { - PaintReader - PaintWriter - PaintStatusWriter + PaintReader + PaintWriter + PaintStatusWriter } type paintClient struct { - client client.Client + client client.Client } func NewPaintClient(client client.Client) *paintClient { - return &paintClient{client: client} + return &paintClient{client: client} } - func (c *paintClient) GetPaint(ctx context.Context, key client.ObjectKey) (*Paint, error) { - obj := &Paint{} - if err := c.client.Get(ctx, key, obj); err != nil { - return nil, err - } - return obj, nil + obj := &Paint{} + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil } func (c *paintClient) ListPaint(ctx context.Context, opts ...client.ListOption) (*PaintList, error) { - list := &PaintList{} - if err := c.client.List(ctx, list, opts...); err != nil { - return nil, err - } - return list, nil + list := &PaintList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil } func (c *paintClient) CreatePaint(ctx context.Context, obj *Paint, opts ...client.CreateOption) error { - return c.client.Create(ctx, obj, opts...) + return c.client.Create(ctx, obj, opts...) } - func (c *paintClient) DeletePaint(ctx context.Context, key client.ObjectKey, opts ...client.DeleteOption) error { - obj := &Paint{} - obj.SetName(key.Name) - obj.SetNamespace(key.Namespace) - return c.client.Delete(ctx, obj, opts...) + obj := &Paint{} + obj.SetName(key.Name) + obj.SetNamespace(key.Namespace) + return c.client.Delete(ctx, obj, opts...) } func (c *paintClient) UpdatePaint(ctx context.Context, obj *Paint, opts ...client.UpdateOption) error { - return c.client.Update(ctx, obj, opts...) + return c.client.Update(ctx, obj, opts...) } func (c *paintClient) PatchPaint(ctx context.Context, obj *Paint, patch client.Patch, opts ...client.PatchOption) error { - return c.client.Patch(ctx, obj, patch, opts...) + return c.client.Patch(ctx, obj, patch, opts...) } func (c *paintClient) DeleteAllOfPaint(ctx context.Context, opts ...client.DeleteAllOfOption) error { - obj := &Paint{} - return c.client.DeleteAllOf(ctx, obj, opts...) + obj := &Paint{} + return c.client.DeleteAllOf(ctx, obj, opts...) } func (c *paintClient) UpsertPaint(ctx context.Context, obj *Paint, transitionFuncs ...PaintTransitionFunction) error { - genericTxFunc := func(existing, desired runtime.Object) error { - for _, txFunc := range transitionFuncs { - if err := txFunc(existing.(*Paint), desired.(*Paint)); err != nil { - return err - } - } - return nil - } - _, err := controllerutils.Upsert(ctx, c.client, obj, genericTxFunc) - return err + genericTxFunc := func(existing, desired runtime.Object) error { + for _, txFunc := range transitionFuncs { + if err := txFunc(existing.(*Paint), desired.(*Paint)); err != nil { + return err + } + } + return nil + } + _, err := controllerutils.Upsert(ctx, c.client, obj, genericTxFunc) + return err } func (c *paintClient) UpdatePaintStatus(ctx context.Context, obj *Paint, opts ...client.SubResourceUpdateOption) error { - return c.client.Status().Update(ctx, obj, opts...) + return c.client.Status().Update(ctx, obj, opts...) } func (c *paintClient) PatchPaintStatus(ctx context.Context, obj *Paint, patch client.Patch, opts ...client.SubResourcePatchOption) error { - return c.client.Status().Patch(ctx, obj, patch, opts...) + return c.client.Status().Patch(ctx, obj, patch, opts...) } // Provides PaintClients for multiple clusters. type MulticlusterPaintClient interface { - // Cluster returns a PaintClient for the given cluster - Cluster(cluster string) (PaintClient, error) + // Cluster returns a PaintClient for the given cluster + Cluster(cluster string) (PaintClient, error) } type multiclusterPaintClient struct { - client multicluster.Client + client multicluster.Client } func NewMulticlusterPaintClient(client multicluster.Client) MulticlusterPaintClient { - return &multiclusterPaintClient{client: client} + return &multiclusterPaintClient{client: client} } func (m *multiclusterPaintClient) Cluster(cluster string) (PaintClient, error) { - client, err := m.client.Cluster(cluster) - if err != nil { - return nil, err - } - return NewPaintClient(client), nil + client, err := m.client.Cluster(cluster) + if err != nil { + return nil, err + } + return NewPaintClient(client), nil } // Reader knows how to read and list ClusterResources. type ClusterResourceReader interface { - // Get retrieves a ClusterResource for the given object key - GetClusterResource(ctx context.Context, name string) (*ClusterResource, error) + // Get retrieves a ClusterResource for the given object key + GetClusterResource(ctx context.Context, name string) (*ClusterResource, error) - // List retrieves list of ClusterResources for a given namespace and list options. - ListClusterResource(ctx context.Context, opts ...client.ListOption) (*ClusterResourceList, error) + // List retrieves list of ClusterResources for a given namespace and list options. + ListClusterResource(ctx context.Context, opts ...client.ListOption) (*ClusterResourceList, error) } // ClusterResourceTransitionFunction instructs the ClusterResourceWriter how to transition between an existing @@ -239,133 +234,131 @@ type ClusterResourceTransitionFunction func(existing, desired *ClusterResource) // Writer knows how to create, delete, and update ClusterResources. type ClusterResourceWriter interface { - // Create saves the ClusterResource object. - CreateClusterResource(ctx context.Context, obj *ClusterResource, opts ...client.CreateOption) error + // Create saves the ClusterResource object. + CreateClusterResource(ctx context.Context, obj *ClusterResource, opts ...client.CreateOption) error - // Delete deletes the ClusterResource object. - DeleteClusterResource(ctx context.Context, name string, opts ...client.DeleteOption) error + // Delete deletes the ClusterResource object. + DeleteClusterResource(ctx context.Context, name string, opts ...client.DeleteOption) error - // Update updates the given ClusterResource object. - UpdateClusterResource(ctx context.Context, obj *ClusterResource, opts ...client.UpdateOption) error + // Update updates the given ClusterResource object. + UpdateClusterResource(ctx context.Context, obj *ClusterResource, opts ...client.UpdateOption) error - // Patch patches the given ClusterResource object. - PatchClusterResource(ctx context.Context, obj *ClusterResource, patch client.Patch, opts ...client.PatchOption) error + // Patch patches the given ClusterResource object. + PatchClusterResource(ctx context.Context, obj *ClusterResource, patch client.Patch, opts ...client.PatchOption) error - // DeleteAllOf deletes all ClusterResource objects matching the given options. - DeleteAllOfClusterResource(ctx context.Context, opts ...client.DeleteAllOfOption) error + // DeleteAllOf deletes all ClusterResource objects matching the given options. + DeleteAllOfClusterResource(ctx context.Context, opts ...client.DeleteAllOfOption) error - // Create or Update the ClusterResource object. - UpsertClusterResource(ctx context.Context, obj *ClusterResource, transitionFuncs ...ClusterResourceTransitionFunction) error + // Create or Update the ClusterResource object. + UpsertClusterResource(ctx context.Context, obj *ClusterResource, transitionFuncs ...ClusterResourceTransitionFunction) error } // StatusWriter knows how to update status subresource of a ClusterResource object. type ClusterResourceStatusWriter interface { - // Update updates the fields corresponding to the status subresource for the - // given ClusterResource object. - UpdateClusterResourceStatus(ctx context.Context, obj *ClusterResource, opts ...client.SubResourceUpdateOption) error + // Update updates the fields corresponding to the status subresource for the + // given ClusterResource object. + UpdateClusterResourceStatus(ctx context.Context, obj *ClusterResource, opts ...client.SubResourceUpdateOption) error - // Patch patches the given ClusterResource object's subresource. - PatchClusterResourceStatus(ctx context.Context, obj *ClusterResource, patch client.Patch, opts ...client.SubResourcePatchOption) error + // Patch patches the given ClusterResource object's subresource. + PatchClusterResourceStatus(ctx context.Context, obj *ClusterResource, patch client.Patch, opts ...client.SubResourcePatchOption) error } // Client knows how to perform CRUD operations on ClusterResources. type ClusterResourceClient interface { - ClusterResourceReader - ClusterResourceWriter - ClusterResourceStatusWriter + ClusterResourceReader + ClusterResourceWriter + ClusterResourceStatusWriter } type clusterResourceClient struct { - client client.Client + client client.Client } func NewClusterResourceClient(client client.Client) *clusterResourceClient { - return &clusterResourceClient{client: client} + return &clusterResourceClient{client: client} } - func (c *clusterResourceClient) GetClusterResource(ctx context.Context, name string) (*ClusterResource, error) { - obj := &ClusterResource{} - key := client.ObjectKey{ - Name: name, - } - if err := c.client.Get(ctx, key, obj); err != nil { - return nil, err - } - return obj, nil + obj := &ClusterResource{} + key := client.ObjectKey{ + Name: name, + } + if err := c.client.Get(ctx, key, obj); err != nil { + return nil, err + } + return obj, nil } func (c *clusterResourceClient) ListClusterResource(ctx context.Context, opts ...client.ListOption) (*ClusterResourceList, error) { - list := &ClusterResourceList{} - if err := c.client.List(ctx, list, opts...); err != nil { - return nil, err - } - return list, nil + list := &ClusterResourceList{} + if err := c.client.List(ctx, list, opts...); err != nil { + return nil, err + } + return list, nil } func (c *clusterResourceClient) CreateClusterResource(ctx context.Context, obj *ClusterResource, opts ...client.CreateOption) error { - return c.client.Create(ctx, obj, opts...) + return c.client.Create(ctx, obj, opts...) } - func (c *clusterResourceClient) DeleteClusterResource(ctx context.Context, name string, opts ...client.DeleteOption) error { - obj := &ClusterResource{} - obj.SetName(name) - return c.client.Delete(ctx, obj, opts...) + obj := &ClusterResource{} + obj.SetName(name) + return c.client.Delete(ctx, obj, opts...) } func (c *clusterResourceClient) UpdateClusterResource(ctx context.Context, obj *ClusterResource, opts ...client.UpdateOption) error { - return c.client.Update(ctx, obj, opts...) + return c.client.Update(ctx, obj, opts...) } func (c *clusterResourceClient) PatchClusterResource(ctx context.Context, obj *ClusterResource, patch client.Patch, opts ...client.PatchOption) error { - return c.client.Patch(ctx, obj, patch, opts...) + return c.client.Patch(ctx, obj, patch, opts...) } func (c *clusterResourceClient) DeleteAllOfClusterResource(ctx context.Context, opts ...client.DeleteAllOfOption) error { - obj := &ClusterResource{} - return c.client.DeleteAllOf(ctx, obj, opts...) + obj := &ClusterResource{} + return c.client.DeleteAllOf(ctx, obj, opts...) } func (c *clusterResourceClient) UpsertClusterResource(ctx context.Context, obj *ClusterResource, transitionFuncs ...ClusterResourceTransitionFunction) error { - genericTxFunc := func(existing, desired runtime.Object) error { - for _, txFunc := range transitionFuncs { - if err := txFunc(existing.(*ClusterResource), desired.(*ClusterResource)); err != nil { - return err - } - } - return nil - } - _, err := controllerutils.Upsert(ctx, c.client, obj, genericTxFunc) - return err + genericTxFunc := func(existing, desired runtime.Object) error { + for _, txFunc := range transitionFuncs { + if err := txFunc(existing.(*ClusterResource), desired.(*ClusterResource)); err != nil { + return err + } + } + return nil + } + _, err := controllerutils.Upsert(ctx, c.client, obj, genericTxFunc) + return err } func (c *clusterResourceClient) UpdateClusterResourceStatus(ctx context.Context, obj *ClusterResource, opts ...client.SubResourceUpdateOption) error { - return c.client.Status().Update(ctx, obj, opts...) + return c.client.Status().Update(ctx, obj, opts...) } func (c *clusterResourceClient) PatchClusterResourceStatus(ctx context.Context, obj *ClusterResource, patch client.Patch, opts ...client.SubResourcePatchOption) error { - return c.client.Status().Patch(ctx, obj, patch, opts...) + return c.client.Status().Patch(ctx, obj, patch, opts...) } // Provides ClusterResourceClients for multiple clusters. type MulticlusterClusterResourceClient interface { - // Cluster returns a ClusterResourceClient for the given cluster - Cluster(cluster string) (ClusterResourceClient, error) + // Cluster returns a ClusterResourceClient for the given cluster + Cluster(cluster string) (ClusterResourceClient, error) } type multiclusterClusterResourceClient struct { - client multicluster.Client + client multicluster.Client } func NewMulticlusterClusterResourceClient(client multicluster.Client) MulticlusterClusterResourceClient { - return &multiclusterClusterResourceClient{client: client} + return &multiclusterClusterResourceClient{client: client} } func (m *multiclusterClusterResourceClient) Cluster(cluster string) (ClusterResourceClient, error) { - client, err := m.client.Cluster(cluster) - if err != nil { - return nil, err - } - return NewClusterResourceClient(client), nil -} \ No newline at end of file + client, err := m.client.Cluster(cluster) + if err != nil { + return nil, err + } + return NewClusterResourceClient(client), nil +} diff --git a/codegen/test/api/things.test.io/v1/controller/event_handlers.go b/codegen/test/api/things.test.io/v1/controller/event_handlers.go index 066691b25..3c52ed1f6 100644 --- a/codegen/test/api/things.test.io/v1/controller/event_handlers.go +++ b/codegen/test/api/things.test.io/v1/controller/event_handlers.go @@ -8,225 +8,225 @@ package controller import ( "context" - things_test_io_v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" + things_test_io_v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" - "github.com/pkg/errors" - "github.com/solo-io/skv2/pkg/events" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/pkg/errors" + "github.com/solo-io/skv2/pkg/events" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/predicate" ) // Handle events for the Paint Resource // DEPRECATED: Prefer reconciler pattern. type PaintEventHandler interface { - CreatePaint(obj *things_test_io_v1.Paint) error - UpdatePaint(old, new *things_test_io_v1.Paint) error - DeletePaint(obj *things_test_io_v1.Paint) error - GenericPaint(obj *things_test_io_v1.Paint) error + CreatePaint(obj *things_test_io_v1.Paint) error + UpdatePaint(old, new *things_test_io_v1.Paint) error + DeletePaint(obj *things_test_io_v1.Paint) error + GenericPaint(obj *things_test_io_v1.Paint) error } type PaintEventHandlerFuncs struct { - OnCreate func(obj *things_test_io_v1.Paint) error - OnUpdate func(old, new *things_test_io_v1.Paint) error - OnDelete func(obj *things_test_io_v1.Paint) error - OnGeneric func(obj *things_test_io_v1.Paint) error + OnCreate func(obj *things_test_io_v1.Paint) error + OnUpdate func(old, new *things_test_io_v1.Paint) error + OnDelete func(obj *things_test_io_v1.Paint) error + OnGeneric func(obj *things_test_io_v1.Paint) error } func (f *PaintEventHandlerFuncs) CreatePaint(obj *things_test_io_v1.Paint) error { - if f.OnCreate == nil { - return nil - } - return f.OnCreate(obj) + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) } func (f *PaintEventHandlerFuncs) DeletePaint(obj *things_test_io_v1.Paint) error { - if f.OnDelete == nil { - return nil - } - return f.OnDelete(obj) + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) } func (f *PaintEventHandlerFuncs) UpdatePaint(objOld, objNew *things_test_io_v1.Paint) error { - if f.OnUpdate == nil { - return nil - } - return f.OnUpdate(objOld, objNew) + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) } func (f *PaintEventHandlerFuncs) GenericPaint(obj *things_test_io_v1.Paint) error { - if f.OnGeneric == nil { - return nil - } - return f.OnGeneric(obj) + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) } type PaintEventWatcher interface { - AddEventHandler(ctx context.Context, h PaintEventHandler, predicates ...predicate.Predicate) error + AddEventHandler(ctx context.Context, h PaintEventHandler, predicates ...predicate.Predicate) error } type paintEventWatcher struct { - watcher events.EventWatcher + watcher events.EventWatcher } func NewPaintEventWatcher(name string, mgr manager.Manager) PaintEventWatcher { - return &paintEventWatcher{ - watcher: events.NewWatcher(name, mgr, &things_test_io_v1.Paint{}), - } + return &paintEventWatcher{ + watcher: events.NewWatcher(name, mgr, &things_test_io_v1.Paint{}), + } } func (c *paintEventWatcher) AddEventHandler(ctx context.Context, h PaintEventHandler, predicates ...predicate.Predicate) error { handler := genericPaintHandler{handler: h} - if err := c.watcher.Watch(ctx, handler, predicates...); err != nil{ - return err - } - return nil + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil } // genericPaintHandler implements a generic events.EventHandler type genericPaintHandler struct { - handler PaintEventHandler + handler PaintEventHandler } func (h genericPaintHandler) Create(object client.Object) error { - obj, ok := object.(*things_test_io_v1.Paint) - if !ok { - return errors.Errorf("internal error: Paint handler received event for %T", object) - } - return h.handler.CreatePaint(obj) + obj, ok := object.(*things_test_io_v1.Paint) + if !ok { + return errors.Errorf("internal error: Paint handler received event for %T", object) + } + return h.handler.CreatePaint(obj) } func (h genericPaintHandler) Delete(object client.Object) error { - obj, ok := object.(*things_test_io_v1.Paint) - if !ok { - return errors.Errorf("internal error: Paint handler received event for %T", object) - } - return h.handler.DeletePaint(obj) + obj, ok := object.(*things_test_io_v1.Paint) + if !ok { + return errors.Errorf("internal error: Paint handler received event for %T", object) + } + return h.handler.DeletePaint(obj) } func (h genericPaintHandler) Update(old, new client.Object) error { - objOld, ok := old.(*things_test_io_v1.Paint) - if !ok { - return errors.Errorf("internal error: Paint handler received event for %T", old) - } - objNew, ok := new.(*things_test_io_v1.Paint) - if !ok { - return errors.Errorf("internal error: Paint handler received event for %T", new) - } - return h.handler.UpdatePaint(objOld, objNew) + objOld, ok := old.(*things_test_io_v1.Paint) + if !ok { + return errors.Errorf("internal error: Paint handler received event for %T", old) + } + objNew, ok := new.(*things_test_io_v1.Paint) + if !ok { + return errors.Errorf("internal error: Paint handler received event for %T", new) + } + return h.handler.UpdatePaint(objOld, objNew) } func (h genericPaintHandler) Generic(object client.Object) error { - obj, ok := object.(*things_test_io_v1.Paint) - if !ok { - return errors.Errorf("internal error: Paint handler received event for %T", object) - } - return h.handler.GenericPaint(obj) + obj, ok := object.(*things_test_io_v1.Paint) + if !ok { + return errors.Errorf("internal error: Paint handler received event for %T", object) + } + return h.handler.GenericPaint(obj) } // Handle events for the ClusterResource Resource // DEPRECATED: Prefer reconciler pattern. type ClusterResourceEventHandler interface { - CreateClusterResource(obj *things_test_io_v1.ClusterResource) error - UpdateClusterResource(old, new *things_test_io_v1.ClusterResource) error - DeleteClusterResource(obj *things_test_io_v1.ClusterResource) error - GenericClusterResource(obj *things_test_io_v1.ClusterResource) error + CreateClusterResource(obj *things_test_io_v1.ClusterResource) error + UpdateClusterResource(old, new *things_test_io_v1.ClusterResource) error + DeleteClusterResource(obj *things_test_io_v1.ClusterResource) error + GenericClusterResource(obj *things_test_io_v1.ClusterResource) error } type ClusterResourceEventHandlerFuncs struct { - OnCreate func(obj *things_test_io_v1.ClusterResource) error - OnUpdate func(old, new *things_test_io_v1.ClusterResource) error - OnDelete func(obj *things_test_io_v1.ClusterResource) error - OnGeneric func(obj *things_test_io_v1.ClusterResource) error + OnCreate func(obj *things_test_io_v1.ClusterResource) error + OnUpdate func(old, new *things_test_io_v1.ClusterResource) error + OnDelete func(obj *things_test_io_v1.ClusterResource) error + OnGeneric func(obj *things_test_io_v1.ClusterResource) error } func (f *ClusterResourceEventHandlerFuncs) CreateClusterResource(obj *things_test_io_v1.ClusterResource) error { - if f.OnCreate == nil { - return nil - } - return f.OnCreate(obj) + if f.OnCreate == nil { + return nil + } + return f.OnCreate(obj) } func (f *ClusterResourceEventHandlerFuncs) DeleteClusterResource(obj *things_test_io_v1.ClusterResource) error { - if f.OnDelete == nil { - return nil - } - return f.OnDelete(obj) + if f.OnDelete == nil { + return nil + } + return f.OnDelete(obj) } func (f *ClusterResourceEventHandlerFuncs) UpdateClusterResource(objOld, objNew *things_test_io_v1.ClusterResource) error { - if f.OnUpdate == nil { - return nil - } - return f.OnUpdate(objOld, objNew) + if f.OnUpdate == nil { + return nil + } + return f.OnUpdate(objOld, objNew) } func (f *ClusterResourceEventHandlerFuncs) GenericClusterResource(obj *things_test_io_v1.ClusterResource) error { - if f.OnGeneric == nil { - return nil - } - return f.OnGeneric(obj) + if f.OnGeneric == nil { + return nil + } + return f.OnGeneric(obj) } type ClusterResourceEventWatcher interface { - AddEventHandler(ctx context.Context, h ClusterResourceEventHandler, predicates ...predicate.Predicate) error + AddEventHandler(ctx context.Context, h ClusterResourceEventHandler, predicates ...predicate.Predicate) error } type clusterResourceEventWatcher struct { - watcher events.EventWatcher + watcher events.EventWatcher } func NewClusterResourceEventWatcher(name string, mgr manager.Manager) ClusterResourceEventWatcher { - return &clusterResourceEventWatcher{ - watcher: events.NewWatcher(name, mgr, &things_test_io_v1.ClusterResource{}), - } + return &clusterResourceEventWatcher{ + watcher: events.NewWatcher(name, mgr, &things_test_io_v1.ClusterResource{}), + } } func (c *clusterResourceEventWatcher) AddEventHandler(ctx context.Context, h ClusterResourceEventHandler, predicates ...predicate.Predicate) error { handler := genericClusterResourceHandler{handler: h} - if err := c.watcher.Watch(ctx, handler, predicates...); err != nil{ - return err - } - return nil + if err := c.watcher.Watch(ctx, handler, predicates...); err != nil { + return err + } + return nil } // genericClusterResourceHandler implements a generic events.EventHandler type genericClusterResourceHandler struct { - handler ClusterResourceEventHandler + handler ClusterResourceEventHandler } func (h genericClusterResourceHandler) Create(object client.Object) error { - obj, ok := object.(*things_test_io_v1.ClusterResource) - if !ok { - return errors.Errorf("internal error: ClusterResource handler received event for %T", object) - } - return h.handler.CreateClusterResource(obj) + obj, ok := object.(*things_test_io_v1.ClusterResource) + if !ok { + return errors.Errorf("internal error: ClusterResource handler received event for %T", object) + } + return h.handler.CreateClusterResource(obj) } func (h genericClusterResourceHandler) Delete(object client.Object) error { - obj, ok := object.(*things_test_io_v1.ClusterResource) - if !ok { - return errors.Errorf("internal error: ClusterResource handler received event for %T", object) - } - return h.handler.DeleteClusterResource(obj) + obj, ok := object.(*things_test_io_v1.ClusterResource) + if !ok { + return errors.Errorf("internal error: ClusterResource handler received event for %T", object) + } + return h.handler.DeleteClusterResource(obj) } func (h genericClusterResourceHandler) Update(old, new client.Object) error { - objOld, ok := old.(*things_test_io_v1.ClusterResource) - if !ok { - return errors.Errorf("internal error: ClusterResource handler received event for %T", old) - } - objNew, ok := new.(*things_test_io_v1.ClusterResource) - if !ok { - return errors.Errorf("internal error: ClusterResource handler received event for %T", new) - } - return h.handler.UpdateClusterResource(objOld, objNew) + objOld, ok := old.(*things_test_io_v1.ClusterResource) + if !ok { + return errors.Errorf("internal error: ClusterResource handler received event for %T", old) + } + objNew, ok := new.(*things_test_io_v1.ClusterResource) + if !ok { + return errors.Errorf("internal error: ClusterResource handler received event for %T", new) + } + return h.handler.UpdateClusterResource(objOld, objNew) } func (h genericClusterResourceHandler) Generic(object client.Object) error { - obj, ok := object.(*things_test_io_v1.ClusterResource) - if !ok { - return errors.Errorf("internal error: ClusterResource handler received event for %T", object) - } - return h.handler.GenericClusterResource(obj) + obj, ok := object.(*things_test_io_v1.ClusterResource) + if !ok { + return errors.Errorf("internal error: ClusterResource handler received event for %T", object) + } + return h.handler.GenericClusterResource(obj) } diff --git a/codegen/test/api/things.test.io/v1/controller/multicluster_reconcilers.go b/codegen/test/api/things.test.io/v1/controller/multicluster_reconcilers.go index 237ee95a0..fbfe2e86e 100644 --- a/codegen/test/api/things.test.io/v1/controller/multicluster_reconcilers.go +++ b/codegen/test/api/things.test.io/v1/controller/multicluster_reconcilers.go @@ -5,8 +5,6 @@ // Definitions for the multicluster Kubernetes Controllers package controller - - import ( "context" diff --git a/codegen/test/api/things.test.io/v1/controller/reconcilers.go b/codegen/test/api/things.test.io/v1/controller/reconcilers.go index a04151fb4..355e61896 100644 --- a/codegen/test/api/things.test.io/v1/controller/reconcilers.go +++ b/codegen/test/api/things.test.io/v1/controller/reconcilers.go @@ -5,24 +5,22 @@ // Definitions for the Kubernetes Controllers package controller - - import ( "context" - things_test_io_v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" + things_test_io_v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" - "github.com/pkg/errors" - "github.com/solo-io/skv2/pkg/ezkube" - "github.com/solo-io/skv2/pkg/reconcile" - "sigs.k8s.io/controller-runtime/pkg/manager" - "sigs.k8s.io/controller-runtime/pkg/predicate" + "github.com/pkg/errors" + "github.com/solo-io/skv2/pkg/ezkube" + "github.com/solo-io/skv2/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/predicate" ) // Reconcile Upsert events for the Paint Resource. // implemented by the user type PaintReconciler interface { - ReconcilePaint(obj *things_test_io_v1.Paint) (reconcile.Result, error) + ReconcilePaint(obj *things_test_io_v1.Paint) (reconcile.Result, error) } // Reconcile deletion events for the Paint Resource. @@ -30,117 +28,116 @@ type PaintReconciler interface { // before being deleted. // implemented by the user type PaintDeletionReconciler interface { - ReconcilePaintDeletion(req reconcile.Request) error + ReconcilePaintDeletion(req reconcile.Request) error } type PaintReconcilerFuncs struct { - OnReconcilePaint func(obj *things_test_io_v1.Paint) (reconcile.Result, error) - OnReconcilePaintDeletion func(req reconcile.Request) error + OnReconcilePaint func(obj *things_test_io_v1.Paint) (reconcile.Result, error) + OnReconcilePaintDeletion func(req reconcile.Request) error } func (f *PaintReconcilerFuncs) ReconcilePaint(obj *things_test_io_v1.Paint) (reconcile.Result, error) { - if f.OnReconcilePaint == nil { - return reconcile.Result{}, nil - } - return f.OnReconcilePaint(obj) + if f.OnReconcilePaint == nil { + return reconcile.Result{}, nil + } + return f.OnReconcilePaint(obj) } func (f *PaintReconcilerFuncs) ReconcilePaintDeletion(req reconcile.Request) error { - if f.OnReconcilePaintDeletion == nil { - return nil - } - return f.OnReconcilePaintDeletion(req) + if f.OnReconcilePaintDeletion == nil { + return nil + } + return f.OnReconcilePaintDeletion(req) } // Reconcile and finalize the Paint Resource // implemented by the user type PaintFinalizer interface { - PaintReconciler + PaintReconciler - // name of the finalizer used by this handler. - // finalizer names should be unique for a single task - PaintFinalizerName() string + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + PaintFinalizerName() string - // finalize the object before it is deleted. - // Watchers created with a finalizing handler will a - FinalizePaint(obj *things_test_io_v1.Paint) error + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizePaint(obj *things_test_io_v1.Paint) error } type PaintReconcileLoop interface { - RunPaintReconciler(ctx context.Context, rec PaintReconciler, predicates ...predicate.Predicate) error + RunPaintReconciler(ctx context.Context, rec PaintReconciler, predicates ...predicate.Predicate) error } type paintReconcileLoop struct { - loop reconcile.Loop + loop reconcile.Loop } func NewPaintReconcileLoop(name string, mgr manager.Manager, options reconcile.Options) PaintReconcileLoop { - return &paintReconcileLoop{ - // empty cluster indicates this reconciler is built for the local cluster - loop: reconcile.NewLoop(name, "", mgr, &things_test_io_v1.Paint{}, options), - } + return &paintReconcileLoop{ + // empty cluster indicates this reconciler is built for the local cluster + loop: reconcile.NewLoop(name, "", mgr, &things_test_io_v1.Paint{}, options), + } } func (c *paintReconcileLoop) RunPaintReconciler(ctx context.Context, reconciler PaintReconciler, predicates ...predicate.Predicate) error { - genericReconciler := genericPaintReconciler{ - reconciler: reconciler, - } + genericReconciler := genericPaintReconciler{ + reconciler: reconciler, + } var reconcilerWrapper reconcile.Reconciler if finalizingReconciler, ok := reconciler.(PaintFinalizer); ok { - reconcilerWrapper = genericPaintFinalizer{ - genericPaintReconciler: genericReconciler, - finalizingReconciler: finalizingReconciler, - } - } else { - reconcilerWrapper = genericReconciler - } + reconcilerWrapper = genericPaintFinalizer{ + genericPaintReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) } // genericPaintHandler implements a generic reconcile.Reconciler type genericPaintReconciler struct { - reconciler PaintReconciler + reconciler PaintReconciler } func (r genericPaintReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { - obj, ok := object.(*things_test_io_v1.Paint) - if !ok { - return reconcile.Result{}, errors.Errorf("internal error: Paint handler received event for %T", object) - } - return r.reconciler.ReconcilePaint(obj) + obj, ok := object.(*things_test_io_v1.Paint) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: Paint handler received event for %T", object) + } + return r.reconciler.ReconcilePaint(obj) } func (r genericPaintReconciler) ReconcileDeletion(request reconcile.Request) error { - if deletionReconciler, ok := r.reconciler.(PaintDeletionReconciler); ok { - return deletionReconciler.ReconcilePaintDeletion(request) - } - return nil + if deletionReconciler, ok := r.reconciler.(PaintDeletionReconciler); ok { + return deletionReconciler.ReconcilePaintDeletion(request) + } + return nil } // genericPaintFinalizer implements a generic reconcile.FinalizingReconciler type genericPaintFinalizer struct { - genericPaintReconciler - finalizingReconciler PaintFinalizer + genericPaintReconciler + finalizingReconciler PaintFinalizer } - func (r genericPaintFinalizer) FinalizerName() string { - return r.finalizingReconciler.PaintFinalizerName() + return r.finalizingReconciler.PaintFinalizerName() } func (r genericPaintFinalizer) Finalize(object ezkube.Object) error { - obj, ok := object.(*things_test_io_v1.Paint) - if !ok { - return errors.Errorf("internal error: Paint handler received event for %T", object) - } - return r.finalizingReconciler.FinalizePaint(obj) + obj, ok := object.(*things_test_io_v1.Paint) + if !ok { + return errors.Errorf("internal error: Paint handler received event for %T", object) + } + return r.finalizingReconciler.FinalizePaint(obj) } // Reconcile Upsert events for the ClusterResource Resource. // implemented by the user type ClusterResourceReconciler interface { - ReconcileClusterResource(obj *things_test_io_v1.ClusterResource) (reconcile.Result, error) + ReconcileClusterResource(obj *things_test_io_v1.ClusterResource) (reconcile.Result, error) } // Reconcile deletion events for the ClusterResource Resource. @@ -148,109 +145,108 @@ type ClusterResourceReconciler interface { // before being deleted. // implemented by the user type ClusterResourceDeletionReconciler interface { - ReconcileClusterResourceDeletion(req reconcile.Request) error + ReconcileClusterResourceDeletion(req reconcile.Request) error } type ClusterResourceReconcilerFuncs struct { - OnReconcileClusterResource func(obj *things_test_io_v1.ClusterResource) (reconcile.Result, error) - OnReconcileClusterResourceDeletion func(req reconcile.Request) error + OnReconcileClusterResource func(obj *things_test_io_v1.ClusterResource) (reconcile.Result, error) + OnReconcileClusterResourceDeletion func(req reconcile.Request) error } func (f *ClusterResourceReconcilerFuncs) ReconcileClusterResource(obj *things_test_io_v1.ClusterResource) (reconcile.Result, error) { - if f.OnReconcileClusterResource == nil { - return reconcile.Result{}, nil - } - return f.OnReconcileClusterResource(obj) + if f.OnReconcileClusterResource == nil { + return reconcile.Result{}, nil + } + return f.OnReconcileClusterResource(obj) } func (f *ClusterResourceReconcilerFuncs) ReconcileClusterResourceDeletion(req reconcile.Request) error { - if f.OnReconcileClusterResourceDeletion == nil { - return nil - } - return f.OnReconcileClusterResourceDeletion(req) + if f.OnReconcileClusterResourceDeletion == nil { + return nil + } + return f.OnReconcileClusterResourceDeletion(req) } // Reconcile and finalize the ClusterResource Resource // implemented by the user type ClusterResourceFinalizer interface { - ClusterResourceReconciler + ClusterResourceReconciler - // name of the finalizer used by this handler. - // finalizer names should be unique for a single task - ClusterResourceFinalizerName() string + // name of the finalizer used by this handler. + // finalizer names should be unique for a single task + ClusterResourceFinalizerName() string - // finalize the object before it is deleted. - // Watchers created with a finalizing handler will a - FinalizeClusterResource(obj *things_test_io_v1.ClusterResource) error + // finalize the object before it is deleted. + // Watchers created with a finalizing handler will a + FinalizeClusterResource(obj *things_test_io_v1.ClusterResource) error } type ClusterResourceReconcileLoop interface { - RunClusterResourceReconciler(ctx context.Context, rec ClusterResourceReconciler, predicates ...predicate.Predicate) error + RunClusterResourceReconciler(ctx context.Context, rec ClusterResourceReconciler, predicates ...predicate.Predicate) error } type clusterResourceReconcileLoop struct { - loop reconcile.Loop + loop reconcile.Loop } func NewClusterResourceReconcileLoop(name string, mgr manager.Manager, options reconcile.Options) ClusterResourceReconcileLoop { - return &clusterResourceReconcileLoop{ - // empty cluster indicates this reconciler is built for the local cluster - loop: reconcile.NewLoop(name, "", mgr, &things_test_io_v1.ClusterResource{}, options), - } + return &clusterResourceReconcileLoop{ + // empty cluster indicates this reconciler is built for the local cluster + loop: reconcile.NewLoop(name, "", mgr, &things_test_io_v1.ClusterResource{}, options), + } } func (c *clusterResourceReconcileLoop) RunClusterResourceReconciler(ctx context.Context, reconciler ClusterResourceReconciler, predicates ...predicate.Predicate) error { - genericReconciler := genericClusterResourceReconciler{ - reconciler: reconciler, - } + genericReconciler := genericClusterResourceReconciler{ + reconciler: reconciler, + } var reconcilerWrapper reconcile.Reconciler if finalizingReconciler, ok := reconciler.(ClusterResourceFinalizer); ok { - reconcilerWrapper = genericClusterResourceFinalizer{ - genericClusterResourceReconciler: genericReconciler, - finalizingReconciler: finalizingReconciler, - } - } else { - reconcilerWrapper = genericReconciler - } + reconcilerWrapper = genericClusterResourceFinalizer{ + genericClusterResourceReconciler: genericReconciler, + finalizingReconciler: finalizingReconciler, + } + } else { + reconcilerWrapper = genericReconciler + } return c.loop.RunReconciler(ctx, reconcilerWrapper, predicates...) } // genericClusterResourceHandler implements a generic reconcile.Reconciler type genericClusterResourceReconciler struct { - reconciler ClusterResourceReconciler + reconciler ClusterResourceReconciler } func (r genericClusterResourceReconciler) Reconcile(object ezkube.Object) (reconcile.Result, error) { - obj, ok := object.(*things_test_io_v1.ClusterResource) - if !ok { - return reconcile.Result{}, errors.Errorf("internal error: ClusterResource handler received event for %T", object) - } - return r.reconciler.ReconcileClusterResource(obj) + obj, ok := object.(*things_test_io_v1.ClusterResource) + if !ok { + return reconcile.Result{}, errors.Errorf("internal error: ClusterResource handler received event for %T", object) + } + return r.reconciler.ReconcileClusterResource(obj) } func (r genericClusterResourceReconciler) ReconcileDeletion(request reconcile.Request) error { - if deletionReconciler, ok := r.reconciler.(ClusterResourceDeletionReconciler); ok { - return deletionReconciler.ReconcileClusterResourceDeletion(request) - } - return nil + if deletionReconciler, ok := r.reconciler.(ClusterResourceDeletionReconciler); ok { + return deletionReconciler.ReconcileClusterResourceDeletion(request) + } + return nil } // genericClusterResourceFinalizer implements a generic reconcile.FinalizingReconciler type genericClusterResourceFinalizer struct { - genericClusterResourceReconciler - finalizingReconciler ClusterResourceFinalizer + genericClusterResourceReconciler + finalizingReconciler ClusterResourceFinalizer } - func (r genericClusterResourceFinalizer) FinalizerName() string { - return r.finalizingReconciler.ClusterResourceFinalizerName() + return r.finalizingReconciler.ClusterResourceFinalizerName() } func (r genericClusterResourceFinalizer) Finalize(object ezkube.Object) error { - obj, ok := object.(*things_test_io_v1.ClusterResource) - if !ok { - return errors.Errorf("internal error: ClusterResource handler received event for %T", object) - } - return r.finalizingReconciler.FinalizeClusterResource(obj) + obj, ok := object.(*things_test_io_v1.ClusterResource) + if !ok { + return errors.Errorf("internal error: ClusterResource handler received event for %T", object) + } + return r.finalizingReconciler.FinalizeClusterResource(obj) } diff --git a/codegen/test/api/things.test.io/v1/json.gen.go b/codegen/test/api/things.test.io/v1/json.gen.go index d7582f228..d8b4c1b0b 100644 --- a/codegen/test/api/things.test.io/v1/json.gen.go +++ b/codegen/test/api/things.test.io/v1/json.gen.go @@ -5,13 +5,13 @@ package v1 import ( - bytes "bytes" - fmt "fmt" - math "math" + bytes "bytes" + fmt "fmt" + math "math" - skv2jsonpb "github.com/solo-io/skv2/pkg/kube_jsonpb" - jsonpb "github.com/golang/protobuf/jsonpb" - proto "github.com/golang/protobuf/proto" + jsonpb "github.com/golang/protobuf/jsonpb" + proto "github.com/golang/protobuf/proto" + skv2jsonpb "github.com/solo-io/skv2/pkg/kube_jsonpb" ) // Reference imports to suppress errors if they are not otherwise used. @@ -20,12 +20,13 @@ var _ = fmt.Errorf var _ = math.Inf var ( - marshaller = &skv2jsonpb.Marshaler{} + marshaller = &skv2jsonpb.Marshaler{} unmarshaller = &jsonpb.Unmarshaler{ AllowUnknownFields: true, } strictUnmarshaller = &jsonpb.Unmarshaler{} ) + // MarshalJSON is a custom marshaler for PaintSpec func (this *PaintSpec) MarshalJSON() ([]byte, error) { str, err := marshaller.MarshalToString(this) @@ -36,6 +37,7 @@ func (this *PaintSpec) MarshalJSON() ([]byte, error) { func (this *PaintSpec) UnmarshalJSON(b []byte) error { return unmarshaller.Unmarshal(bytes.NewReader(b), this) } + // MarshalJSON is a custom marshaler for PaintStatus func (this *PaintStatus) MarshalJSON() ([]byte, error) { str, err := marshaller.MarshalToString(this) @@ -46,6 +48,7 @@ func (this *PaintStatus) MarshalJSON() ([]byte, error) { func (this *PaintStatus) UnmarshalJSON(b []byte) error { return unmarshaller.Unmarshal(bytes.NewReader(b), this) } + // MarshalJSON is a custom marshaler for ClusterResourceSpec func (this *ClusterResourceSpec) MarshalJSON() ([]byte, error) { str, err := marshaller.MarshalToString(this) diff --git a/codegen/test/api/things.test.io/v1/proto_deepcopy.go b/codegen/test/api/things.test.io/v1/proto_deepcopy.go index 30d4d08c0..7fe7a023f 100644 --- a/codegen/test/api/things.test.io/v1/proto_deepcopy.go +++ b/codegen/test/api/things.test.io/v1/proto_deepcopy.go @@ -5,36 +5,39 @@ package v1 import ( - proto "github.com/golang/protobuf/proto" + proto "github.com/golang/protobuf/proto" "github.com/solo-io/protoc-gen-ext/pkg/clone" ) + // DeepCopyInto for the Paint.Spec func (in *PaintSpec) DeepCopyInto(out *PaintSpec) { - var p *PaintSpec - if h, ok := interface{}(in).(clone.Cloner); ok { - p = h.Clone().(*PaintSpec) - } else { - p = proto.Clone(in).(*PaintSpec) - } - *out = *p + var p *PaintSpec + if h, ok := interface{}(in).(clone.Cloner); ok { + p = h.Clone().(*PaintSpec) + } else { + p = proto.Clone(in).(*PaintSpec) + } + *out = *p } + // DeepCopyInto for the Paint.Status func (in *PaintStatus) DeepCopyInto(out *PaintStatus) { - var p *PaintStatus - if h, ok := interface{}(in).(clone.Cloner); ok { - p = h.Clone().(*PaintStatus) - } else { - p = proto.Clone(in).(*PaintStatus) - } - *out = *p + var p *PaintStatus + if h, ok := interface{}(in).(clone.Cloner); ok { + p = h.Clone().(*PaintStatus) + } else { + p = proto.Clone(in).(*PaintStatus) + } + *out = *p } + // DeepCopyInto for the ClusterResource.Spec func (in *ClusterResourceSpec) DeepCopyInto(out *ClusterResourceSpec) { - var p *ClusterResourceSpec - if h, ok := interface{}(in).(clone.Cloner); ok { - p = h.Clone().(*ClusterResourceSpec) - } else { - p = proto.Clone(in).(*ClusterResourceSpec) - } - *out = *p + var p *ClusterResourceSpec + if h, ok := interface{}(in).(clone.Cloner); ok { + p = h.Clone().(*ClusterResourceSpec) + } else { + p = proto.Clone(in).(*ClusterResourceSpec) + } + *out = *p } diff --git a/codegen/test/api/things.test.io/v1/providers/client_providers.go b/codegen/test/api/things.test.io/v1/providers/client_providers.go index 53570c869..ea1c91a28 100644 --- a/codegen/test/api/things.test.io/v1/providers/client_providers.go +++ b/codegen/test/api/things.test.io/v1/providers/client_providers.go @@ -2,13 +2,11 @@ package v1 - - import ( - things_test_io_v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" + things_test_io_v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" - "k8s.io/client-go/rest" - "sigs.k8s.io/controller-runtime/pkg/client" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" ) /* @@ -21,56 +19,56 @@ import ( // Provider for PaintClient from Clientset func PaintClientFromClientsetProvider(clients things_test_io_v1.Clientset) things_test_io_v1.PaintClient { - return clients.Paints() + return clients.Paints() } // Provider for Paint Client from Client func PaintClientProvider(client client.Client) things_test_io_v1.PaintClient { - return things_test_io_v1.NewPaintClient(client) + return things_test_io_v1.NewPaintClient(client) } type PaintClientFactory func(client client.Client) things_test_io_v1.PaintClient func PaintClientFactoryProvider() PaintClientFactory { - return PaintClientProvider + return PaintClientProvider } type PaintClientFromConfigFactory func(cfg *rest.Config) (things_test_io_v1.PaintClient, error) func PaintClientFromConfigFactoryProvider() PaintClientFromConfigFactory { - return func(cfg *rest.Config) (things_test_io_v1.PaintClient, error) { - clients, err := things_test_io_v1.NewClientsetFromConfig(cfg) - if err != nil { - return nil, err - } - return clients.Paints(), nil - } + return func(cfg *rest.Config) (things_test_io_v1.PaintClient, error) { + clients, err := things_test_io_v1.NewClientsetFromConfig(cfg) + if err != nil { + return nil, err + } + return clients.Paints(), nil + } } // Provider for ClusterResourceClient from Clientset func ClusterResourceClientFromClientsetProvider(clients things_test_io_v1.Clientset) things_test_io_v1.ClusterResourceClient { - return clients.ClusterResources() + return clients.ClusterResources() } // Provider for ClusterResource Client from Client func ClusterResourceClientProvider(client client.Client) things_test_io_v1.ClusterResourceClient { - return things_test_io_v1.NewClusterResourceClient(client) + return things_test_io_v1.NewClusterResourceClient(client) } type ClusterResourceClientFactory func(client client.Client) things_test_io_v1.ClusterResourceClient func ClusterResourceClientFactoryProvider() ClusterResourceClientFactory { - return ClusterResourceClientProvider + return ClusterResourceClientProvider } type ClusterResourceClientFromConfigFactory func(cfg *rest.Config) (things_test_io_v1.ClusterResourceClient, error) func ClusterResourceClientFromConfigFactoryProvider() ClusterResourceClientFromConfigFactory { - return func(cfg *rest.Config) (things_test_io_v1.ClusterResourceClient, error) { - clients, err := things_test_io_v1.NewClientsetFromConfig(cfg) - if err != nil { - return nil, err - } - return clients.ClusterResources(), nil - } -} \ No newline at end of file + return func(cfg *rest.Config) (things_test_io_v1.ClusterResourceClient, error) { + clients, err := things_test_io_v1.NewClientsetFromConfig(cfg) + if err != nil { + return nil, err + } + return clients.ClusterResources(), nil + } +} diff --git a/codegen/test/api/things.test.io/v1/register.go b/codegen/test/api/things.test.io/v1/register.go index 99e1def72..38bbf15c1 100644 --- a/codegen/test/api/things.test.io/v1/register.go +++ b/codegen/test/api/things.test.io/v1/register.go @@ -6,9 +6,9 @@ package v1 import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" - "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" ) // AddToSchemes may be used to add all resources defined in the project to a Scheme @@ -16,19 +16,18 @@ import ( // AddToScheme adds all Resources to the Scheme var ( - // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "things.test.io", Version: "v1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "things.test.io", Version: "v1"} + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} ) // Resource takes an unqualified resource and returns a Group qualified GroupResource func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() + return SchemeGroupVersion.WithResource(resource).GroupResource() } func AddToScheme(s *runtime.Scheme) error { - return SchemeBuilder.AddToScheme(s) + return SchemeBuilder.AddToScheme(s) } diff --git a/codegen/test/api/things.test.io/v1/sets/sets.go b/codegen/test/api/things.test.io/v1/sets/sets.go index 8e9cb54fb..73703a3cd 100644 --- a/codegen/test/api/things.test.io/v1/sets/sets.go +++ b/codegen/test/api/things.test.io/v1/sets/sets.go @@ -4,232 +4,229 @@ package v1sets - - import ( - things_test_io_v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" + things_test_io_v1 "github.com/solo-io/skv2/codegen/test/api/things.test.io/v1" - "github.com/rotisserie/eris" - sksets "github.com/solo-io/skv2/contrib/pkg/sets" - "github.com/solo-io/skv2/pkg/ezkube" - "k8s.io/apimachinery/pkg/util/sets" + "github.com/rotisserie/eris" + sksets "github.com/solo-io/skv2/contrib/pkg/sets" + "github.com/solo-io/skv2/pkg/ezkube" + "k8s.io/apimachinery/pkg/util/sets" ) type PaintSet interface { // Get the set stored keys - Keys() sets.String - // List of resources stored in the set. Pass an optional filter function to filter on the list. - // The filter function should return false to keep the resource, true to drop it. - List(filterResource ... func(*things_test_io_v1.Paint) bool) []*things_test_io_v1.Paint - // Unsorted list of resources stored in the set. Pass an optional filter function to filter on the list. - // The filter function should return false to keep the resource, true to drop it. - UnsortedList(filterResource ... func(*things_test_io_v1.Paint) bool) []*things_test_io_v1.Paint - // Return the Set as a map of key to resource. - Map() map[string]*things_test_io_v1.Paint - // Insert a resource into the set. - Insert(paint ...*things_test_io_v1.Paint) - // Compare the equality of the keys in two sets (not the resources themselves) - Equal(paintSet PaintSet) bool - // Check if the set contains a key matching the resource (not the resource itself) - Has(paint ezkube.ResourceId) bool - // Delete the key matching the resource - Delete(paint ezkube.ResourceId) - // Return the union with the provided set - Union(set PaintSet) PaintSet - // Return the difference with the provided set - Difference(set PaintSet) PaintSet - // Return the intersection with the provided set - Intersection(set PaintSet) PaintSet - // Find the resource with the given ID - Find(id ezkube.ResourceId) (*things_test_io_v1.Paint, error) - // Get the length of the set - Length() int - // returns the generic implementation of the set - Generic() sksets.ResourceSet - // returns the delta between this and and another PaintSet - Delta(newSet PaintSet) sksets.ResourceDelta - // Create a deep copy of the current PaintSet - Clone() PaintSet + Keys() sets.String + // List of resources stored in the set. Pass an optional filter function to filter on the list. + // The filter function should return false to keep the resource, true to drop it. + List(filterResource ...func(*things_test_io_v1.Paint) bool) []*things_test_io_v1.Paint + // Unsorted list of resources stored in the set. Pass an optional filter function to filter on the list. + // The filter function should return false to keep the resource, true to drop it. + UnsortedList(filterResource ...func(*things_test_io_v1.Paint) bool) []*things_test_io_v1.Paint + // Return the Set as a map of key to resource. + Map() map[string]*things_test_io_v1.Paint + // Insert a resource into the set. + Insert(paint ...*things_test_io_v1.Paint) + // Compare the equality of the keys in two sets (not the resources themselves) + Equal(paintSet PaintSet) bool + // Check if the set contains a key matching the resource (not the resource itself) + Has(paint ezkube.ResourceId) bool + // Delete the key matching the resource + Delete(paint ezkube.ResourceId) + // Return the union with the provided set + Union(set PaintSet) PaintSet + // Return the difference with the provided set + Difference(set PaintSet) PaintSet + // Return the intersection with the provided set + Intersection(set PaintSet) PaintSet + // Find the resource with the given ID + Find(id ezkube.ResourceId) (*things_test_io_v1.Paint, error) + // Get the length of the set + Length() int + // returns the generic implementation of the set + Generic() sksets.ResourceSet + // returns the delta between this and and another PaintSet + Delta(newSet PaintSet) sksets.ResourceDelta + // Create a deep copy of the current PaintSet + Clone() PaintSet } func makeGenericPaintSet(paintList []*things_test_io_v1.Paint) sksets.ResourceSet { - var genericResources []ezkube.ResourceId - for _, obj := range paintList { - genericResources = append(genericResources, obj) - } - return sksets.NewResourceSet(genericResources...) + var genericResources []ezkube.ResourceId + for _, obj := range paintList { + genericResources = append(genericResources, obj) + } + return sksets.NewResourceSet(genericResources...) } type paintSet struct { - set sksets.ResourceSet + set sksets.ResourceSet } func NewPaintSet(paintList ...*things_test_io_v1.Paint) PaintSet { - return &paintSet{set: makeGenericPaintSet(paintList)} + return &paintSet{set: makeGenericPaintSet(paintList)} } func NewPaintSetFromList(paintList *things_test_io_v1.PaintList) PaintSet { - list := make([]*things_test_io_v1.Paint, 0, len(paintList.Items)) - for idx := range paintList.Items { - list = append(list, &paintList.Items[idx]) - } - return &paintSet{set: makeGenericPaintSet(list)} + list := make([]*things_test_io_v1.Paint, 0, len(paintList.Items)) + for idx := range paintList.Items { + list = append(list, &paintList.Items[idx]) + } + return &paintSet{set: makeGenericPaintSet(list)} } func (s *paintSet) Keys() sets.String { if s == nil { return sets.String{} - } - return s.Generic().Keys() -} - -func (s *paintSet) List(filterResource ... func(*things_test_io_v1.Paint) bool) []*things_test_io_v1.Paint { - if s == nil { - return nil - } - var genericFilters []func(ezkube.ResourceId) bool - for _, filter := range filterResource { - filter := filter - genericFilters = append(genericFilters, func(obj ezkube.ResourceId) bool { - return filter(obj.(*things_test_io_v1.Paint)) - }) - } - - objs := s.Generic().List(genericFilters...) - paintList := make([]*things_test_io_v1.Paint, 0, len(objs)) - for _, obj := range objs { - paintList = append(paintList, obj.(*things_test_io_v1.Paint)) - } - return paintList -} - -func (s *paintSet) UnsortedList(filterResource ... func(*things_test_io_v1.Paint) bool) []*things_test_io_v1.Paint { - if s == nil { - return nil - } - var genericFilters []func(ezkube.ResourceId) bool - for _, filter := range filterResource { - filter := filter - genericFilters = append(genericFilters, func(obj ezkube.ResourceId) bool { - return filter(obj.(*things_test_io_v1.Paint)) - }) - } - - var paintList []*things_test_io_v1.Paint - for _, obj := range s.Generic().UnsortedList(genericFilters...) { - paintList = append(paintList, obj.(*things_test_io_v1.Paint)) - } - return paintList + } + return s.Generic().Keys() +} + +func (s *paintSet) List(filterResource ...func(*things_test_io_v1.Paint) bool) []*things_test_io_v1.Paint { + if s == nil { + return nil + } + var genericFilters []func(ezkube.ResourceId) bool + for _, filter := range filterResource { + filter := filter + genericFilters = append(genericFilters, func(obj ezkube.ResourceId) bool { + return filter(obj.(*things_test_io_v1.Paint)) + }) + } + + objs := s.Generic().List(genericFilters...) + paintList := make([]*things_test_io_v1.Paint, 0, len(objs)) + for _, obj := range objs { + paintList = append(paintList, obj.(*things_test_io_v1.Paint)) + } + return paintList +} + +func (s *paintSet) UnsortedList(filterResource ...func(*things_test_io_v1.Paint) bool) []*things_test_io_v1.Paint { + if s == nil { + return nil + } + var genericFilters []func(ezkube.ResourceId) bool + for _, filter := range filterResource { + filter := filter + genericFilters = append(genericFilters, func(obj ezkube.ResourceId) bool { + return filter(obj.(*things_test_io_v1.Paint)) + }) + } + + var paintList []*things_test_io_v1.Paint + for _, obj := range s.Generic().UnsortedList(genericFilters...) { + paintList = append(paintList, obj.(*things_test_io_v1.Paint)) + } + return paintList } func (s *paintSet) Map() map[string]*things_test_io_v1.Paint { - if s == nil { - return nil - } + if s == nil { + return nil + } - newMap := map[string]*things_test_io_v1.Paint{} - for k, v := range s.Generic().Map() { - newMap[k] = v.(*things_test_io_v1.Paint) - } - return newMap + newMap := map[string]*things_test_io_v1.Paint{} + for k, v := range s.Generic().Map() { + newMap[k] = v.(*things_test_io_v1.Paint) + } + return newMap } func (s *paintSet) Insert( - paintList ...*things_test_io_v1.Paint, + paintList ...*things_test_io_v1.Paint, ) { - if s == nil { - panic("cannot insert into nil set") - } + if s == nil { + panic("cannot insert into nil set") + } - for _, obj := range paintList { - s.Generic().Insert(obj) - } + for _, obj := range paintList { + s.Generic().Insert(obj) + } } func (s *paintSet) Has(paint ezkube.ResourceId) bool { - if s == nil { - return false - } - return s.Generic().Has(paint) + if s == nil { + return false + } + return s.Generic().Has(paint) } func (s *paintSet) Equal( - paintSet PaintSet, + paintSet PaintSet, ) bool { - if s == nil { - return paintSet == nil - } - return s.Generic().Equal(paintSet.Generic()) + if s == nil { + return paintSet == nil + } + return s.Generic().Equal(paintSet.Generic()) } func (s *paintSet) Delete(Paint ezkube.ResourceId) { - if s == nil { - return - } - s.Generic().Delete(Paint) + if s == nil { + return + } + s.Generic().Delete(Paint) } func (s *paintSet) Union(set PaintSet) PaintSet { - if s == nil { - return set - } - return NewPaintSet(append(s.List(), set.List()...)...) + if s == nil { + return set + } + return NewPaintSet(append(s.List(), set.List()...)...) } func (s *paintSet) Difference(set PaintSet) PaintSet { - if s == nil { - return set - } - newSet := s.Generic().Difference(set.Generic()) - return &paintSet{set: newSet} + if s == nil { + return set + } + newSet := s.Generic().Difference(set.Generic()) + return &paintSet{set: newSet} } func (s *paintSet) Intersection(set PaintSet) PaintSet { - if s == nil { - return nil - } - newSet := s.Generic().Intersection(set.Generic()) - var paintList []*things_test_io_v1.Paint - for _, obj := range newSet.List() { - paintList = append(paintList, obj.(*things_test_io_v1.Paint)) - } - return NewPaintSet(paintList...) + if s == nil { + return nil + } + newSet := s.Generic().Intersection(set.Generic()) + var paintList []*things_test_io_v1.Paint + for _, obj := range newSet.List() { + paintList = append(paintList, obj.(*things_test_io_v1.Paint)) + } + return NewPaintSet(paintList...) } - func (s *paintSet) Find(id ezkube.ResourceId) (*things_test_io_v1.Paint, error) { - if s == nil { - return nil, eris.Errorf("empty set, cannot find Paint %v", sksets.Key(id)) - } + if s == nil { + return nil, eris.Errorf("empty set, cannot find Paint %v", sksets.Key(id)) + } obj, err := s.Generic().Find(&things_test_io_v1.Paint{}, id) if err != nil { return nil, err - } + } - return obj.(*things_test_io_v1.Paint), nil + return obj.(*things_test_io_v1.Paint), nil } func (s *paintSet) Length() int { - if s == nil { - return 0 - } - return s.Generic().Length() + if s == nil { + return 0 + } + return s.Generic().Length() } func (s *paintSet) Generic() sksets.ResourceSet { - if s == nil { - return nil - } - return s.set + if s == nil { + return nil + } + return s.set } func (s *paintSet) Delta(newSet PaintSet) sksets.ResourceDelta { - if s == nil { - return sksets.ResourceDelta{ - Inserted: newSet.Generic(), - } - } - return s.Generic().Delta(newSet.Generic()) + if s == nil { + return sksets.ResourceDelta{ + Inserted: newSet.Generic(), + } + } + return s.Generic().Delta(newSet.Generic()) } func (s *paintSet) Clone() PaintSet { @@ -241,219 +238,218 @@ func (s *paintSet) Clone() PaintSet { type ClusterResourceSet interface { // Get the set stored keys - Keys() sets.String - // List of resources stored in the set. Pass an optional filter function to filter on the list. - // The filter function should return false to keep the resource, true to drop it. - List(filterResource ... func(*things_test_io_v1.ClusterResource) bool) []*things_test_io_v1.ClusterResource - // Unsorted list of resources stored in the set. Pass an optional filter function to filter on the list. - // The filter function should return false to keep the resource, true to drop it. - UnsortedList(filterResource ... func(*things_test_io_v1.ClusterResource) bool) []*things_test_io_v1.ClusterResource - // Return the Set as a map of key to resource. - Map() map[string]*things_test_io_v1.ClusterResource - // Insert a resource into the set. - Insert(clusterResource ...*things_test_io_v1.ClusterResource) - // Compare the equality of the keys in two sets (not the resources themselves) - Equal(clusterResourceSet ClusterResourceSet) bool - // Check if the set contains a key matching the resource (not the resource itself) - Has(clusterResource ezkube.ResourceId) bool - // Delete the key matching the resource - Delete(clusterResource ezkube.ResourceId) - // Return the union with the provided set - Union(set ClusterResourceSet) ClusterResourceSet - // Return the difference with the provided set - Difference(set ClusterResourceSet) ClusterResourceSet - // Return the intersection with the provided set - Intersection(set ClusterResourceSet) ClusterResourceSet - // Find the resource with the given ID - Find(id ezkube.ResourceId) (*things_test_io_v1.ClusterResource, error) - // Get the length of the set - Length() int - // returns the generic implementation of the set - Generic() sksets.ResourceSet - // returns the delta between this and and another ClusterResourceSet - Delta(newSet ClusterResourceSet) sksets.ResourceDelta - // Create a deep copy of the current ClusterResourceSet - Clone() ClusterResourceSet + Keys() sets.String + // List of resources stored in the set. Pass an optional filter function to filter on the list. + // The filter function should return false to keep the resource, true to drop it. + List(filterResource ...func(*things_test_io_v1.ClusterResource) bool) []*things_test_io_v1.ClusterResource + // Unsorted list of resources stored in the set. Pass an optional filter function to filter on the list. + // The filter function should return false to keep the resource, true to drop it. + UnsortedList(filterResource ...func(*things_test_io_v1.ClusterResource) bool) []*things_test_io_v1.ClusterResource + // Return the Set as a map of key to resource. + Map() map[string]*things_test_io_v1.ClusterResource + // Insert a resource into the set. + Insert(clusterResource ...*things_test_io_v1.ClusterResource) + // Compare the equality of the keys in two sets (not the resources themselves) + Equal(clusterResourceSet ClusterResourceSet) bool + // Check if the set contains a key matching the resource (not the resource itself) + Has(clusterResource ezkube.ResourceId) bool + // Delete the key matching the resource + Delete(clusterResource ezkube.ResourceId) + // Return the union with the provided set + Union(set ClusterResourceSet) ClusterResourceSet + // Return the difference with the provided set + Difference(set ClusterResourceSet) ClusterResourceSet + // Return the intersection with the provided set + Intersection(set ClusterResourceSet) ClusterResourceSet + // Find the resource with the given ID + Find(id ezkube.ResourceId) (*things_test_io_v1.ClusterResource, error) + // Get the length of the set + Length() int + // returns the generic implementation of the set + Generic() sksets.ResourceSet + // returns the delta between this and and another ClusterResourceSet + Delta(newSet ClusterResourceSet) sksets.ResourceDelta + // Create a deep copy of the current ClusterResourceSet + Clone() ClusterResourceSet } func makeGenericClusterResourceSet(clusterResourceList []*things_test_io_v1.ClusterResource) sksets.ResourceSet { - var genericResources []ezkube.ResourceId - for _, obj := range clusterResourceList { - genericResources = append(genericResources, obj) - } - return sksets.NewResourceSet(genericResources...) + var genericResources []ezkube.ResourceId + for _, obj := range clusterResourceList { + genericResources = append(genericResources, obj) + } + return sksets.NewResourceSet(genericResources...) } type clusterResourceSet struct { - set sksets.ResourceSet + set sksets.ResourceSet } func NewClusterResourceSet(clusterResourceList ...*things_test_io_v1.ClusterResource) ClusterResourceSet { - return &clusterResourceSet{set: makeGenericClusterResourceSet(clusterResourceList)} + return &clusterResourceSet{set: makeGenericClusterResourceSet(clusterResourceList)} } func NewClusterResourceSetFromList(clusterResourceList *things_test_io_v1.ClusterResourceList) ClusterResourceSet { - list := make([]*things_test_io_v1.ClusterResource, 0, len(clusterResourceList.Items)) - for idx := range clusterResourceList.Items { - list = append(list, &clusterResourceList.Items[idx]) - } - return &clusterResourceSet{set: makeGenericClusterResourceSet(list)} + list := make([]*things_test_io_v1.ClusterResource, 0, len(clusterResourceList.Items)) + for idx := range clusterResourceList.Items { + list = append(list, &clusterResourceList.Items[idx]) + } + return &clusterResourceSet{set: makeGenericClusterResourceSet(list)} } func (s *clusterResourceSet) Keys() sets.String { if s == nil { return sets.String{} - } - return s.Generic().Keys() -} - -func (s *clusterResourceSet) List(filterResource ... func(*things_test_io_v1.ClusterResource) bool) []*things_test_io_v1.ClusterResource { - if s == nil { - return nil - } - var genericFilters []func(ezkube.ResourceId) bool - for _, filter := range filterResource { - filter := filter - genericFilters = append(genericFilters, func(obj ezkube.ResourceId) bool { - return filter(obj.(*things_test_io_v1.ClusterResource)) - }) - } - - objs := s.Generic().List(genericFilters...) - clusterResourceList := make([]*things_test_io_v1.ClusterResource, 0, len(objs)) - for _, obj := range objs { - clusterResourceList = append(clusterResourceList, obj.(*things_test_io_v1.ClusterResource)) - } - return clusterResourceList -} - -func (s *clusterResourceSet) UnsortedList(filterResource ... func(*things_test_io_v1.ClusterResource) bool) []*things_test_io_v1.ClusterResource { - if s == nil { - return nil - } - var genericFilters []func(ezkube.ResourceId) bool - for _, filter := range filterResource { - filter := filter - genericFilters = append(genericFilters, func(obj ezkube.ResourceId) bool { - return filter(obj.(*things_test_io_v1.ClusterResource)) - }) - } - - var clusterResourceList []*things_test_io_v1.ClusterResource - for _, obj := range s.Generic().UnsortedList(genericFilters...) { - clusterResourceList = append(clusterResourceList, obj.(*things_test_io_v1.ClusterResource)) - } - return clusterResourceList + } + return s.Generic().Keys() +} + +func (s *clusterResourceSet) List(filterResource ...func(*things_test_io_v1.ClusterResource) bool) []*things_test_io_v1.ClusterResource { + if s == nil { + return nil + } + var genericFilters []func(ezkube.ResourceId) bool + for _, filter := range filterResource { + filter := filter + genericFilters = append(genericFilters, func(obj ezkube.ResourceId) bool { + return filter(obj.(*things_test_io_v1.ClusterResource)) + }) + } + + objs := s.Generic().List(genericFilters...) + clusterResourceList := make([]*things_test_io_v1.ClusterResource, 0, len(objs)) + for _, obj := range objs { + clusterResourceList = append(clusterResourceList, obj.(*things_test_io_v1.ClusterResource)) + } + return clusterResourceList +} + +func (s *clusterResourceSet) UnsortedList(filterResource ...func(*things_test_io_v1.ClusterResource) bool) []*things_test_io_v1.ClusterResource { + if s == nil { + return nil + } + var genericFilters []func(ezkube.ResourceId) bool + for _, filter := range filterResource { + filter := filter + genericFilters = append(genericFilters, func(obj ezkube.ResourceId) bool { + return filter(obj.(*things_test_io_v1.ClusterResource)) + }) + } + + var clusterResourceList []*things_test_io_v1.ClusterResource + for _, obj := range s.Generic().UnsortedList(genericFilters...) { + clusterResourceList = append(clusterResourceList, obj.(*things_test_io_v1.ClusterResource)) + } + return clusterResourceList } func (s *clusterResourceSet) Map() map[string]*things_test_io_v1.ClusterResource { - if s == nil { - return nil - } + if s == nil { + return nil + } - newMap := map[string]*things_test_io_v1.ClusterResource{} - for k, v := range s.Generic().Map() { - newMap[k] = v.(*things_test_io_v1.ClusterResource) - } - return newMap + newMap := map[string]*things_test_io_v1.ClusterResource{} + for k, v := range s.Generic().Map() { + newMap[k] = v.(*things_test_io_v1.ClusterResource) + } + return newMap } func (s *clusterResourceSet) Insert( - clusterResourceList ...*things_test_io_v1.ClusterResource, + clusterResourceList ...*things_test_io_v1.ClusterResource, ) { - if s == nil { - panic("cannot insert into nil set") - } + if s == nil { + panic("cannot insert into nil set") + } - for _, obj := range clusterResourceList { - s.Generic().Insert(obj) - } + for _, obj := range clusterResourceList { + s.Generic().Insert(obj) + } } func (s *clusterResourceSet) Has(clusterResource ezkube.ResourceId) bool { - if s == nil { - return false - } - return s.Generic().Has(clusterResource) + if s == nil { + return false + } + return s.Generic().Has(clusterResource) } func (s *clusterResourceSet) Equal( - clusterResourceSet ClusterResourceSet, + clusterResourceSet ClusterResourceSet, ) bool { - if s == nil { - return clusterResourceSet == nil - } - return s.Generic().Equal(clusterResourceSet.Generic()) + if s == nil { + return clusterResourceSet == nil + } + return s.Generic().Equal(clusterResourceSet.Generic()) } func (s *clusterResourceSet) Delete(ClusterResource ezkube.ResourceId) { - if s == nil { - return - } - s.Generic().Delete(ClusterResource) + if s == nil { + return + } + s.Generic().Delete(ClusterResource) } func (s *clusterResourceSet) Union(set ClusterResourceSet) ClusterResourceSet { - if s == nil { - return set - } - return NewClusterResourceSet(append(s.List(), set.List()...)...) + if s == nil { + return set + } + return NewClusterResourceSet(append(s.List(), set.List()...)...) } func (s *clusterResourceSet) Difference(set ClusterResourceSet) ClusterResourceSet { - if s == nil { - return set - } - newSet := s.Generic().Difference(set.Generic()) - return &clusterResourceSet{set: newSet} + if s == nil { + return set + } + newSet := s.Generic().Difference(set.Generic()) + return &clusterResourceSet{set: newSet} } func (s *clusterResourceSet) Intersection(set ClusterResourceSet) ClusterResourceSet { - if s == nil { - return nil - } - newSet := s.Generic().Intersection(set.Generic()) - var clusterResourceList []*things_test_io_v1.ClusterResource - for _, obj := range newSet.List() { - clusterResourceList = append(clusterResourceList, obj.(*things_test_io_v1.ClusterResource)) - } - return NewClusterResourceSet(clusterResourceList...) + if s == nil { + return nil + } + newSet := s.Generic().Intersection(set.Generic()) + var clusterResourceList []*things_test_io_v1.ClusterResource + for _, obj := range newSet.List() { + clusterResourceList = append(clusterResourceList, obj.(*things_test_io_v1.ClusterResource)) + } + return NewClusterResourceSet(clusterResourceList...) } - func (s *clusterResourceSet) Find(id ezkube.ResourceId) (*things_test_io_v1.ClusterResource, error) { - if s == nil { - return nil, eris.Errorf("empty set, cannot find ClusterResource %v", sksets.Key(id)) - } + if s == nil { + return nil, eris.Errorf("empty set, cannot find ClusterResource %v", sksets.Key(id)) + } obj, err := s.Generic().Find(&things_test_io_v1.ClusterResource{}, id) if err != nil { return nil, err - } + } - return obj.(*things_test_io_v1.ClusterResource), nil + return obj.(*things_test_io_v1.ClusterResource), nil } func (s *clusterResourceSet) Length() int { - if s == nil { - return 0 - } - return s.Generic().Length() + if s == nil { + return 0 + } + return s.Generic().Length() } func (s *clusterResourceSet) Generic() sksets.ResourceSet { - if s == nil { - return nil - } - return s.set + if s == nil { + return nil + } + return s.set } func (s *clusterResourceSet) Delta(newSet ClusterResourceSet) sksets.ResourceDelta { - if s == nil { - return sksets.ResourceDelta{ - Inserted: newSet.Generic(), - } - } - return s.Generic().Delta(newSet.Generic()) + if s == nil { + return sksets.ResourceDelta{ + Inserted: newSet.Generic(), + } + } + return s.Generic().Delta(newSet.Generic()) } func (s *clusterResourceSet) Clone() ClusterResourceSet { diff --git a/codegen/test/api/things.test.io/v1/test_api.pb.go b/codegen/test/api/things.test.io/v1/test_api.pb.go index 21c590bfc..85202c9bb 100644 --- a/codegen/test/api/things.test.io/v1/test_api.pb.go +++ b/codegen/test/api/things.test.io/v1/test_api.pb.go @@ -7,14 +7,15 @@ package v1 import ( + reflect "reflect" + sync "sync" + _ "github.com/solo-io/cue/encoding/protobuf/cue" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" anypb "google.golang.org/protobuf/types/known/anypb" structpb "google.golang.org/protobuf/types/known/structpb" wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" - reflect "reflect" - sync "sync" ) const ( diff --git a/codegen/test/api/things.test.io/v1/type_helpers.go b/codegen/test/api/things.test.io/v1/type_helpers.go index 2d04a4fd1..4133a8e21 100644 --- a/codegen/test/api/things.test.io/v1/type_helpers.go +++ b/codegen/test/api/things.test.io/v1/type_helpers.go @@ -3,9 +3,6 @@ // Definitions for the Kubernetes types package v1 -import ( -) - // PaintSlice represents a slice of *Paint type PaintSlice []*Paint diff --git a/codegen/test/api/things.test.io/v1/types.go b/codegen/test/api/things.test.io/v1/types.go index 3f3fc59e2..f153a3983 100644 --- a/codegen/test/api/things.test.io/v1/types.go +++ b/codegen/test/api/things.test.io/v1/types.go @@ -4,8 +4,9 @@ package v1 import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema") + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" +) // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -14,22 +15,22 @@ import ( // GroupVersionKind for Paint var PaintGVK = schema.GroupVersionKind{ - Group: "things.test.io", - Version: "v1", - Kind: "Paint", + Group: "things.test.io", + Version: "v1", + Kind: "Paint", } // Paint is the Schema for the paint API type Paint struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` - Spec PaintSpec `json:"spec,omitempty"` - Status PaintStatus `json:"status,omitempty"` + Spec PaintSpec `json:"spec,omitempty"` + Status PaintStatus `json:"status,omitempty"` } // GVK returns the GroupVersionKind associated with the resource type. -func (Paint) GVK() schema.GroupVersionKind { +func (Paint) GVK() schema.GroupVersionKind { return PaintGVK } @@ -37,9 +38,9 @@ func (Paint) GVK() schema.GroupVersionKind { // PaintList contains a list of Paint type PaintList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []Paint `json:"items"` + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Paint `json:"items"` } // +genclient @@ -49,21 +50,21 @@ type PaintList struct { // GroupVersionKind for ClusterResource var ClusterResourceGVK = schema.GroupVersionKind{ - Group: "things.test.io", - Version: "v1", - Kind: "ClusterResource", + Group: "things.test.io", + Version: "v1", + Kind: "ClusterResource", } // ClusterResource is the Schema for the clusterResource API type ClusterResource struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ClusterResourceSpec `json:"spec,omitempty"` + Spec ClusterResourceSpec `json:"spec,omitempty"` } // GVK returns the GroupVersionKind associated with the resource type. -func (ClusterResource) GVK() schema.GroupVersionKind { +func (ClusterResource) GVK() schema.GroupVersionKind { return ClusterResourceGVK } @@ -71,12 +72,12 @@ func (ClusterResource) GVK() schema.GroupVersionKind { // ClusterResourceList contains a list of ClusterResource type ClusterResourceList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []ClusterResource `json:"items"` + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ClusterResource `json:"items"` } func init() { - SchemeBuilder.Register(&Paint{}, &PaintList{}) - SchemeBuilder.Register(&ClusterResource{}, &ClusterResourceList{}) + SchemeBuilder.Register(&Paint{}, &PaintList{}) + SchemeBuilder.Register(&ClusterResource{}, &ClusterResourceList{}) } diff --git a/codegen/test/api/things.test.io/v1/zz_generated.deepcopy.go b/codegen/test/api/things.test.io/v1/zz_generated.deepcopy.go index 8939012a9..4203de9bf 100644 --- a/codegen/test/api/things.test.io/v1/zz_generated.deepcopy.go +++ b/codegen/test/api/things.test.io/v1/zz_generated.deepcopy.go @@ -5,124 +5,123 @@ package v1 import ( - runtime "k8s.io/apimachinery/pkg/runtime" + runtime "k8s.io/apimachinery/pkg/runtime" ) // Generated Deepcopy methods for Paint func (in *Paint) DeepCopyInto(out *Paint) { - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - // deepcopy spec - in.Spec.DeepCopyInto(&out.Spec) - // deepcopy status - in.Status.DeepCopyInto(&out.Status) + // deepcopy spec + in.Spec.DeepCopyInto(&out.Spec) + // deepcopy status + in.Status.DeepCopyInto(&out.Status) - return + return } func (in *Paint) DeepCopy() *Paint { - if in == nil { - return nil - } - out := new(Paint) - in.DeepCopyInto(out) - return out + if in == nil { + return nil + } + out := new(Paint) + in.DeepCopyInto(out) + return out } func (in *Paint) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil + if c := in.DeepCopy(); c != nil { + return c + } + return nil } func (in *PaintList) DeepCopyInto(out *PaintList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]Paint, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Paint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return } func (in *PaintList) DeepCopy() *PaintList { - if in == nil { - return nil - } - out := new(PaintList) - in.DeepCopyInto(out) - return out + if in == nil { + return nil + } + out := new(PaintList) + in.DeepCopyInto(out) + return out } func (in *PaintList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil + if c := in.DeepCopy(); c != nil { + return c + } + return nil } // Generated Deepcopy methods for ClusterResource func (in *ClusterResource) DeepCopyInto(out *ClusterResource) { - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - // deepcopy spec - in.Spec.DeepCopyInto(&out.Spec) + // deepcopy spec + in.Spec.DeepCopyInto(&out.Spec) - return + return } func (in *ClusterResource) DeepCopy() *ClusterResource { - if in == nil { - return nil - } - out := new(ClusterResource) - in.DeepCopyInto(out) - return out + if in == nil { + return nil + } + out := new(ClusterResource) + in.DeepCopyInto(out) + return out } func (in *ClusterResource) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil + if c := in.DeepCopy(); c != nil { + return c + } + return nil } func (in *ClusterResourceList) DeepCopyInto(out *ClusterResourceList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]ClusterResource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ClusterResource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return } func (in *ClusterResourceList) DeepCopy() *ClusterResourceList { - if in == nil { - return nil - } - out := new(ClusterResourceList) - in.DeepCopyInto(out) - return out + if in == nil { + return nil + } + out := new(ClusterResourceList) + in.DeepCopyInto(out) + return out } func (in *ClusterResourceList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil + if c := in.DeepCopy(); c != nil { + return c + } + return nil } - diff --git a/pkg/api/core.skv2.solo.io/v1/core.pb.go b/pkg/api/core.skv2.solo.io/v1/core.pb.go index 5a35e6efe..5277ce8f5 100644 --- a/pkg/api/core.skv2.solo.io/v1/core.pb.go +++ b/pkg/api/core.skv2.solo.io/v1/core.pb.go @@ -7,13 +7,14 @@ package v1 import ( + reflect "reflect" + sync "sync" + _ "github.com/solo-io/protoc-gen-ext/extproto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" timestamppb "google.golang.org/protobuf/types/known/timestamppb" wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" - reflect "reflect" - sync "sync" ) const ( diff --git a/pkg/api/multicluster.solo.io/v1alpha1/cluster.pb.go b/pkg/api/multicluster.solo.io/v1alpha1/cluster.pb.go index 729adf049..6012226be 100644 --- a/pkg/api/multicluster.solo.io/v1alpha1/cluster.pb.go +++ b/pkg/api/multicluster.solo.io/v1alpha1/cluster.pb.go @@ -7,12 +7,13 @@ package v1alpha1 import ( + reflect "reflect" + sync "sync" + _ "github.com/solo-io/protoc-gen-ext/extproto" v1 "github.com/solo-io/skv2/pkg/api/core.skv2.solo.io/v1" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const (