From b2a9c90ad73227d1dfdeb2cf94efb37a219dd76f Mon Sep 17 00:00:00 2001 From: Kevin Joiner Date: Wed, 31 May 2023 09:26:37 -0400 Subject: [PATCH] Updates ControllerInterface to use a cache struct. Changes the generated cache to a pointer receiver, and the ControllerInterface now returns a real struct instead of an interface. These changes greatly reduce the amount of generated code needed and allows users to use the mocks directly with controllers without having to wrap them as an embedded object. --- .../generators/group_version_interface_go.go | 4 +- pkg/controller-gen/generators/type_go.go | 104 +---------------- .../v1/interface.go | 8 +- .../v1/mutatingwebhookconfiguration.go | 101 +---------------- .../v1/validatingwebhookconfiguration.go | 101 +---------------- .../v1/customresourcedefinition.go | 107 +----------------- .../apiextensions.k8s.io/v1/interface.go | 4 +- .../apiregistration.k8s.io/v1/apiservice.go | 107 +----------------- .../apiregistration.k8s.io/v1/interface.go | 4 +- .../controllers/apps/v1/daemonset.go | 107 +----------------- .../controllers/apps/v1/deployment.go | 107 +----------------- .../controllers/apps/v1/interface.go | 12 +- .../controllers/apps/v1/statefulset.go | 107 +----------------- .../controllers/batch/v1/interface.go | 4 +- pkg/generated/controllers/batch/v1/job.go | 107 +----------------- .../coordination.k8s.io/v1/interface.go | 4 +- .../coordination.k8s.io/v1/lease.go | 101 +---------------- .../controllers/core/v1/configmap.go | 101 +---------------- .../controllers/core/v1/endpoints.go | 101 +---------------- pkg/generated/controllers/core/v1/event.go | 101 +---------------- .../controllers/core/v1/interface.go | 44 ++----- .../controllers/core/v1/namespace.go | 107 +----------------- pkg/generated/controllers/core/v1/node.go | 107 +----------------- .../controllers/core/v1/persistentvolume.go | 107 +----------------- .../core/v1/persistentvolumeclaim.go | 107 +----------------- pkg/generated/controllers/core/v1/pod.go | 107 +----------------- pkg/generated/controllers/core/v1/secret.go | 101 +---------------- pkg/generated/controllers/core/v1/service.go | 107 +----------------- .../controllers/core/v1/serviceaccount.go | 101 +---------------- .../controllers/discovery/v1/endpointslice.go | 101 +---------------- .../controllers/discovery/v1/interface.go | 4 +- .../controllers/extensions/v1beta1/ingress.go | 107 +----------------- .../extensions/v1beta1/interface.go | 4 +- .../networking.k8s.io/v1/interface.go | 4 +- .../networking.k8s.io/v1/networkpolicy.go | 107 +----------------- .../controllers/rbac/v1/clusterrole.go | 101 +---------------- .../controllers/rbac/v1/clusterrolebinding.go | 101 +---------------- .../controllers/rbac/v1/interface.go | 16 +-- pkg/generated/controllers/rbac/v1/role.go | 101 +---------------- .../controllers/rbac/v1/rolebinding.go | 101 +---------------- .../controllers/storage/v1/interface.go | 4 +- .../controllers/storage/v1/storageclass.go | 101 +---------------- pkg/generic/controller.go | 26 ++++- pkg/generic/fake/README.md | 23 +--- pkg/generic/fake/controller.go | 8 +- 45 files changed, 133 insertions(+), 3056 deletions(-) diff --git a/pkg/controller-gen/generators/group_version_interface_go.go b/pkg/controller-gen/generators/group_version_interface_go.go index 3d580fe5..9c66c2aa 100644 --- a/pkg/controller-gen/generators/group_version_interface_go.go +++ b/pkg/controller-gen/generators/group_version_interface_go.go @@ -92,9 +92,7 @@ func (f *groupInterfaceGo) Init(c *generator.Context, w io.Writer) error { } body := ` func (v *version) {{.type}}() {{.type}}Controller { - return &{{.type}}GenericController { - generic.New{{ if not .namespaced}}NonNamespaced{{end}}Controller[*{{.version}}.{{.type}}, *{{.version}}.{{.type}}List](schema.GroupVersionKind{Group: "{{.group}}", Version: "{{.version}}", Kind: "{{.type}}"}, "{{.pluralLower}}", {{ if .namespaced}}true, {{end}}v.controllerFactory), - } + return generic.New{{ if not .namespaced}}NonNamespaced{{end}}Controller[*{{.version}}.{{.type}}, *{{.version}}.{{.type}}List](schema.GroupVersionKind{Group: "{{.group}}", Version: "{{.version}}", Kind: "{{.type}}"}, "{{.pluralLower}}", {{ if .namespaced}}true, {{end}}v.controllerFactory) } ` sw.Do(body, m) diff --git a/pkg/controller-gen/generators/type_go.go b/pkg/controller-gen/generators/type_go.go index 49e283fc..3e833a10 100644 --- a/pkg/controller-gen/generators/type_go.go +++ b/pkg/controller-gen/generators/type_go.go @@ -84,129 +84,31 @@ func hasStatus(t *types.Type) bool { var typeBody = ` // {{.type}}Controller interface for managing {{.type}} resources. type {{.type}}Controller interface { - generic.ControllerMeta - {{.type}}Client - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync {{.type}}Handler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync {{.type}}Handler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue({{ if .namespaced}}namespace, {{end}}name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter({{ if .namespaced}}namespace, {{end}}name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() {{.type}}Cache + generic.{{ if not .namespaced}}NonNamespaced{{end}}ControllerInterface[*{{.version}}.{{.type}}, *{{.version}}.{{.type}}List] } // {{.type}}Client interface for managing {{.type}} resources in Kubernetes. type {{.type}}Client interface { - // Create creates a new object and return the newly created Object or an error. - Create(*{{.version}}.{{.type}}) (*{{.version}}.{{.type}}, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*{{.version}}.{{.type}}) (*{{.version}}.{{.type}}, error) -{{ if .hasStatus -}} - - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*{{.version}}.{{.type}}) (*{{.version}}.{{.type}}, error) -{{- end }} - - // Delete deletes the Object in the given name. - Delete({{ if .namespaced}}namespace, {{end}}name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get({{ if .namespaced}}namespace, {{end}}name string, options metav1.GetOptions) (*{{.version}}.{{.type}}, error) - - // List will attempt to find multiple resources. - List({{ if .namespaced}}namespace string, {{end}}opts metav1.ListOptions) (*{{.version}}.{{.type}}List, error) - - // Watch will start watching resources. - Watch({{ if .namespaced}}namespace string, {{end}}opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch({{ if .namespaced}}namespace, {{end}}name string, pt types.PatchType, data []byte, subresources ...string) (result *{{.version}}.{{.type}}, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.{{ if not .namespaced}}NonNamespaced{{end}}ClientInterface[*{{.version}}.{{.type}}, *{{.version}}.{{.type}}List], error) + generic.{{ if not .namespaced}}NonNamespaced{{end}}ClientInterface[*{{.version}}.{{.type}}, *{{.version}}.{{.type}}List] } // {{.type}}Cache interface for retrieving {{.type}} resources in memory. type {{.type}}Cache interface { - // Get returns the resources with the specified name from the cache. - Get({{ if .namespaced}}namespace, {{end}}name string) (*{{.version}}.{{.type}}, error) - - // List will attempt to find resources from the Cache. - List({{ if .namespaced}}namespace string, {{end}}selector labels.Selector) ([]*{{.version}}.{{.type}}, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer {{.type}}Indexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*{{.version}}.{{.type}}, error) -} -// {{.type}}Handler is function for performing any potential modifications to a {{.type}} resource. -type {{.type}}Handler func(string, *{{.version}}.{{.type}}) (*{{.version}}.{{.type}}, error) - -// {{.type}}Indexer computes a set of indexed values for the provided object. -type {{.type}}Indexer func(obj *{{.version}}.{{.type}}) ([]string, error) - -// {{.type}}GenericController wraps wrangler/pkg/generic.{{ if not .namespaced}}NonNamespaced{{end}}Controller so that the function definitions adhere to {{.type}}Controller interface. -type {{.type}}GenericController struct { - generic.{{ if not .namespaced}}NonNamespaced{{end}}ControllerInterface[*{{.version}}.{{.type}}, *{{.version}}.{{.type}}List] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *{{.type}}GenericController) OnChange(ctx context.Context, name string, sync {{.type}}Handler) { - c.{{ if not .namespaced}}NonNamespaced{{end}}ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*{{.version}}.{{.type}}](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *{{.type}}GenericController) OnRemove(ctx context.Context, name string, sync {{.type}}Handler) { - c.{{ if not .namespaced}}NonNamespaced{{end}}ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*{{.version}}.{{.type}}](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *{{.type}}GenericController) Cache() {{.type}}Cache { - return &{{.type}}GenericCache{ - c.{{ if not .namespaced}}NonNamespaced{{end}}ControllerInterface.Cache(), - } -} - -// {{.type}}GenericCache wraps wrangler/pkg/generic.{{ if not .namespaced}}NonNamespaced{{end}}Cache so the function definitions adhere to {{.type}}Cache interface. -type {{.type}}GenericCache struct { generic.{{ if not .namespaced}}NonNamespaced{{end}}CacheInterface[*{{.version}}.{{.type}}] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c {{.type}}GenericCache) AddIndexer(indexName string, indexer {{.type}}Indexer) { - c.{{ if not .namespaced}}NonNamespaced{{end}}CacheInterface.AddIndexer(indexName, generic.Indexer[*{{.version}}.{{.type}}](indexer)) -} - {{ if .hasStatus -}} type {{.type}}StatusHandler func(obj *{{.version}}.{{.type}}, status {{.version}}.{{.statusType}}) ({{.version}}.{{.statusType}}, error) type {{.type}}GeneratingHandler func(obj *{{.version}}.{{.type}}, status {{.version}}.{{.statusType}}) ([]runtime.Object, {{.version}}.{{.statusType}}, error) -func From{{.type}}HandlerToHandler(sync {{.type}}Handler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*{{.version}}.{{.type}},](sync)) -} - func Register{{.type}}StatusHandler(ctx context.Context, controller {{.type}}Controller, condition condition.Cond, name string, handler {{.type}}StatusHandler) { statusHandler := &{{.lowerName}}StatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, From{{.type}}HandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func Register{{.type}}GeneratingHandler(ctx context.Context, controller {{.type}}Controller, apply apply.Apply, diff --git a/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go b/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go index d436f137..f2162f18 100644 --- a/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go +++ b/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go @@ -46,13 +46,9 @@ type version struct { } func (v *version) MutatingWebhookConfiguration() MutatingWebhookConfigurationController { - return &MutatingWebhookConfigurationGenericController{ - generic.NewNonNamespacedController[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList](schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Version: "v1", Kind: "MutatingWebhookConfiguration"}, "mutatingwebhookconfigurations", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList](schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Version: "v1", Kind: "MutatingWebhookConfiguration"}, "mutatingwebhookconfigurations", v.controllerFactory) } func (v *version) ValidatingWebhookConfiguration() ValidatingWebhookConfigurationController { - return &ValidatingWebhookConfigurationGenericController{ - generic.NewNonNamespacedController[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList](schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Version: "v1", Kind: "ValidatingWebhookConfiguration"}, "validatingwebhookconfigurations", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList](schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Version: "v1", Kind: "ValidatingWebhookConfiguration"}, "validatingwebhookconfigurations", v.controllerFactory) } diff --git a/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go b/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go index 947877ef..c086c132 100644 --- a/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go +++ b/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/admissionregistration/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // MutatingWebhookConfigurationController interface for managing MutatingWebhookConfiguration resources. type MutatingWebhookConfigurationController interface { - generic.ControllerMeta - MutatingWebhookConfigurationClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync MutatingWebhookConfigurationHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync MutatingWebhookConfigurationHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() MutatingWebhookConfigurationCache + generic.NonNamespacedControllerInterface[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList] } // MutatingWebhookConfigurationClient interface for managing MutatingWebhookConfiguration resources in Kubernetes. type MutatingWebhookConfigurationClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.MutatingWebhookConfiguration, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.MutatingWebhookConfigurationList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.MutatingWebhookConfiguration, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList], error) + generic.NonNamespacedClientInterface[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList] } // MutatingWebhookConfigurationCache interface for retrieving MutatingWebhookConfiguration resources in memory. type MutatingWebhookConfigurationCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.MutatingWebhookConfiguration, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.MutatingWebhookConfiguration, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer MutatingWebhookConfigurationIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.MutatingWebhookConfiguration, error) -} - -// MutatingWebhookConfigurationHandler is function for performing any potential modifications to a MutatingWebhookConfiguration resource. -type MutatingWebhookConfigurationHandler func(string, *v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error) - -// MutatingWebhookConfigurationIndexer computes a set of indexed values for the provided object. -type MutatingWebhookConfigurationIndexer func(obj *v1.MutatingWebhookConfiguration) ([]string, error) - -// MutatingWebhookConfigurationGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to MutatingWebhookConfigurationController interface. -type MutatingWebhookConfigurationGenericController struct { - generic.NonNamespacedControllerInterface[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *MutatingWebhookConfigurationGenericController) OnChange(ctx context.Context, name string, sync MutatingWebhookConfigurationHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.MutatingWebhookConfiguration](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *MutatingWebhookConfigurationGenericController) OnRemove(ctx context.Context, name string, sync MutatingWebhookConfigurationHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.MutatingWebhookConfiguration](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *MutatingWebhookConfigurationGenericController) Cache() MutatingWebhookConfigurationCache { - return &MutatingWebhookConfigurationGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// MutatingWebhookConfigurationGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to MutatingWebhookConfigurationCache interface. -type MutatingWebhookConfigurationGenericCache struct { generic.NonNamespacedCacheInterface[*v1.MutatingWebhookConfiguration] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c MutatingWebhookConfigurationGenericCache) AddIndexer(indexName string, indexer MutatingWebhookConfigurationIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.MutatingWebhookConfiguration](indexer)) -} diff --git a/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go b/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go index 28d53eeb..c2e7d61c 100644 --- a/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go +++ b/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/admissionregistration/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // ValidatingWebhookConfigurationController interface for managing ValidatingWebhookConfiguration resources. type ValidatingWebhookConfigurationController interface { - generic.ControllerMeta - ValidatingWebhookConfigurationClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync ValidatingWebhookConfigurationHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync ValidatingWebhookConfigurationHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() ValidatingWebhookConfigurationCache + generic.NonNamespacedControllerInterface[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList] } // ValidatingWebhookConfigurationClient interface for managing ValidatingWebhookConfiguration resources in Kubernetes. type ValidatingWebhookConfigurationClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.ValidatingWebhookConfiguration, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.ValidatingWebhookConfigurationList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ValidatingWebhookConfiguration, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList], error) + generic.NonNamespacedClientInterface[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList] } // ValidatingWebhookConfigurationCache interface for retrieving ValidatingWebhookConfiguration resources in memory. type ValidatingWebhookConfigurationCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.ValidatingWebhookConfiguration, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.ValidatingWebhookConfiguration, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer ValidatingWebhookConfigurationIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.ValidatingWebhookConfiguration, error) -} - -// ValidatingWebhookConfigurationHandler is function for performing any potential modifications to a ValidatingWebhookConfiguration resource. -type ValidatingWebhookConfigurationHandler func(string, *v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error) - -// ValidatingWebhookConfigurationIndexer computes a set of indexed values for the provided object. -type ValidatingWebhookConfigurationIndexer func(obj *v1.ValidatingWebhookConfiguration) ([]string, error) - -// ValidatingWebhookConfigurationGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to ValidatingWebhookConfigurationController interface. -type ValidatingWebhookConfigurationGenericController struct { - generic.NonNamespacedControllerInterface[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *ValidatingWebhookConfigurationGenericController) OnChange(ctx context.Context, name string, sync ValidatingWebhookConfigurationHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.ValidatingWebhookConfiguration](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *ValidatingWebhookConfigurationGenericController) OnRemove(ctx context.Context, name string, sync ValidatingWebhookConfigurationHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.ValidatingWebhookConfiguration](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *ValidatingWebhookConfigurationGenericController) Cache() ValidatingWebhookConfigurationCache { - return &ValidatingWebhookConfigurationGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// ValidatingWebhookConfigurationGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to ValidatingWebhookConfigurationCache interface. -type ValidatingWebhookConfigurationGenericCache struct { generic.NonNamespacedCacheInterface[*v1.ValidatingWebhookConfiguration] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c ValidatingWebhookConfigurationGenericCache) AddIndexer(indexName string, indexer ValidatingWebhookConfigurationIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.ValidatingWebhookConfiguration](indexer)) -} diff --git a/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go b/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go index c453b96e..646829bb 100644 --- a/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go +++ b/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // CustomResourceDefinitionController interface for managing CustomResourceDefinition resources. type CustomResourceDefinitionController interface { - generic.ControllerMeta - CustomResourceDefinitionClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync CustomResourceDefinitionHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync CustomResourceDefinitionHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() CustomResourceDefinitionCache + generic.NonNamespacedControllerInterface[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList] } // CustomResourceDefinitionClient interface for managing CustomResourceDefinition resources in Kubernetes. type CustomResourceDefinitionClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.CustomResourceDefinition, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.CustomResourceDefinitionList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.CustomResourceDefinition, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList], error) + generic.NonNamespacedClientInterface[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList] } // CustomResourceDefinitionCache interface for retrieving CustomResourceDefinition resources in memory. type CustomResourceDefinitionCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.CustomResourceDefinition, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.CustomResourceDefinition, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer CustomResourceDefinitionIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.CustomResourceDefinition, error) -} - -// CustomResourceDefinitionHandler is function for performing any potential modifications to a CustomResourceDefinition resource. -type CustomResourceDefinitionHandler func(string, *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) - -// CustomResourceDefinitionIndexer computes a set of indexed values for the provided object. -type CustomResourceDefinitionIndexer func(obj *v1.CustomResourceDefinition) ([]string, error) - -// CustomResourceDefinitionGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to CustomResourceDefinitionController interface. -type CustomResourceDefinitionGenericController struct { - generic.NonNamespacedControllerInterface[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *CustomResourceDefinitionGenericController) OnChange(ctx context.Context, name string, sync CustomResourceDefinitionHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.CustomResourceDefinition](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *CustomResourceDefinitionGenericController) OnRemove(ctx context.Context, name string, sync CustomResourceDefinitionHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.CustomResourceDefinition](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *CustomResourceDefinitionGenericController) Cache() CustomResourceDefinitionCache { - return &CustomResourceDefinitionGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// CustomResourceDefinitionGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to CustomResourceDefinitionCache interface. -type CustomResourceDefinitionGenericCache struct { generic.NonNamespacedCacheInterface[*v1.CustomResourceDefinition] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c CustomResourceDefinitionGenericCache) AddIndexer(indexName string, indexer CustomResourceDefinitionIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.CustomResourceDefinition](indexer)) -} - type CustomResourceDefinitionStatusHandler func(obj *v1.CustomResourceDefinition, status v1.CustomResourceDefinitionStatus) (v1.CustomResourceDefinitionStatus, error) type CustomResourceDefinitionGeneratingHandler func(obj *v1.CustomResourceDefinition, status v1.CustomResourceDefinitionStatus) ([]runtime.Object, v1.CustomResourceDefinitionStatus, error) -func FromCustomResourceDefinitionHandlerToHandler(sync CustomResourceDefinitionHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.CustomResourceDefinition](sync)) -} - func RegisterCustomResourceDefinitionStatusHandler(ctx context.Context, controller CustomResourceDefinitionController, condition condition.Cond, name string, handler CustomResourceDefinitionStatusHandler) { statusHandler := &customResourceDefinitionStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromCustomResourceDefinitionHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterCustomResourceDefinitionGeneratingHandler(ctx context.Context, controller CustomResourceDefinitionController, apply apply.Apply, diff --git a/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go b/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go index 4f1c3c9b..7db10d7a 100644 --- a/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go +++ b/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go @@ -45,7 +45,5 @@ type version struct { } func (v *version) CustomResourceDefinition() CustomResourceDefinitionController { - return &CustomResourceDefinitionGenericController{ - generic.NewNonNamespacedController[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList](schema.GroupVersionKind{Group: "apiextensions.k8s.io", Version: "v1", Kind: "CustomResourceDefinition"}, "customresourcedefinitions", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList](schema.GroupVersionKind{Group: "apiextensions.k8s.io", Version: "v1", Kind: "CustomResourceDefinition"}, "customresourcedefinitions", v.controllerFactory) } diff --git a/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go b/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go index 4f931413..b462f63d 100644 --- a/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go +++ b/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go @@ -28,138 +28,37 @@ import ( "github.com/rancher/wrangler/pkg/kv" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" ) // APIServiceController interface for managing APIService resources. type APIServiceController interface { - generic.ControllerMeta - APIServiceClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync APIServiceHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync APIServiceHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() APIServiceCache + generic.NonNamespacedControllerInterface[*v1.APIService, *v1.APIServiceList] } // APIServiceClient interface for managing APIService resources in Kubernetes. type APIServiceClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.APIService) (*v1.APIService, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.APIService) (*v1.APIService, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.APIService) (*v1.APIService, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.APIService, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.APIServiceList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.APIService, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.APIService, *v1.APIServiceList], error) + generic.NonNamespacedClientInterface[*v1.APIService, *v1.APIServiceList] } // APIServiceCache interface for retrieving APIService resources in memory. type APIServiceCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.APIService, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.APIService, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer APIServiceIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.APIService, error) -} - -// APIServiceHandler is function for performing any potential modifications to a APIService resource. -type APIServiceHandler func(string, *v1.APIService) (*v1.APIService, error) - -// APIServiceIndexer computes a set of indexed values for the provided object. -type APIServiceIndexer func(obj *v1.APIService) ([]string, error) - -// APIServiceGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to APIServiceController interface. -type APIServiceGenericController struct { - generic.NonNamespacedControllerInterface[*v1.APIService, *v1.APIServiceList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *APIServiceGenericController) OnChange(ctx context.Context, name string, sync APIServiceHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.APIService](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *APIServiceGenericController) OnRemove(ctx context.Context, name string, sync APIServiceHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.APIService](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *APIServiceGenericController) Cache() APIServiceCache { - return &APIServiceGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// APIServiceGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to APIServiceCache interface. -type APIServiceGenericCache struct { generic.NonNamespacedCacheInterface[*v1.APIService] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c APIServiceGenericCache) AddIndexer(indexName string, indexer APIServiceIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.APIService](indexer)) -} - type APIServiceStatusHandler func(obj *v1.APIService, status v1.APIServiceStatus) (v1.APIServiceStatus, error) type APIServiceGeneratingHandler func(obj *v1.APIService, status v1.APIServiceStatus) ([]runtime.Object, v1.APIServiceStatus, error) -func FromAPIServiceHandlerToHandler(sync APIServiceHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.APIService](sync)) -} - func RegisterAPIServiceStatusHandler(ctx context.Context, controller APIServiceController, condition condition.Cond, name string, handler APIServiceStatusHandler) { statusHandler := &aPIServiceStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromAPIServiceHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterAPIServiceGeneratingHandler(ctx context.Context, controller APIServiceController, apply apply.Apply, diff --git a/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go b/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go index 29d1f251..398bd811 100644 --- a/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go +++ b/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go @@ -45,7 +45,5 @@ type version struct { } func (v *version) APIService() APIServiceController { - return &APIServiceGenericController{ - generic.NewNonNamespacedController[*v1.APIService, *v1.APIServiceList](schema.GroupVersionKind{Group: "apiregistration.k8s.io", Version: "v1", Kind: "APIService"}, "apiservices", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.APIService, *v1.APIServiceList](schema.GroupVersionKind{Group: "apiregistration.k8s.io", Version: "v1", Kind: "APIService"}, "apiservices", v.controllerFactory) } diff --git a/pkg/generated/controllers/apps/v1/daemonset.go b/pkg/generated/controllers/apps/v1/daemonset.go index 17246e9a..81dc9926 100644 --- a/pkg/generated/controllers/apps/v1/daemonset.go +++ b/pkg/generated/controllers/apps/v1/daemonset.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // DaemonSetController interface for managing DaemonSet resources. type DaemonSetController interface { - generic.ControllerMeta - DaemonSetClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync DaemonSetHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync DaemonSetHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() DaemonSetCache + generic.ControllerInterface[*v1.DaemonSet, *v1.DaemonSetList] } // DaemonSetClient interface for managing DaemonSet resources in Kubernetes. type DaemonSetClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.DaemonSet) (*v1.DaemonSet, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.DaemonSet) (*v1.DaemonSet, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.DaemonSet) (*v1.DaemonSet, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.DaemonSet, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.DaemonSetList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.DaemonSet, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.DaemonSet, *v1.DaemonSetList], error) + generic.ClientInterface[*v1.DaemonSet, *v1.DaemonSetList] } // DaemonSetCache interface for retrieving DaemonSet resources in memory. type DaemonSetCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.DaemonSet, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.DaemonSet, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer DaemonSetIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.DaemonSet, error) -} - -// DaemonSetHandler is function for performing any potential modifications to a DaemonSet resource. -type DaemonSetHandler func(string, *v1.DaemonSet) (*v1.DaemonSet, error) - -// DaemonSetIndexer computes a set of indexed values for the provided object. -type DaemonSetIndexer func(obj *v1.DaemonSet) ([]string, error) - -// DaemonSetGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to DaemonSetController interface. -type DaemonSetGenericController struct { - generic.ControllerInterface[*v1.DaemonSet, *v1.DaemonSetList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *DaemonSetGenericController) OnChange(ctx context.Context, name string, sync DaemonSetHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.DaemonSet](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *DaemonSetGenericController) OnRemove(ctx context.Context, name string, sync DaemonSetHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.DaemonSet](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *DaemonSetGenericController) Cache() DaemonSetCache { - return &DaemonSetGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// DaemonSetGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to DaemonSetCache interface. -type DaemonSetGenericCache struct { generic.CacheInterface[*v1.DaemonSet] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c DaemonSetGenericCache) AddIndexer(indexName string, indexer DaemonSetIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.DaemonSet](indexer)) -} - type DaemonSetStatusHandler func(obj *v1.DaemonSet, status v1.DaemonSetStatus) (v1.DaemonSetStatus, error) type DaemonSetGeneratingHandler func(obj *v1.DaemonSet, status v1.DaemonSetStatus) ([]runtime.Object, v1.DaemonSetStatus, error) -func FromDaemonSetHandlerToHandler(sync DaemonSetHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.DaemonSet](sync)) -} - func RegisterDaemonSetStatusHandler(ctx context.Context, controller DaemonSetController, condition condition.Cond, name string, handler DaemonSetStatusHandler) { statusHandler := &daemonSetStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromDaemonSetHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterDaemonSetGeneratingHandler(ctx context.Context, controller DaemonSetController, apply apply.Apply, diff --git a/pkg/generated/controllers/apps/v1/deployment.go b/pkg/generated/controllers/apps/v1/deployment.go index 15850b77..27daa00d 100644 --- a/pkg/generated/controllers/apps/v1/deployment.go +++ b/pkg/generated/controllers/apps/v1/deployment.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // DeploymentController interface for managing Deployment resources. type DeploymentController interface { - generic.ControllerMeta - DeploymentClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync DeploymentHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync DeploymentHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() DeploymentCache + generic.ControllerInterface[*v1.Deployment, *v1.DeploymentList] } // DeploymentClient interface for managing Deployment resources in Kubernetes. type DeploymentClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Deployment) (*v1.Deployment, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Deployment) (*v1.Deployment, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.Deployment) (*v1.Deployment, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Deployment, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.DeploymentList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Deployment, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Deployment, *v1.DeploymentList], error) + generic.ClientInterface[*v1.Deployment, *v1.DeploymentList] } // DeploymentCache interface for retrieving Deployment resources in memory. type DeploymentCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Deployment, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Deployment, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer DeploymentIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Deployment, error) -} - -// DeploymentHandler is function for performing any potential modifications to a Deployment resource. -type DeploymentHandler func(string, *v1.Deployment) (*v1.Deployment, error) - -// DeploymentIndexer computes a set of indexed values for the provided object. -type DeploymentIndexer func(obj *v1.Deployment) ([]string, error) - -// DeploymentGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to DeploymentController interface. -type DeploymentGenericController struct { - generic.ControllerInterface[*v1.Deployment, *v1.DeploymentList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *DeploymentGenericController) OnChange(ctx context.Context, name string, sync DeploymentHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Deployment](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *DeploymentGenericController) OnRemove(ctx context.Context, name string, sync DeploymentHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Deployment](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *DeploymentGenericController) Cache() DeploymentCache { - return &DeploymentGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// DeploymentGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to DeploymentCache interface. -type DeploymentGenericCache struct { generic.CacheInterface[*v1.Deployment] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c DeploymentGenericCache) AddIndexer(indexName string, indexer DeploymentIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Deployment](indexer)) -} - type DeploymentStatusHandler func(obj *v1.Deployment, status v1.DeploymentStatus) (v1.DeploymentStatus, error) type DeploymentGeneratingHandler func(obj *v1.Deployment, status v1.DeploymentStatus) ([]runtime.Object, v1.DeploymentStatus, error) -func FromDeploymentHandlerToHandler(sync DeploymentHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.Deployment](sync)) -} - func RegisterDeploymentStatusHandler(ctx context.Context, controller DeploymentController, condition condition.Cond, name string, handler DeploymentStatusHandler) { statusHandler := &deploymentStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromDeploymentHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterDeploymentGeneratingHandler(ctx context.Context, controller DeploymentController, apply apply.Apply, diff --git a/pkg/generated/controllers/apps/v1/interface.go b/pkg/generated/controllers/apps/v1/interface.go index f50de14e..0968f1b1 100644 --- a/pkg/generated/controllers/apps/v1/interface.go +++ b/pkg/generated/controllers/apps/v1/interface.go @@ -47,19 +47,13 @@ type version struct { } func (v *version) DaemonSet() DaemonSetController { - return &DaemonSetGenericController{ - generic.NewController[*v1.DaemonSet, *v1.DaemonSetList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"}, "daemonsets", true, v.controllerFactory), - } + return generic.NewController[*v1.DaemonSet, *v1.DaemonSetList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"}, "daemonsets", true, v.controllerFactory) } func (v *version) Deployment() DeploymentController { - return &DeploymentGenericController{ - generic.NewController[*v1.Deployment, *v1.DeploymentList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}, "deployments", true, v.controllerFactory), - } + return generic.NewController[*v1.Deployment, *v1.DeploymentList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}, "deployments", true, v.controllerFactory) } func (v *version) StatefulSet() StatefulSetController { - return &StatefulSetGenericController{ - generic.NewController[*v1.StatefulSet, *v1.StatefulSetList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}, "statefulsets", true, v.controllerFactory), - } + return generic.NewController[*v1.StatefulSet, *v1.StatefulSetList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}, "statefulsets", true, v.controllerFactory) } diff --git a/pkg/generated/controllers/apps/v1/statefulset.go b/pkg/generated/controllers/apps/v1/statefulset.go index 2adfaa3e..58b827fa 100644 --- a/pkg/generated/controllers/apps/v1/statefulset.go +++ b/pkg/generated/controllers/apps/v1/statefulset.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // StatefulSetController interface for managing StatefulSet resources. type StatefulSetController interface { - generic.ControllerMeta - StatefulSetClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync StatefulSetHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync StatefulSetHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() StatefulSetCache + generic.ControllerInterface[*v1.StatefulSet, *v1.StatefulSetList] } // StatefulSetClient interface for managing StatefulSet resources in Kubernetes. type StatefulSetClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.StatefulSet) (*v1.StatefulSet, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.StatefulSet) (*v1.StatefulSet, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.StatefulSet) (*v1.StatefulSet, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.StatefulSet, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.StatefulSetList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.StatefulSet, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.StatefulSet, *v1.StatefulSetList], error) + generic.ClientInterface[*v1.StatefulSet, *v1.StatefulSetList] } // StatefulSetCache interface for retrieving StatefulSet resources in memory. type StatefulSetCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.StatefulSet, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.StatefulSet, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer StatefulSetIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.StatefulSet, error) -} - -// StatefulSetHandler is function for performing any potential modifications to a StatefulSet resource. -type StatefulSetHandler func(string, *v1.StatefulSet) (*v1.StatefulSet, error) - -// StatefulSetIndexer computes a set of indexed values for the provided object. -type StatefulSetIndexer func(obj *v1.StatefulSet) ([]string, error) - -// StatefulSetGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to StatefulSetController interface. -type StatefulSetGenericController struct { - generic.ControllerInterface[*v1.StatefulSet, *v1.StatefulSetList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *StatefulSetGenericController) OnChange(ctx context.Context, name string, sync StatefulSetHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.StatefulSet](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *StatefulSetGenericController) OnRemove(ctx context.Context, name string, sync StatefulSetHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.StatefulSet](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *StatefulSetGenericController) Cache() StatefulSetCache { - return &StatefulSetGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// StatefulSetGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to StatefulSetCache interface. -type StatefulSetGenericCache struct { generic.CacheInterface[*v1.StatefulSet] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c StatefulSetGenericCache) AddIndexer(indexName string, indexer StatefulSetIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.StatefulSet](indexer)) -} - type StatefulSetStatusHandler func(obj *v1.StatefulSet, status v1.StatefulSetStatus) (v1.StatefulSetStatus, error) type StatefulSetGeneratingHandler func(obj *v1.StatefulSet, status v1.StatefulSetStatus) ([]runtime.Object, v1.StatefulSetStatus, error) -func FromStatefulSetHandlerToHandler(sync StatefulSetHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.StatefulSet](sync)) -} - func RegisterStatefulSetStatusHandler(ctx context.Context, controller StatefulSetController, condition condition.Cond, name string, handler StatefulSetStatusHandler) { statusHandler := &statefulSetStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromStatefulSetHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterStatefulSetGeneratingHandler(ctx context.Context, controller StatefulSetController, apply apply.Apply, diff --git a/pkg/generated/controllers/batch/v1/interface.go b/pkg/generated/controllers/batch/v1/interface.go index 68b38507..1b1c359a 100644 --- a/pkg/generated/controllers/batch/v1/interface.go +++ b/pkg/generated/controllers/batch/v1/interface.go @@ -45,7 +45,5 @@ type version struct { } func (v *version) Job() JobController { - return &JobGenericController{ - generic.NewController[*v1.Job, *v1.JobList](schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"}, "jobs", true, v.controllerFactory), - } + return generic.NewController[*v1.Job, *v1.JobList](schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"}, "jobs", true, v.controllerFactory) } diff --git a/pkg/generated/controllers/batch/v1/job.go b/pkg/generated/controllers/batch/v1/job.go index 5872ac8e..abfde6e1 100644 --- a/pkg/generated/controllers/batch/v1/job.go +++ b/pkg/generated/controllers/batch/v1/job.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/batch/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // JobController interface for managing Job resources. type JobController interface { - generic.ControllerMeta - JobClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync JobHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync JobHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() JobCache + generic.ControllerInterface[*v1.Job, *v1.JobList] } // JobClient interface for managing Job resources in Kubernetes. type JobClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Job) (*v1.Job, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Job) (*v1.Job, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.Job) (*v1.Job, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Job, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.JobList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Job, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Job, *v1.JobList], error) + generic.ClientInterface[*v1.Job, *v1.JobList] } // JobCache interface for retrieving Job resources in memory. type JobCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Job, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Job, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer JobIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Job, error) -} - -// JobHandler is function for performing any potential modifications to a Job resource. -type JobHandler func(string, *v1.Job) (*v1.Job, error) - -// JobIndexer computes a set of indexed values for the provided object. -type JobIndexer func(obj *v1.Job) ([]string, error) - -// JobGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to JobController interface. -type JobGenericController struct { - generic.ControllerInterface[*v1.Job, *v1.JobList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *JobGenericController) OnChange(ctx context.Context, name string, sync JobHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Job](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *JobGenericController) OnRemove(ctx context.Context, name string, sync JobHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Job](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *JobGenericController) Cache() JobCache { - return &JobGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// JobGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to JobCache interface. -type JobGenericCache struct { generic.CacheInterface[*v1.Job] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c JobGenericCache) AddIndexer(indexName string, indexer JobIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Job](indexer)) -} - type JobStatusHandler func(obj *v1.Job, status v1.JobStatus) (v1.JobStatus, error) type JobGeneratingHandler func(obj *v1.Job, status v1.JobStatus) ([]runtime.Object, v1.JobStatus, error) -func FromJobHandlerToHandler(sync JobHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.Job](sync)) -} - func RegisterJobStatusHandler(ctx context.Context, controller JobController, condition condition.Cond, name string, handler JobStatusHandler) { statusHandler := &jobStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromJobHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterJobGeneratingHandler(ctx context.Context, controller JobController, apply apply.Apply, diff --git a/pkg/generated/controllers/coordination.k8s.io/v1/interface.go b/pkg/generated/controllers/coordination.k8s.io/v1/interface.go index aaf4d3c8..060d9f10 100644 --- a/pkg/generated/controllers/coordination.k8s.io/v1/interface.go +++ b/pkg/generated/controllers/coordination.k8s.io/v1/interface.go @@ -45,7 +45,5 @@ type version struct { } func (v *version) Lease() LeaseController { - return &LeaseGenericController{ - generic.NewController[*v1.Lease, *v1.LeaseList](schema.GroupVersionKind{Group: "coordination.k8s.io", Version: "v1", Kind: "Lease"}, "leases", true, v.controllerFactory), - } + return generic.NewController[*v1.Lease, *v1.LeaseList](schema.GroupVersionKind{Group: "coordination.k8s.io", Version: "v1", Kind: "Lease"}, "leases", true, v.controllerFactory) } diff --git a/pkg/generated/controllers/coordination.k8s.io/v1/lease.go b/pkg/generated/controllers/coordination.k8s.io/v1/lease.go index d5fd63a7..ef5f6bbc 100644 --- a/pkg/generated/controllers/coordination.k8s.io/v1/lease.go +++ b/pkg/generated/controllers/coordination.k8s.io/v1/lease.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/coordination/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // LeaseController interface for managing Lease resources. type LeaseController interface { - generic.ControllerMeta - LeaseClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync LeaseHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync LeaseHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() LeaseCache + generic.ControllerInterface[*v1.Lease, *v1.LeaseList] } // LeaseClient interface for managing Lease resources in Kubernetes. type LeaseClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Lease) (*v1.Lease, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Lease) (*v1.Lease, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Lease, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.LeaseList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Lease, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Lease, *v1.LeaseList], error) + generic.ClientInterface[*v1.Lease, *v1.LeaseList] } // LeaseCache interface for retrieving Lease resources in memory. type LeaseCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Lease, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Lease, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer LeaseIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Lease, error) -} - -// LeaseHandler is function for performing any potential modifications to a Lease resource. -type LeaseHandler func(string, *v1.Lease) (*v1.Lease, error) - -// LeaseIndexer computes a set of indexed values for the provided object. -type LeaseIndexer func(obj *v1.Lease) ([]string, error) - -// LeaseGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to LeaseController interface. -type LeaseGenericController struct { - generic.ControllerInterface[*v1.Lease, *v1.LeaseList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *LeaseGenericController) OnChange(ctx context.Context, name string, sync LeaseHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Lease](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *LeaseGenericController) OnRemove(ctx context.Context, name string, sync LeaseHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Lease](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *LeaseGenericController) Cache() LeaseCache { - return &LeaseGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// LeaseGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to LeaseCache interface. -type LeaseGenericCache struct { generic.CacheInterface[*v1.Lease] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c LeaseGenericCache) AddIndexer(indexName string, indexer LeaseIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Lease](indexer)) -} diff --git a/pkg/generated/controllers/core/v1/configmap.go b/pkg/generated/controllers/core/v1/configmap.go index edd6242f..b5b7bdff 100644 --- a/pkg/generated/controllers/core/v1/configmap.go +++ b/pkg/generated/controllers/core/v1/configmap.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // ConfigMapController interface for managing ConfigMap resources. type ConfigMapController interface { - generic.ControllerMeta - ConfigMapClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync ConfigMapHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync ConfigMapHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() ConfigMapCache + generic.ControllerInterface[*v1.ConfigMap, *v1.ConfigMapList] } // ConfigMapClient interface for managing ConfigMap resources in Kubernetes. type ConfigMapClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.ConfigMap) (*v1.ConfigMap, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.ConfigMap) (*v1.ConfigMap, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.ConfigMap, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.ConfigMapList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ConfigMap, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.ConfigMap, *v1.ConfigMapList], error) + generic.ClientInterface[*v1.ConfigMap, *v1.ConfigMapList] } // ConfigMapCache interface for retrieving ConfigMap resources in memory. type ConfigMapCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.ConfigMap, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.ConfigMap, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer ConfigMapIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.ConfigMap, error) -} - -// ConfigMapHandler is function for performing any potential modifications to a ConfigMap resource. -type ConfigMapHandler func(string, *v1.ConfigMap) (*v1.ConfigMap, error) - -// ConfigMapIndexer computes a set of indexed values for the provided object. -type ConfigMapIndexer func(obj *v1.ConfigMap) ([]string, error) - -// ConfigMapGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to ConfigMapController interface. -type ConfigMapGenericController struct { - generic.ControllerInterface[*v1.ConfigMap, *v1.ConfigMapList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *ConfigMapGenericController) OnChange(ctx context.Context, name string, sync ConfigMapHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.ConfigMap](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *ConfigMapGenericController) OnRemove(ctx context.Context, name string, sync ConfigMapHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.ConfigMap](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *ConfigMapGenericController) Cache() ConfigMapCache { - return &ConfigMapGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// ConfigMapGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to ConfigMapCache interface. -type ConfigMapGenericCache struct { generic.CacheInterface[*v1.ConfigMap] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c ConfigMapGenericCache) AddIndexer(indexName string, indexer ConfigMapIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.ConfigMap](indexer)) -} diff --git a/pkg/generated/controllers/core/v1/endpoints.go b/pkg/generated/controllers/core/v1/endpoints.go index 9dac8254..a6d0c145 100644 --- a/pkg/generated/controllers/core/v1/endpoints.go +++ b/pkg/generated/controllers/core/v1/endpoints.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // EndpointsController interface for managing Endpoints resources. type EndpointsController interface { - generic.ControllerMeta - EndpointsClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync EndpointsHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync EndpointsHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() EndpointsCache + generic.ControllerInterface[*v1.Endpoints, *v1.EndpointsList] } // EndpointsClient interface for managing Endpoints resources in Kubernetes. type EndpointsClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Endpoints) (*v1.Endpoints, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Endpoints) (*v1.Endpoints, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Endpoints, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.EndpointsList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Endpoints, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Endpoints, *v1.EndpointsList], error) + generic.ClientInterface[*v1.Endpoints, *v1.EndpointsList] } // EndpointsCache interface for retrieving Endpoints resources in memory. type EndpointsCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Endpoints, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Endpoints, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer EndpointsIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Endpoints, error) -} - -// EndpointsHandler is function for performing any potential modifications to a Endpoints resource. -type EndpointsHandler func(string, *v1.Endpoints) (*v1.Endpoints, error) - -// EndpointsIndexer computes a set of indexed values for the provided object. -type EndpointsIndexer func(obj *v1.Endpoints) ([]string, error) - -// EndpointsGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to EndpointsController interface. -type EndpointsGenericController struct { - generic.ControllerInterface[*v1.Endpoints, *v1.EndpointsList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *EndpointsGenericController) OnChange(ctx context.Context, name string, sync EndpointsHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Endpoints](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *EndpointsGenericController) OnRemove(ctx context.Context, name string, sync EndpointsHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Endpoints](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *EndpointsGenericController) Cache() EndpointsCache { - return &EndpointsGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// EndpointsGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to EndpointsCache interface. -type EndpointsGenericCache struct { generic.CacheInterface[*v1.Endpoints] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c EndpointsGenericCache) AddIndexer(indexName string, indexer EndpointsIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Endpoints](indexer)) -} diff --git a/pkg/generated/controllers/core/v1/event.go b/pkg/generated/controllers/core/v1/event.go index de50df65..f307ce33 100644 --- a/pkg/generated/controllers/core/v1/event.go +++ b/pkg/generated/controllers/core/v1/event.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // EventController interface for managing Event resources. type EventController interface { - generic.ControllerMeta - EventClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync EventHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync EventHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() EventCache + generic.ControllerInterface[*v1.Event, *v1.EventList] } // EventClient interface for managing Event resources in Kubernetes. type EventClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Event) (*v1.Event, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Event) (*v1.Event, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Event, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.EventList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Event, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Event, *v1.EventList], error) + generic.ClientInterface[*v1.Event, *v1.EventList] } // EventCache interface for retrieving Event resources in memory. type EventCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Event, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Event, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer EventIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Event, error) -} - -// EventHandler is function for performing any potential modifications to a Event resource. -type EventHandler func(string, *v1.Event) (*v1.Event, error) - -// EventIndexer computes a set of indexed values for the provided object. -type EventIndexer func(obj *v1.Event) ([]string, error) - -// EventGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to EventController interface. -type EventGenericController struct { - generic.ControllerInterface[*v1.Event, *v1.EventList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *EventGenericController) OnChange(ctx context.Context, name string, sync EventHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Event](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *EventGenericController) OnRemove(ctx context.Context, name string, sync EventHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Event](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *EventGenericController) Cache() EventCache { - return &EventGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// EventGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to EventCache interface. -type EventGenericCache struct { generic.CacheInterface[*v1.Event] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c EventGenericCache) AddIndexer(indexName string, indexer EventIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Event](indexer)) -} diff --git a/pkg/generated/controllers/core/v1/interface.go b/pkg/generated/controllers/core/v1/interface.go index 150ea2c7..c0923e6a 100644 --- a/pkg/generated/controllers/core/v1/interface.go +++ b/pkg/generated/controllers/core/v1/interface.go @@ -55,67 +55,45 @@ type version struct { } func (v *version) ConfigMap() ConfigMapController { - return &ConfigMapGenericController{ - generic.NewController[*v1.ConfigMap, *v1.ConfigMapList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"}, "configmaps", true, v.controllerFactory), - } + return generic.NewController[*v1.ConfigMap, *v1.ConfigMapList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"}, "configmaps", true, v.controllerFactory) } func (v *version) Endpoints() EndpointsController { - return &EndpointsGenericController{ - generic.NewController[*v1.Endpoints, *v1.EndpointsList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Endpoints"}, "endpoints", true, v.controllerFactory), - } + return generic.NewController[*v1.Endpoints, *v1.EndpointsList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Endpoints"}, "endpoints", true, v.controllerFactory) } func (v *version) Event() EventController { - return &EventGenericController{ - generic.NewController[*v1.Event, *v1.EventList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Event"}, "events", true, v.controllerFactory), - } + return generic.NewController[*v1.Event, *v1.EventList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Event"}, "events", true, v.controllerFactory) } func (v *version) Namespace() NamespaceController { - return &NamespaceGenericController{ - generic.NewNonNamespacedController[*v1.Namespace, *v1.NamespaceList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"}, "namespaces", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.Namespace, *v1.NamespaceList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"}, "namespaces", v.controllerFactory) } func (v *version) Node() NodeController { - return &NodeGenericController{ - generic.NewNonNamespacedController[*v1.Node, *v1.NodeList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"}, "nodes", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.Node, *v1.NodeList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"}, "nodes", v.controllerFactory) } func (v *version) PersistentVolume() PersistentVolumeController { - return &PersistentVolumeGenericController{ - generic.NewNonNamespacedController[*v1.PersistentVolume, *v1.PersistentVolumeList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolume"}, "persistentvolumes", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.PersistentVolume, *v1.PersistentVolumeList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolume"}, "persistentvolumes", v.controllerFactory) } func (v *version) PersistentVolumeClaim() PersistentVolumeClaimController { - return &PersistentVolumeClaimGenericController{ - generic.NewController[*v1.PersistentVolumeClaim, *v1.PersistentVolumeClaimList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolumeClaim"}, "persistentvolumeclaims", true, v.controllerFactory), - } + return generic.NewController[*v1.PersistentVolumeClaim, *v1.PersistentVolumeClaimList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolumeClaim"}, "persistentvolumeclaims", true, v.controllerFactory) } func (v *version) Pod() PodController { - return &PodGenericController{ - generic.NewController[*v1.Pod, *v1.PodList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"}, "pods", true, v.controllerFactory), - } + return generic.NewController[*v1.Pod, *v1.PodList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"}, "pods", true, v.controllerFactory) } func (v *version) Secret() SecretController { - return &SecretGenericController{ - generic.NewController[*v1.Secret, *v1.SecretList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"}, "secrets", true, v.controllerFactory), - } + return generic.NewController[*v1.Secret, *v1.SecretList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"}, "secrets", true, v.controllerFactory) } func (v *version) Service() ServiceController { - return &ServiceGenericController{ - generic.NewController[*v1.Service, *v1.ServiceList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"}, "services", true, v.controllerFactory), - } + return generic.NewController[*v1.Service, *v1.ServiceList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"}, "services", true, v.controllerFactory) } func (v *version) ServiceAccount() ServiceAccountController { - return &ServiceAccountGenericController{ - generic.NewController[*v1.ServiceAccount, *v1.ServiceAccountList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ServiceAccount"}, "serviceaccounts", true, v.controllerFactory), - } + return generic.NewController[*v1.ServiceAccount, *v1.ServiceAccountList](schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ServiceAccount"}, "serviceaccounts", true, v.controllerFactory) } diff --git a/pkg/generated/controllers/core/v1/namespace.go b/pkg/generated/controllers/core/v1/namespace.go index 2af1d148..7ea3d7d5 100644 --- a/pkg/generated/controllers/core/v1/namespace.go +++ b/pkg/generated/controllers/core/v1/namespace.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // NamespaceController interface for managing Namespace resources. type NamespaceController interface { - generic.ControllerMeta - NamespaceClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync NamespaceHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync NamespaceHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() NamespaceCache + generic.NonNamespacedControllerInterface[*v1.Namespace, *v1.NamespaceList] } // NamespaceClient interface for managing Namespace resources in Kubernetes. type NamespaceClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Namespace) (*v1.Namespace, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Namespace) (*v1.Namespace, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.Namespace) (*v1.Namespace, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.Namespace, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.NamespaceList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Namespace, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.Namespace, *v1.NamespaceList], error) + generic.NonNamespacedClientInterface[*v1.Namespace, *v1.NamespaceList] } // NamespaceCache interface for retrieving Namespace resources in memory. type NamespaceCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.Namespace, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.Namespace, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer NamespaceIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Namespace, error) -} - -// NamespaceHandler is function for performing any potential modifications to a Namespace resource. -type NamespaceHandler func(string, *v1.Namespace) (*v1.Namespace, error) - -// NamespaceIndexer computes a set of indexed values for the provided object. -type NamespaceIndexer func(obj *v1.Namespace) ([]string, error) - -// NamespaceGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to NamespaceController interface. -type NamespaceGenericController struct { - generic.NonNamespacedControllerInterface[*v1.Namespace, *v1.NamespaceList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *NamespaceGenericController) OnChange(ctx context.Context, name string, sync NamespaceHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Namespace](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *NamespaceGenericController) OnRemove(ctx context.Context, name string, sync NamespaceHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Namespace](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *NamespaceGenericController) Cache() NamespaceCache { - return &NamespaceGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// NamespaceGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to NamespaceCache interface. -type NamespaceGenericCache struct { generic.NonNamespacedCacheInterface[*v1.Namespace] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c NamespaceGenericCache) AddIndexer(indexName string, indexer NamespaceIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Namespace](indexer)) -} - type NamespaceStatusHandler func(obj *v1.Namespace, status v1.NamespaceStatus) (v1.NamespaceStatus, error) type NamespaceGeneratingHandler func(obj *v1.Namespace, status v1.NamespaceStatus) ([]runtime.Object, v1.NamespaceStatus, error) -func FromNamespaceHandlerToHandler(sync NamespaceHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.Namespace](sync)) -} - func RegisterNamespaceStatusHandler(ctx context.Context, controller NamespaceController, condition condition.Cond, name string, handler NamespaceStatusHandler) { statusHandler := &namespaceStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromNamespaceHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterNamespaceGeneratingHandler(ctx context.Context, controller NamespaceController, apply apply.Apply, diff --git a/pkg/generated/controllers/core/v1/node.go b/pkg/generated/controllers/core/v1/node.go index 2ac5b38d..03508ad7 100644 --- a/pkg/generated/controllers/core/v1/node.go +++ b/pkg/generated/controllers/core/v1/node.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // NodeController interface for managing Node resources. type NodeController interface { - generic.ControllerMeta - NodeClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync NodeHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync NodeHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() NodeCache + generic.NonNamespacedControllerInterface[*v1.Node, *v1.NodeList] } // NodeClient interface for managing Node resources in Kubernetes. type NodeClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Node) (*v1.Node, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Node) (*v1.Node, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.Node) (*v1.Node, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.Node, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.NodeList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Node, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.Node, *v1.NodeList], error) + generic.NonNamespacedClientInterface[*v1.Node, *v1.NodeList] } // NodeCache interface for retrieving Node resources in memory. type NodeCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.Node, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.Node, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer NodeIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Node, error) -} - -// NodeHandler is function for performing any potential modifications to a Node resource. -type NodeHandler func(string, *v1.Node) (*v1.Node, error) - -// NodeIndexer computes a set of indexed values for the provided object. -type NodeIndexer func(obj *v1.Node) ([]string, error) - -// NodeGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to NodeController interface. -type NodeGenericController struct { - generic.NonNamespacedControllerInterface[*v1.Node, *v1.NodeList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *NodeGenericController) OnChange(ctx context.Context, name string, sync NodeHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Node](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *NodeGenericController) OnRemove(ctx context.Context, name string, sync NodeHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Node](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *NodeGenericController) Cache() NodeCache { - return &NodeGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// NodeGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to NodeCache interface. -type NodeGenericCache struct { generic.NonNamespacedCacheInterface[*v1.Node] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c NodeGenericCache) AddIndexer(indexName string, indexer NodeIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Node](indexer)) -} - type NodeStatusHandler func(obj *v1.Node, status v1.NodeStatus) (v1.NodeStatus, error) type NodeGeneratingHandler func(obj *v1.Node, status v1.NodeStatus) ([]runtime.Object, v1.NodeStatus, error) -func FromNodeHandlerToHandler(sync NodeHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.Node](sync)) -} - func RegisterNodeStatusHandler(ctx context.Context, controller NodeController, condition condition.Cond, name string, handler NodeStatusHandler) { statusHandler := &nodeStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromNodeHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterNodeGeneratingHandler(ctx context.Context, controller NodeController, apply apply.Apply, diff --git a/pkg/generated/controllers/core/v1/persistentvolume.go b/pkg/generated/controllers/core/v1/persistentvolume.go index 88ef36d2..13db2a56 100644 --- a/pkg/generated/controllers/core/v1/persistentvolume.go +++ b/pkg/generated/controllers/core/v1/persistentvolume.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // PersistentVolumeController interface for managing PersistentVolume resources. type PersistentVolumeController interface { - generic.ControllerMeta - PersistentVolumeClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync PersistentVolumeHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync PersistentVolumeHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() PersistentVolumeCache + generic.NonNamespacedControllerInterface[*v1.PersistentVolume, *v1.PersistentVolumeList] } // PersistentVolumeClient interface for managing PersistentVolume resources in Kubernetes. type PersistentVolumeClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.PersistentVolume) (*v1.PersistentVolume, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.PersistentVolume) (*v1.PersistentVolume, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.PersistentVolume) (*v1.PersistentVolume, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.PersistentVolume, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.PersistentVolumeList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.PersistentVolume, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.PersistentVolume, *v1.PersistentVolumeList], error) + generic.NonNamespacedClientInterface[*v1.PersistentVolume, *v1.PersistentVolumeList] } // PersistentVolumeCache interface for retrieving PersistentVolume resources in memory. type PersistentVolumeCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.PersistentVolume, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.PersistentVolume, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer PersistentVolumeIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.PersistentVolume, error) -} - -// PersistentVolumeHandler is function for performing any potential modifications to a PersistentVolume resource. -type PersistentVolumeHandler func(string, *v1.PersistentVolume) (*v1.PersistentVolume, error) - -// PersistentVolumeIndexer computes a set of indexed values for the provided object. -type PersistentVolumeIndexer func(obj *v1.PersistentVolume) ([]string, error) - -// PersistentVolumeGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to PersistentVolumeController interface. -type PersistentVolumeGenericController struct { - generic.NonNamespacedControllerInterface[*v1.PersistentVolume, *v1.PersistentVolumeList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *PersistentVolumeGenericController) OnChange(ctx context.Context, name string, sync PersistentVolumeHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.PersistentVolume](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *PersistentVolumeGenericController) OnRemove(ctx context.Context, name string, sync PersistentVolumeHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.PersistentVolume](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *PersistentVolumeGenericController) Cache() PersistentVolumeCache { - return &PersistentVolumeGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// PersistentVolumeGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to PersistentVolumeCache interface. -type PersistentVolumeGenericCache struct { generic.NonNamespacedCacheInterface[*v1.PersistentVolume] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c PersistentVolumeGenericCache) AddIndexer(indexName string, indexer PersistentVolumeIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.PersistentVolume](indexer)) -} - type PersistentVolumeStatusHandler func(obj *v1.PersistentVolume, status v1.PersistentVolumeStatus) (v1.PersistentVolumeStatus, error) type PersistentVolumeGeneratingHandler func(obj *v1.PersistentVolume, status v1.PersistentVolumeStatus) ([]runtime.Object, v1.PersistentVolumeStatus, error) -func FromPersistentVolumeHandlerToHandler(sync PersistentVolumeHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.PersistentVolume](sync)) -} - func RegisterPersistentVolumeStatusHandler(ctx context.Context, controller PersistentVolumeController, condition condition.Cond, name string, handler PersistentVolumeStatusHandler) { statusHandler := &persistentVolumeStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromPersistentVolumeHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterPersistentVolumeGeneratingHandler(ctx context.Context, controller PersistentVolumeController, apply apply.Apply, diff --git a/pkg/generated/controllers/core/v1/persistentvolumeclaim.go b/pkg/generated/controllers/core/v1/persistentvolumeclaim.go index f52f45e3..9b9abfff 100644 --- a/pkg/generated/controllers/core/v1/persistentvolumeclaim.go +++ b/pkg/generated/controllers/core/v1/persistentvolumeclaim.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // PersistentVolumeClaimController interface for managing PersistentVolumeClaim resources. type PersistentVolumeClaimController interface { - generic.ControllerMeta - PersistentVolumeClaimClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync PersistentVolumeClaimHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync PersistentVolumeClaimHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() PersistentVolumeClaimCache + generic.ControllerInterface[*v1.PersistentVolumeClaim, *v1.PersistentVolumeClaimList] } // PersistentVolumeClaimClient interface for managing PersistentVolumeClaim resources in Kubernetes. type PersistentVolumeClaimClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.PersistentVolumeClaim, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.PersistentVolumeClaimList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.PersistentVolumeClaim, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.PersistentVolumeClaim, *v1.PersistentVolumeClaimList], error) + generic.ClientInterface[*v1.PersistentVolumeClaim, *v1.PersistentVolumeClaimList] } // PersistentVolumeClaimCache interface for retrieving PersistentVolumeClaim resources in memory. type PersistentVolumeClaimCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.PersistentVolumeClaim, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.PersistentVolumeClaim, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer PersistentVolumeClaimIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.PersistentVolumeClaim, error) -} - -// PersistentVolumeClaimHandler is function for performing any potential modifications to a PersistentVolumeClaim resource. -type PersistentVolumeClaimHandler func(string, *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) - -// PersistentVolumeClaimIndexer computes a set of indexed values for the provided object. -type PersistentVolumeClaimIndexer func(obj *v1.PersistentVolumeClaim) ([]string, error) - -// PersistentVolumeClaimGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to PersistentVolumeClaimController interface. -type PersistentVolumeClaimGenericController struct { - generic.ControllerInterface[*v1.PersistentVolumeClaim, *v1.PersistentVolumeClaimList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *PersistentVolumeClaimGenericController) OnChange(ctx context.Context, name string, sync PersistentVolumeClaimHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.PersistentVolumeClaim](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *PersistentVolumeClaimGenericController) OnRemove(ctx context.Context, name string, sync PersistentVolumeClaimHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.PersistentVolumeClaim](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *PersistentVolumeClaimGenericController) Cache() PersistentVolumeClaimCache { - return &PersistentVolumeClaimGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// PersistentVolumeClaimGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to PersistentVolumeClaimCache interface. -type PersistentVolumeClaimGenericCache struct { generic.CacheInterface[*v1.PersistentVolumeClaim] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c PersistentVolumeClaimGenericCache) AddIndexer(indexName string, indexer PersistentVolumeClaimIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.PersistentVolumeClaim](indexer)) -} - type PersistentVolumeClaimStatusHandler func(obj *v1.PersistentVolumeClaim, status v1.PersistentVolumeClaimStatus) (v1.PersistentVolumeClaimStatus, error) type PersistentVolumeClaimGeneratingHandler func(obj *v1.PersistentVolumeClaim, status v1.PersistentVolumeClaimStatus) ([]runtime.Object, v1.PersistentVolumeClaimStatus, error) -func FromPersistentVolumeClaimHandlerToHandler(sync PersistentVolumeClaimHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.PersistentVolumeClaim](sync)) -} - func RegisterPersistentVolumeClaimStatusHandler(ctx context.Context, controller PersistentVolumeClaimController, condition condition.Cond, name string, handler PersistentVolumeClaimStatusHandler) { statusHandler := &persistentVolumeClaimStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromPersistentVolumeClaimHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterPersistentVolumeClaimGeneratingHandler(ctx context.Context, controller PersistentVolumeClaimController, apply apply.Apply, diff --git a/pkg/generated/controllers/core/v1/pod.go b/pkg/generated/controllers/core/v1/pod.go index 6c8c45e5..13989f81 100644 --- a/pkg/generated/controllers/core/v1/pod.go +++ b/pkg/generated/controllers/core/v1/pod.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // PodController interface for managing Pod resources. type PodController interface { - generic.ControllerMeta - PodClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync PodHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync PodHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() PodCache + generic.ControllerInterface[*v1.Pod, *v1.PodList] } // PodClient interface for managing Pod resources in Kubernetes. type PodClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Pod) (*v1.Pod, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Pod) (*v1.Pod, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.Pod) (*v1.Pod, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Pod, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.PodList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Pod, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Pod, *v1.PodList], error) + generic.ClientInterface[*v1.Pod, *v1.PodList] } // PodCache interface for retrieving Pod resources in memory. type PodCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Pod, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Pod, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer PodIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Pod, error) -} - -// PodHandler is function for performing any potential modifications to a Pod resource. -type PodHandler func(string, *v1.Pod) (*v1.Pod, error) - -// PodIndexer computes a set of indexed values for the provided object. -type PodIndexer func(obj *v1.Pod) ([]string, error) - -// PodGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to PodController interface. -type PodGenericController struct { - generic.ControllerInterface[*v1.Pod, *v1.PodList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *PodGenericController) OnChange(ctx context.Context, name string, sync PodHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Pod](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *PodGenericController) OnRemove(ctx context.Context, name string, sync PodHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Pod](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *PodGenericController) Cache() PodCache { - return &PodGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// PodGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to PodCache interface. -type PodGenericCache struct { generic.CacheInterface[*v1.Pod] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c PodGenericCache) AddIndexer(indexName string, indexer PodIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Pod](indexer)) -} - type PodStatusHandler func(obj *v1.Pod, status v1.PodStatus) (v1.PodStatus, error) type PodGeneratingHandler func(obj *v1.Pod, status v1.PodStatus) ([]runtime.Object, v1.PodStatus, error) -func FromPodHandlerToHandler(sync PodHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.Pod](sync)) -} - func RegisterPodStatusHandler(ctx context.Context, controller PodController, condition condition.Cond, name string, handler PodStatusHandler) { statusHandler := &podStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromPodHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterPodGeneratingHandler(ctx context.Context, controller PodController, apply apply.Apply, diff --git a/pkg/generated/controllers/core/v1/secret.go b/pkg/generated/controllers/core/v1/secret.go index b6381b41..c65c18b5 100644 --- a/pkg/generated/controllers/core/v1/secret.go +++ b/pkg/generated/controllers/core/v1/secret.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // SecretController interface for managing Secret resources. type SecretController interface { - generic.ControllerMeta - SecretClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync SecretHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync SecretHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() SecretCache + generic.ControllerInterface[*v1.Secret, *v1.SecretList] } // SecretClient interface for managing Secret resources in Kubernetes. type SecretClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Secret) (*v1.Secret, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Secret) (*v1.Secret, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Secret, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.SecretList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Secret, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Secret, *v1.SecretList], error) + generic.ClientInterface[*v1.Secret, *v1.SecretList] } // SecretCache interface for retrieving Secret resources in memory. type SecretCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Secret, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Secret, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer SecretIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Secret, error) -} - -// SecretHandler is function for performing any potential modifications to a Secret resource. -type SecretHandler func(string, *v1.Secret) (*v1.Secret, error) - -// SecretIndexer computes a set of indexed values for the provided object. -type SecretIndexer func(obj *v1.Secret) ([]string, error) - -// SecretGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to SecretController interface. -type SecretGenericController struct { - generic.ControllerInterface[*v1.Secret, *v1.SecretList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *SecretGenericController) OnChange(ctx context.Context, name string, sync SecretHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Secret](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *SecretGenericController) OnRemove(ctx context.Context, name string, sync SecretHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Secret](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *SecretGenericController) Cache() SecretCache { - return &SecretGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// SecretGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to SecretCache interface. -type SecretGenericCache struct { generic.CacheInterface[*v1.Secret] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c SecretGenericCache) AddIndexer(indexName string, indexer SecretIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Secret](indexer)) -} diff --git a/pkg/generated/controllers/core/v1/service.go b/pkg/generated/controllers/core/v1/service.go index 3ec2424a..7f4105c6 100644 --- a/pkg/generated/controllers/core/v1/service.go +++ b/pkg/generated/controllers/core/v1/service.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // ServiceController interface for managing Service resources. type ServiceController interface { - generic.ControllerMeta - ServiceClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync ServiceHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync ServiceHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() ServiceCache + generic.ControllerInterface[*v1.Service, *v1.ServiceList] } // ServiceClient interface for managing Service resources in Kubernetes. type ServiceClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Service) (*v1.Service, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Service) (*v1.Service, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.Service) (*v1.Service, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Service, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.ServiceList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Service, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Service, *v1.ServiceList], error) + generic.ClientInterface[*v1.Service, *v1.ServiceList] } // ServiceCache interface for retrieving Service resources in memory. type ServiceCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Service, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Service, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer ServiceIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Service, error) -} - -// ServiceHandler is function for performing any potential modifications to a Service resource. -type ServiceHandler func(string, *v1.Service) (*v1.Service, error) - -// ServiceIndexer computes a set of indexed values for the provided object. -type ServiceIndexer func(obj *v1.Service) ([]string, error) - -// ServiceGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to ServiceController interface. -type ServiceGenericController struct { - generic.ControllerInterface[*v1.Service, *v1.ServiceList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *ServiceGenericController) OnChange(ctx context.Context, name string, sync ServiceHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Service](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *ServiceGenericController) OnRemove(ctx context.Context, name string, sync ServiceHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Service](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *ServiceGenericController) Cache() ServiceCache { - return &ServiceGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// ServiceGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to ServiceCache interface. -type ServiceGenericCache struct { generic.CacheInterface[*v1.Service] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c ServiceGenericCache) AddIndexer(indexName string, indexer ServiceIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Service](indexer)) -} - type ServiceStatusHandler func(obj *v1.Service, status v1.ServiceStatus) (v1.ServiceStatus, error) type ServiceGeneratingHandler func(obj *v1.Service, status v1.ServiceStatus) ([]runtime.Object, v1.ServiceStatus, error) -func FromServiceHandlerToHandler(sync ServiceHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.Service](sync)) -} - func RegisterServiceStatusHandler(ctx context.Context, controller ServiceController, condition condition.Cond, name string, handler ServiceStatusHandler) { statusHandler := &serviceStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromServiceHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterServiceGeneratingHandler(ctx context.Context, controller ServiceController, apply apply.Apply, diff --git a/pkg/generated/controllers/core/v1/serviceaccount.go b/pkg/generated/controllers/core/v1/serviceaccount.go index e296b2d4..cd3a132b 100644 --- a/pkg/generated/controllers/core/v1/serviceaccount.go +++ b/pkg/generated/controllers/core/v1/serviceaccount.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // ServiceAccountController interface for managing ServiceAccount resources. type ServiceAccountController interface { - generic.ControllerMeta - ServiceAccountClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync ServiceAccountHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync ServiceAccountHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() ServiceAccountCache + generic.ControllerInterface[*v1.ServiceAccount, *v1.ServiceAccountList] } // ServiceAccountClient interface for managing ServiceAccount resources in Kubernetes. type ServiceAccountClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.ServiceAccount) (*v1.ServiceAccount, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.ServiceAccount) (*v1.ServiceAccount, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.ServiceAccount, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.ServiceAccountList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ServiceAccount, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.ServiceAccount, *v1.ServiceAccountList], error) + generic.ClientInterface[*v1.ServiceAccount, *v1.ServiceAccountList] } // ServiceAccountCache interface for retrieving ServiceAccount resources in memory. type ServiceAccountCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.ServiceAccount, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.ServiceAccount, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer ServiceAccountIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.ServiceAccount, error) -} - -// ServiceAccountHandler is function for performing any potential modifications to a ServiceAccount resource. -type ServiceAccountHandler func(string, *v1.ServiceAccount) (*v1.ServiceAccount, error) - -// ServiceAccountIndexer computes a set of indexed values for the provided object. -type ServiceAccountIndexer func(obj *v1.ServiceAccount) ([]string, error) - -// ServiceAccountGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to ServiceAccountController interface. -type ServiceAccountGenericController struct { - generic.ControllerInterface[*v1.ServiceAccount, *v1.ServiceAccountList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *ServiceAccountGenericController) OnChange(ctx context.Context, name string, sync ServiceAccountHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.ServiceAccount](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *ServiceAccountGenericController) OnRemove(ctx context.Context, name string, sync ServiceAccountHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.ServiceAccount](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *ServiceAccountGenericController) Cache() ServiceAccountCache { - return &ServiceAccountGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// ServiceAccountGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to ServiceAccountCache interface. -type ServiceAccountGenericCache struct { generic.CacheInterface[*v1.ServiceAccount] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c ServiceAccountGenericCache) AddIndexer(indexName string, indexer ServiceAccountIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.ServiceAccount](indexer)) -} diff --git a/pkg/generated/controllers/discovery/v1/endpointslice.go b/pkg/generated/controllers/discovery/v1/endpointslice.go index ce154209..f44400d5 100644 --- a/pkg/generated/controllers/discovery/v1/endpointslice.go +++ b/pkg/generated/controllers/discovery/v1/endpointslice.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/discovery/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // EndpointSliceController interface for managing EndpointSlice resources. type EndpointSliceController interface { - generic.ControllerMeta - EndpointSliceClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync EndpointSliceHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync EndpointSliceHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() EndpointSliceCache + generic.ControllerInterface[*v1.EndpointSlice, *v1.EndpointSliceList] } // EndpointSliceClient interface for managing EndpointSlice resources in Kubernetes. type EndpointSliceClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.EndpointSlice) (*v1.EndpointSlice, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.EndpointSlice) (*v1.EndpointSlice, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.EndpointSlice, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.EndpointSliceList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.EndpointSlice, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.EndpointSlice, *v1.EndpointSliceList], error) + generic.ClientInterface[*v1.EndpointSlice, *v1.EndpointSliceList] } // EndpointSliceCache interface for retrieving EndpointSlice resources in memory. type EndpointSliceCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.EndpointSlice, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.EndpointSlice, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer EndpointSliceIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.EndpointSlice, error) -} - -// EndpointSliceHandler is function for performing any potential modifications to a EndpointSlice resource. -type EndpointSliceHandler func(string, *v1.EndpointSlice) (*v1.EndpointSlice, error) - -// EndpointSliceIndexer computes a set of indexed values for the provided object. -type EndpointSliceIndexer func(obj *v1.EndpointSlice) ([]string, error) - -// EndpointSliceGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to EndpointSliceController interface. -type EndpointSliceGenericController struct { - generic.ControllerInterface[*v1.EndpointSlice, *v1.EndpointSliceList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *EndpointSliceGenericController) OnChange(ctx context.Context, name string, sync EndpointSliceHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.EndpointSlice](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *EndpointSliceGenericController) OnRemove(ctx context.Context, name string, sync EndpointSliceHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.EndpointSlice](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *EndpointSliceGenericController) Cache() EndpointSliceCache { - return &EndpointSliceGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// EndpointSliceGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to EndpointSliceCache interface. -type EndpointSliceGenericCache struct { generic.CacheInterface[*v1.EndpointSlice] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c EndpointSliceGenericCache) AddIndexer(indexName string, indexer EndpointSliceIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.EndpointSlice](indexer)) -} diff --git a/pkg/generated/controllers/discovery/v1/interface.go b/pkg/generated/controllers/discovery/v1/interface.go index 4c0118e9..82f6d6cc 100644 --- a/pkg/generated/controllers/discovery/v1/interface.go +++ b/pkg/generated/controllers/discovery/v1/interface.go @@ -45,7 +45,5 @@ type version struct { } func (v *version) EndpointSlice() EndpointSliceController { - return &EndpointSliceGenericController{ - generic.NewController[*v1.EndpointSlice, *v1.EndpointSliceList](schema.GroupVersionKind{Group: "discovery.k8s.io", Version: "v1", Kind: "EndpointSlice"}, "endpointslices", true, v.controllerFactory), - } + return generic.NewController[*v1.EndpointSlice, *v1.EndpointSliceList](schema.GroupVersionKind{Group: "discovery.k8s.io", Version: "v1", Kind: "EndpointSlice"}, "endpointslices", true, v.controllerFactory) } diff --git a/pkg/generated/controllers/extensions/v1beta1/ingress.go b/pkg/generated/controllers/extensions/v1beta1/ingress.go index 21674d8f..c8ed73a7 100644 --- a/pkg/generated/controllers/extensions/v1beta1/ingress.go +++ b/pkg/generated/controllers/extensions/v1beta1/ingress.go @@ -29,137 +29,36 @@ import ( v1beta1 "k8s.io/api/extensions/v1beta1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // IngressController interface for managing Ingress resources. type IngressController interface { - generic.ControllerMeta - IngressClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync IngressHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync IngressHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() IngressCache + generic.ControllerInterface[*v1beta1.Ingress, *v1beta1.IngressList] } // IngressClient interface for managing Ingress resources in Kubernetes. type IngressClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1beta1.Ingress) (*v1beta1.Ingress, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1beta1.Ingress) (*v1beta1.Ingress, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1beta1.Ingress) (*v1beta1.Ingress, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1beta1.Ingress, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1beta1.IngressList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1beta1.Ingress, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1beta1.Ingress, *v1beta1.IngressList], error) + generic.ClientInterface[*v1beta1.Ingress, *v1beta1.IngressList] } // IngressCache interface for retrieving Ingress resources in memory. type IngressCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1beta1.Ingress, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1beta1.Ingress, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer IngressIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1beta1.Ingress, error) -} - -// IngressHandler is function for performing any potential modifications to a Ingress resource. -type IngressHandler func(string, *v1beta1.Ingress) (*v1beta1.Ingress, error) - -// IngressIndexer computes a set of indexed values for the provided object. -type IngressIndexer func(obj *v1beta1.Ingress) ([]string, error) - -// IngressGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to IngressController interface. -type IngressGenericController struct { - generic.ControllerInterface[*v1beta1.Ingress, *v1beta1.IngressList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *IngressGenericController) OnChange(ctx context.Context, name string, sync IngressHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1beta1.Ingress](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *IngressGenericController) OnRemove(ctx context.Context, name string, sync IngressHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1beta1.Ingress](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *IngressGenericController) Cache() IngressCache { - return &IngressGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// IngressGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to IngressCache interface. -type IngressGenericCache struct { generic.CacheInterface[*v1beta1.Ingress] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c IngressGenericCache) AddIndexer(indexName string, indexer IngressIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1beta1.Ingress](indexer)) -} - type IngressStatusHandler func(obj *v1beta1.Ingress, status v1beta1.IngressStatus) (v1beta1.IngressStatus, error) type IngressGeneratingHandler func(obj *v1beta1.Ingress, status v1beta1.IngressStatus) ([]runtime.Object, v1beta1.IngressStatus, error) -func FromIngressHandlerToHandler(sync IngressHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1beta1.Ingress](sync)) -} - func RegisterIngressStatusHandler(ctx context.Context, controller IngressController, condition condition.Cond, name string, handler IngressStatusHandler) { statusHandler := &ingressStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromIngressHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterIngressGeneratingHandler(ctx context.Context, controller IngressController, apply apply.Apply, diff --git a/pkg/generated/controllers/extensions/v1beta1/interface.go b/pkg/generated/controllers/extensions/v1beta1/interface.go index 4ec8500b..1126cf21 100644 --- a/pkg/generated/controllers/extensions/v1beta1/interface.go +++ b/pkg/generated/controllers/extensions/v1beta1/interface.go @@ -45,7 +45,5 @@ type version struct { } func (v *version) Ingress() IngressController { - return &IngressGenericController{ - generic.NewController[*v1beta1.Ingress, *v1beta1.IngressList](schema.GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "Ingress"}, "ingresses", true, v.controllerFactory), - } + return generic.NewController[*v1beta1.Ingress, *v1beta1.IngressList](schema.GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "Ingress"}, "ingresses", true, v.controllerFactory) } diff --git a/pkg/generated/controllers/networking.k8s.io/v1/interface.go b/pkg/generated/controllers/networking.k8s.io/v1/interface.go index 2afdab37..f38d5e4a 100644 --- a/pkg/generated/controllers/networking.k8s.io/v1/interface.go +++ b/pkg/generated/controllers/networking.k8s.io/v1/interface.go @@ -45,7 +45,5 @@ type version struct { } func (v *version) NetworkPolicy() NetworkPolicyController { - return &NetworkPolicyGenericController{ - generic.NewController[*v1.NetworkPolicy, *v1.NetworkPolicyList](schema.GroupVersionKind{Group: "networking.k8s.io", Version: "v1", Kind: "NetworkPolicy"}, "networkpolicies", true, v.controllerFactory), - } + return generic.NewController[*v1.NetworkPolicy, *v1.NetworkPolicyList](schema.GroupVersionKind{Group: "networking.k8s.io", Version: "v1", Kind: "NetworkPolicy"}, "networkpolicies", true, v.controllerFactory) } diff --git a/pkg/generated/controllers/networking.k8s.io/v1/networkpolicy.go b/pkg/generated/controllers/networking.k8s.io/v1/networkpolicy.go index baa89068..28a1d152 100644 --- a/pkg/generated/controllers/networking.k8s.io/v1/networkpolicy.go +++ b/pkg/generated/controllers/networking.k8s.io/v1/networkpolicy.go @@ -29,137 +29,36 @@ import ( v1 "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // NetworkPolicyController interface for managing NetworkPolicy resources. type NetworkPolicyController interface { - generic.ControllerMeta - NetworkPolicyClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync NetworkPolicyHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync NetworkPolicyHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() NetworkPolicyCache + generic.ControllerInterface[*v1.NetworkPolicy, *v1.NetworkPolicyList] } // NetworkPolicyClient interface for managing NetworkPolicy resources in Kubernetes. type NetworkPolicyClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.NetworkPolicy) (*v1.NetworkPolicy, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.NetworkPolicy) (*v1.NetworkPolicy, error) - // UpdateStatus updates the Status field of a the object and return the newly updated Object or an error. - // Will always return an error if the object does not have a status field. - UpdateStatus(*v1.NetworkPolicy) (*v1.NetworkPolicy, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.NetworkPolicy, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.NetworkPolicyList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.NetworkPolicy, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.NetworkPolicy, *v1.NetworkPolicyList], error) + generic.ClientInterface[*v1.NetworkPolicy, *v1.NetworkPolicyList] } // NetworkPolicyCache interface for retrieving NetworkPolicy resources in memory. type NetworkPolicyCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.NetworkPolicy, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.NetworkPolicy, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer NetworkPolicyIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.NetworkPolicy, error) -} - -// NetworkPolicyHandler is function for performing any potential modifications to a NetworkPolicy resource. -type NetworkPolicyHandler func(string, *v1.NetworkPolicy) (*v1.NetworkPolicy, error) - -// NetworkPolicyIndexer computes a set of indexed values for the provided object. -type NetworkPolicyIndexer func(obj *v1.NetworkPolicy) ([]string, error) - -// NetworkPolicyGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to NetworkPolicyController interface. -type NetworkPolicyGenericController struct { - generic.ControllerInterface[*v1.NetworkPolicy, *v1.NetworkPolicyList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *NetworkPolicyGenericController) OnChange(ctx context.Context, name string, sync NetworkPolicyHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.NetworkPolicy](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *NetworkPolicyGenericController) OnRemove(ctx context.Context, name string, sync NetworkPolicyHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.NetworkPolicy](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *NetworkPolicyGenericController) Cache() NetworkPolicyCache { - return &NetworkPolicyGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// NetworkPolicyGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to NetworkPolicyCache interface. -type NetworkPolicyGenericCache struct { generic.CacheInterface[*v1.NetworkPolicy] } -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c NetworkPolicyGenericCache) AddIndexer(indexName string, indexer NetworkPolicyIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.NetworkPolicy](indexer)) -} - type NetworkPolicyStatusHandler func(obj *v1.NetworkPolicy, status v1.NetworkPolicyStatus) (v1.NetworkPolicyStatus, error) type NetworkPolicyGeneratingHandler func(obj *v1.NetworkPolicy, status v1.NetworkPolicyStatus) ([]runtime.Object, v1.NetworkPolicyStatus, error) -func FromNetworkPolicyHandlerToHandler(sync NetworkPolicyHandler) generic.Handler { - return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.NetworkPolicy](sync)) -} - func RegisterNetworkPolicyStatusHandler(ctx context.Context, controller NetworkPolicyController, condition condition.Cond, name string, handler NetworkPolicyStatusHandler) { statusHandler := &networkPolicyStatusHandler{ client: controller, condition: condition, handler: handler, } - controller.AddGenericHandler(ctx, name, FromNetworkPolicyHandlerToHandler(statusHandler.sync)) + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) } func RegisterNetworkPolicyGeneratingHandler(ctx context.Context, controller NetworkPolicyController, apply apply.Apply, diff --git a/pkg/generated/controllers/rbac/v1/clusterrole.go b/pkg/generated/controllers/rbac/v1/clusterrole.go index 3d916c43..d515fe96 100644 --- a/pkg/generated/controllers/rbac/v1/clusterrole.go +++ b/pkg/generated/controllers/rbac/v1/clusterrole.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // ClusterRoleController interface for managing ClusterRole resources. type ClusterRoleController interface { - generic.ControllerMeta - ClusterRoleClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync ClusterRoleHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync ClusterRoleHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() ClusterRoleCache + generic.NonNamespacedControllerInterface[*v1.ClusterRole, *v1.ClusterRoleList] } // ClusterRoleClient interface for managing ClusterRole resources in Kubernetes. type ClusterRoleClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.ClusterRole) (*v1.ClusterRole, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.ClusterRole) (*v1.ClusterRole, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.ClusterRole, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.ClusterRoleList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ClusterRole, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.ClusterRole, *v1.ClusterRoleList], error) + generic.NonNamespacedClientInterface[*v1.ClusterRole, *v1.ClusterRoleList] } // ClusterRoleCache interface for retrieving ClusterRole resources in memory. type ClusterRoleCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.ClusterRole, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.ClusterRole, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer ClusterRoleIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.ClusterRole, error) -} - -// ClusterRoleHandler is function for performing any potential modifications to a ClusterRole resource. -type ClusterRoleHandler func(string, *v1.ClusterRole) (*v1.ClusterRole, error) - -// ClusterRoleIndexer computes a set of indexed values for the provided object. -type ClusterRoleIndexer func(obj *v1.ClusterRole) ([]string, error) - -// ClusterRoleGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to ClusterRoleController interface. -type ClusterRoleGenericController struct { - generic.NonNamespacedControllerInterface[*v1.ClusterRole, *v1.ClusterRoleList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *ClusterRoleGenericController) OnChange(ctx context.Context, name string, sync ClusterRoleHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.ClusterRole](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *ClusterRoleGenericController) OnRemove(ctx context.Context, name string, sync ClusterRoleHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.ClusterRole](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *ClusterRoleGenericController) Cache() ClusterRoleCache { - return &ClusterRoleGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// ClusterRoleGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to ClusterRoleCache interface. -type ClusterRoleGenericCache struct { generic.NonNamespacedCacheInterface[*v1.ClusterRole] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c ClusterRoleGenericCache) AddIndexer(indexName string, indexer ClusterRoleIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.ClusterRole](indexer)) -} diff --git a/pkg/generated/controllers/rbac/v1/clusterrolebinding.go b/pkg/generated/controllers/rbac/v1/clusterrolebinding.go index 6bfcb878..b191f463 100644 --- a/pkg/generated/controllers/rbac/v1/clusterrolebinding.go +++ b/pkg/generated/controllers/rbac/v1/clusterrolebinding.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // ClusterRoleBindingController interface for managing ClusterRoleBinding resources. type ClusterRoleBindingController interface { - generic.ControllerMeta - ClusterRoleBindingClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync ClusterRoleBindingHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync ClusterRoleBindingHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() ClusterRoleBindingCache + generic.NonNamespacedControllerInterface[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList] } // ClusterRoleBindingClient interface for managing ClusterRoleBinding resources in Kubernetes. type ClusterRoleBindingClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.ClusterRoleBinding, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.ClusterRoleBindingList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ClusterRoleBinding, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList], error) + generic.NonNamespacedClientInterface[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList] } // ClusterRoleBindingCache interface for retrieving ClusterRoleBinding resources in memory. type ClusterRoleBindingCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.ClusterRoleBinding, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.ClusterRoleBinding, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer ClusterRoleBindingIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.ClusterRoleBinding, error) -} - -// ClusterRoleBindingHandler is function for performing any potential modifications to a ClusterRoleBinding resource. -type ClusterRoleBindingHandler func(string, *v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) - -// ClusterRoleBindingIndexer computes a set of indexed values for the provided object. -type ClusterRoleBindingIndexer func(obj *v1.ClusterRoleBinding) ([]string, error) - -// ClusterRoleBindingGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to ClusterRoleBindingController interface. -type ClusterRoleBindingGenericController struct { - generic.NonNamespacedControllerInterface[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *ClusterRoleBindingGenericController) OnChange(ctx context.Context, name string, sync ClusterRoleBindingHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.ClusterRoleBinding](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *ClusterRoleBindingGenericController) OnRemove(ctx context.Context, name string, sync ClusterRoleBindingHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.ClusterRoleBinding](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *ClusterRoleBindingGenericController) Cache() ClusterRoleBindingCache { - return &ClusterRoleBindingGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// ClusterRoleBindingGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to ClusterRoleBindingCache interface. -type ClusterRoleBindingGenericCache struct { generic.NonNamespacedCacheInterface[*v1.ClusterRoleBinding] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c ClusterRoleBindingGenericCache) AddIndexer(indexName string, indexer ClusterRoleBindingIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.ClusterRoleBinding](indexer)) -} diff --git a/pkg/generated/controllers/rbac/v1/interface.go b/pkg/generated/controllers/rbac/v1/interface.go index 63fa892e..cff09749 100644 --- a/pkg/generated/controllers/rbac/v1/interface.go +++ b/pkg/generated/controllers/rbac/v1/interface.go @@ -48,25 +48,17 @@ type version struct { } func (v *version) ClusterRole() ClusterRoleController { - return &ClusterRoleGenericController{ - generic.NewNonNamespacedController[*v1.ClusterRole, *v1.ClusterRoleList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, "clusterroles", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.ClusterRole, *v1.ClusterRoleList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, "clusterroles", v.controllerFactory) } func (v *version) ClusterRoleBinding() ClusterRoleBindingController { - return &ClusterRoleBindingGenericController{ - generic.NewNonNamespacedController[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, "clusterrolebindings", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, "clusterrolebindings", v.controllerFactory) } func (v *version) Role() RoleController { - return &RoleGenericController{ - generic.NewController[*v1.Role, *v1.RoleList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role"}, "roles", true, v.controllerFactory), - } + return generic.NewController[*v1.Role, *v1.RoleList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role"}, "roles", true, v.controllerFactory) } func (v *version) RoleBinding() RoleBindingController { - return &RoleBindingGenericController{ - generic.NewController[*v1.RoleBinding, *v1.RoleBindingList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"}, "rolebindings", true, v.controllerFactory), - } + return generic.NewController[*v1.RoleBinding, *v1.RoleBindingList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"}, "rolebindings", true, v.controllerFactory) } diff --git a/pkg/generated/controllers/rbac/v1/role.go b/pkg/generated/controllers/rbac/v1/role.go index 656ee67c..d1898057 100644 --- a/pkg/generated/controllers/rbac/v1/role.go +++ b/pkg/generated/controllers/rbac/v1/role.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // RoleController interface for managing Role resources. type RoleController interface { - generic.ControllerMeta - RoleClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync RoleHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync RoleHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() RoleCache + generic.ControllerInterface[*v1.Role, *v1.RoleList] } // RoleClient interface for managing Role resources in Kubernetes. type RoleClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.Role) (*v1.Role, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.Role) (*v1.Role, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.Role, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.RoleList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Role, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.Role, *v1.RoleList], error) + generic.ClientInterface[*v1.Role, *v1.RoleList] } // RoleCache interface for retrieving Role resources in memory. type RoleCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.Role, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.Role, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer RoleIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.Role, error) -} - -// RoleHandler is function for performing any potential modifications to a Role resource. -type RoleHandler func(string, *v1.Role) (*v1.Role, error) - -// RoleIndexer computes a set of indexed values for the provided object. -type RoleIndexer func(obj *v1.Role) ([]string, error) - -// RoleGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to RoleController interface. -type RoleGenericController struct { - generic.ControllerInterface[*v1.Role, *v1.RoleList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *RoleGenericController) OnChange(ctx context.Context, name string, sync RoleHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Role](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *RoleGenericController) OnRemove(ctx context.Context, name string, sync RoleHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Role](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *RoleGenericController) Cache() RoleCache { - return &RoleGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// RoleGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to RoleCache interface. -type RoleGenericCache struct { generic.CacheInterface[*v1.Role] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c RoleGenericCache) AddIndexer(indexName string, indexer RoleIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Role](indexer)) -} diff --git a/pkg/generated/controllers/rbac/v1/rolebinding.go b/pkg/generated/controllers/rbac/v1/rolebinding.go index adccba92..2593e36d 100644 --- a/pkg/generated/controllers/rbac/v1/rolebinding.go +++ b/pkg/generated/controllers/rbac/v1/rolebinding.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // RoleBindingController interface for managing RoleBinding resources. type RoleBindingController interface { - generic.ControllerMeta - RoleBindingClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync RoleBindingHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync RoleBindingHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(namespace, name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(namespace, name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() RoleBindingCache + generic.ControllerInterface[*v1.RoleBinding, *v1.RoleBindingList] } // RoleBindingClient interface for managing RoleBinding resources in Kubernetes. type RoleBindingClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.RoleBinding) (*v1.RoleBinding, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.RoleBinding) (*v1.RoleBinding, error) - - // Delete deletes the Object in the given name. - Delete(namespace, name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(namespace, name string, options metav1.GetOptions) (*v1.RoleBinding, error) - - // List will attempt to find multiple resources. - List(namespace string, opts metav1.ListOptions) (*v1.RoleBindingList, error) - - // Watch will start watching resources. - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.RoleBinding, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.ClientInterface[*v1.RoleBinding, *v1.RoleBindingList], error) + generic.ClientInterface[*v1.RoleBinding, *v1.RoleBindingList] } // RoleBindingCache interface for retrieving RoleBinding resources in memory. type RoleBindingCache interface { - // Get returns the resources with the specified name from the cache. - Get(namespace, name string) (*v1.RoleBinding, error) - - // List will attempt to find resources from the Cache. - List(namespace string, selector labels.Selector) ([]*v1.RoleBinding, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer RoleBindingIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.RoleBinding, error) -} - -// RoleBindingHandler is function for performing any potential modifications to a RoleBinding resource. -type RoleBindingHandler func(string, *v1.RoleBinding) (*v1.RoleBinding, error) - -// RoleBindingIndexer computes a set of indexed values for the provided object. -type RoleBindingIndexer func(obj *v1.RoleBinding) ([]string, error) - -// RoleBindingGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to RoleBindingController interface. -type RoleBindingGenericController struct { - generic.ControllerInterface[*v1.RoleBinding, *v1.RoleBindingList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *RoleBindingGenericController) OnChange(ctx context.Context, name string, sync RoleBindingHandler) { - c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.RoleBinding](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *RoleBindingGenericController) OnRemove(ctx context.Context, name string, sync RoleBindingHandler) { - c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.RoleBinding](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *RoleBindingGenericController) Cache() RoleBindingCache { - return &RoleBindingGenericCache{ - c.ControllerInterface.Cache(), - } -} - -// RoleBindingGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to RoleBindingCache interface. -type RoleBindingGenericCache struct { generic.CacheInterface[*v1.RoleBinding] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c RoleBindingGenericCache) AddIndexer(indexName string, indexer RoleBindingIndexer) { - c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.RoleBinding](indexer)) -} diff --git a/pkg/generated/controllers/storage/v1/interface.go b/pkg/generated/controllers/storage/v1/interface.go index 02a43dfa..2ad2e9b5 100644 --- a/pkg/generated/controllers/storage/v1/interface.go +++ b/pkg/generated/controllers/storage/v1/interface.go @@ -45,7 +45,5 @@ type version struct { } func (v *version) StorageClass() StorageClassController { - return &StorageClassGenericController{ - generic.NewNonNamespacedController[*v1.StorageClass, *v1.StorageClassList](schema.GroupVersionKind{Group: "storage.k8s.io", Version: "v1", Kind: "StorageClass"}, "storageclasses", v.controllerFactory), - } + return generic.NewNonNamespacedController[*v1.StorageClass, *v1.StorageClassList](schema.GroupVersionKind{Group: "storage.k8s.io", Version: "v1", Kind: "StorageClass"}, "storageclasses", v.controllerFactory) } diff --git a/pkg/generated/controllers/storage/v1/storageclass.go b/pkg/generated/controllers/storage/v1/storageclass.go index fe7e1f6c..e3f299c3 100644 --- a/pkg/generated/controllers/storage/v1/storageclass.go +++ b/pkg/generated/controllers/storage/v1/storageclass.go @@ -19,118 +19,21 @@ limitations under the License. package v1 import ( - "context" - "time" - "github.com/rancher/wrangler/pkg/generic" v1 "k8s.io/api/storage/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/rest" ) // StorageClassController interface for managing StorageClass resources. type StorageClassController interface { - generic.ControllerMeta - StorageClassClient - - // OnChange runs the given handler when the controller detects a resource was changed. - OnChange(ctx context.Context, name string, sync StorageClassHandler) - - // OnRemove runs the given handler when the controller detects a resource was changed. - OnRemove(ctx context.Context, name string, sync StorageClassHandler) - - // Enqueue adds the resource with the given name to the worker queue of the controller. - Enqueue(name string) - - // EnqueueAfter runs Enqueue after the provided duration. - EnqueueAfter(name string, duration time.Duration) - - // Cache returns a cache for the resource type T. - Cache() StorageClassCache + generic.NonNamespacedControllerInterface[*v1.StorageClass, *v1.StorageClassList] } // StorageClassClient interface for managing StorageClass resources in Kubernetes. type StorageClassClient interface { - // Create creates a new object and return the newly created Object or an error. - Create(*v1.StorageClass) (*v1.StorageClass, error) - - // Update updates the object and return the newly updated Object or an error. - Update(*v1.StorageClass) (*v1.StorageClass, error) - - // Delete deletes the Object in the given name. - Delete(name string, options *metav1.DeleteOptions) error - - // Get will attempt to retrieve the resource with the specified name. - Get(name string, options metav1.GetOptions) (*v1.StorageClass, error) - - // List will attempt to find multiple resources. - List(opts metav1.ListOptions) (*v1.StorageClassList, error) - - // Watch will start watching resources. - Watch(opts metav1.ListOptions) (watch.Interface, error) - - // Patch will patch the resource with the matching name. - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.StorageClass, err error) - - // WithImpersonation returns a new client that will use the provided impersonation config for new request. - WithImpersonation(impersonate rest.ImpersonationConfig) (generic.NonNamespacedClientInterface[*v1.StorageClass, *v1.StorageClassList], error) + generic.NonNamespacedClientInterface[*v1.StorageClass, *v1.StorageClassList] } // StorageClassCache interface for retrieving StorageClass resources in memory. type StorageClassCache interface { - // Get returns the resources with the specified name from the cache. - Get(name string) (*v1.StorageClass, error) - - // List will attempt to find resources from the Cache. - List(selector labels.Selector) ([]*v1.StorageClass, error) - - // AddIndexer adds a new Indexer to the cache with the provided name. - // If you call this after you already have data in the store, the results are undefined. - AddIndexer(indexName string, indexer StorageClassIndexer) - - // GetByIndex returns the stored objects whose set of indexed values - // for the named index includes the given indexed value. - GetByIndex(indexName, key string) ([]*v1.StorageClass, error) -} - -// StorageClassHandler is function for performing any potential modifications to a StorageClass resource. -type StorageClassHandler func(string, *v1.StorageClass) (*v1.StorageClass, error) - -// StorageClassIndexer computes a set of indexed values for the provided object. -type StorageClassIndexer func(obj *v1.StorageClass) ([]string, error) - -// StorageClassGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to StorageClassController interface. -type StorageClassGenericController struct { - generic.NonNamespacedControllerInterface[*v1.StorageClass, *v1.StorageClassList] -} - -// OnChange runs the given resource handler when the controller detects a resource was changed. -func (c *StorageClassGenericController) OnChange(ctx context.Context, name string, sync StorageClassHandler) { - c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.StorageClass](sync)) -} - -// OnRemove runs the given object handler when the controller detects a resource was changed. -func (c *StorageClassGenericController) OnRemove(ctx context.Context, name string, sync StorageClassHandler) { - c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.StorageClass](sync)) -} - -// Cache returns a cache of resources in memory. -func (c *StorageClassGenericController) Cache() StorageClassCache { - return &StorageClassGenericCache{ - c.NonNamespacedControllerInterface.Cache(), - } -} - -// StorageClassGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to StorageClassCache interface. -type StorageClassGenericCache struct { generic.NonNamespacedCacheInterface[*v1.StorageClass] } - -// AddIndexer adds a new Indexer to the cache with the provided name. -// If you call this after you already have data in the store, the results are undefined. -func (c StorageClassGenericCache) AddIndexer(indexName string, indexer StorageClassIndexer) { - c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.StorageClass](indexer)) -} diff --git a/pkg/generic/controller.go b/pkg/generic/controller.go index 97afa715..b6c845a0 100644 --- a/pkg/generic/controller.go +++ b/pkg/generic/controller.go @@ -63,7 +63,7 @@ type ControllerInterface[T RuntimeMetaObject, TList runtime.Object] interface { EnqueueAfter(namespace, name string, duration time.Duration) // Cache returns a cache for the resource type T. - Cache() CacheInterface[T] + Cache() *Cache[T] } // NonNamespacedControllerInterface interface for managing non namespaced K8s Objects. @@ -84,7 +84,7 @@ type NonNamespacedControllerInterface[T RuntimeMetaObject, TList runtime.Object] EnqueueAfter(name string, duration time.Duration) // Cache returns a cache for the resource type T. - Cache() NonNamespacedCacheInterface[T] + Cache() *NonNamespacedCache[T] } // ClientInterface is an interface to performs CRUD like operations on an Objects. @@ -269,7 +269,7 @@ func (c *Controller[T, TList]) GroupVersionKind() schema.GroupVersionKind { } // Cache returns a cache for the objects T. -func (c *Controller[T, TList]) Cache() CacheInterface[T] { +func (c *Controller[T, TList]) Cache() *Cache[T] { return &Cache[T]{ indexer: c.Informer().GetIndexer(), resource: c.groupResource, @@ -326,6 +326,24 @@ func (c *Controller[T, TList]) Patch(namespace, name string, pt types.PatchType, return result, c.embeddedClient.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) } +// WithImpersonation returns a new copy of the client that uses impersonation. +func (c *Controller[T, TList]) WithImpersonation(impersonate rest.ImpersonationConfig) (ClientInterface[T, TList], error) { + newClient, err := c.embeddedClient.WithImpersonation(impersonate) + if err != nil { + return nil, fmt.Errorf("failed to make new client: %w", err) + } + + // return a new controller with a new embeddedClient + return &Controller[T, TList]{ + controller: c.controller, + embeddedClient: newClient, + objType: c.objType, + objListType: c.objListType, + gvk: c.gvk, + groupResource: c.groupResource, + }, nil +} + // NewNonNamespacedController returns a Controller controller that is not namespaced. // NonNamespacedController redefines specific functions to no longer accept the namespace parameter. func NewNonNamespacedController[T RuntimeMetaObject, TList runtime.Object](gvk schema.GroupVersionKind, resource string, @@ -387,7 +405,7 @@ func (c *NonNamespacedController[T, TList]) WithImpersonation(impersonate rest.I } // Cache calls ControllerInterface.Cache(...) and wraps the result in a new NonNamespacedCache. -func (c *NonNamespacedController[T, TList]) Cache() NonNamespacedCacheInterface[T] { +func (c *NonNamespacedController[T, TList]) Cache() *NonNamespacedCache[T] { return &NonNamespacedCache[T]{ CacheInterface: c.Controller.Cache(), } diff --git a/pkg/generic/fake/README.md b/pkg/generic/fake/README.md index 99d26c4c..d5824d75 100644 --- a/pkg/generic/fake/README.md +++ b/pkg/generic/fake/README.md @@ -17,13 +17,7 @@ Example use of generic/fake with a generated Deployment Controller. ``` golang // Generated controller interface to mock. type DeploymentController interface { - generic.ControllerMeta - DeploymentClient - OnChange(ctx context.Context, name string, sync DeploymentHandler) - OnRemove(ctx context.Context, name string, sync DeploymentHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - Cache() DeploymentGenericCache + generic.ControllerInterface[*v1.Deployment, *v1.DeploymentList] } ``` ``` golang @@ -44,10 +38,6 @@ func TestController(t *testing.T){ // Create a new Generic Controller Mock with type apps1.Deployment. deployMock := fake.NewMockControllerInterface[*v1.Deployment, *v1.DeploymentList](ctrl) - // Wrap our mocked genericController around the type specific DeploymentGenericController - // which satisfies DeploymentController interface - testDeployCtrl := wranglerv1.DeploymentGenericController{deployMock} - // Define expected calls to our mock controller using gomock. deployMock.EXPECT().Enqueue("test-namespace", "test-name").AnyTimes() @@ -57,11 +47,11 @@ func TestController(t *testing.T){ // . // Test calls Enqueue with expected parameters nothing happens. - testDeployCtrl.Enqueue("test-namespace", "test-name") + deployMock.Enqueue("test-namespace", "test-name") // Test calls Enqueue with unexpected parameters. // gomock will fail the test because it did not expect the call. - testDeployCtrl.Enqueue("unexpected-namespace", "unexpected-name") + deployMock.Enqueue("unexpected-namespace", "unexpected-name") } ``` @@ -72,8 +62,6 @@ ctrl := gomock.NewController(t) mock := fake.NewMockNonNamespacedControllerInterface[*v3.RoleTemplate, *v3.RoleTemplateList](ctrl) mock.EXPECT().List(gomock.Any()).Return(nil, nil) - -roleTemplateController := RoleTemplateGenericController{mock} ``` ## Fake Generation @@ -82,12 +70,11 @@ This package was generated with `mockgen -package fake -destination ./controller Due to an open issue with mockgen https://github.com/golang/mock/issues/649 `controller.go` must be modified for the generation to succeed. 1. Comment out the `comparable` in RuntimeMetaObject -2. Remove `[T, TList]` on the embedded client interface for ControllerInterface and NonNamespacedControllerInterface. This will cause the file to no longer build but the generation will succeed. +2. Remove `[T, TList]` on `ClientInterface` embedded into ControllerInterface and NonNamespacedControllerInterface. This will cause the file to no longer build but the generation will succeed. ``` golang type ControllerInterface[T RuntimeMetaObject, TList runtime.Object interface { ControllerMeta ClientInterface //[T, TList] - ``` - + ``` \ No newline at end of file diff --git a/pkg/generic/fake/controller.go b/pkg/generic/fake/controller.go index b9f6d225..3f175d4e 100644 --- a/pkg/generic/fake/controller.go +++ b/pkg/generic/fake/controller.go @@ -598,10 +598,10 @@ func (mr *MockControllerInterfaceMockRecorder[T, TList]) AddGenericRemoveHandler } // Cache mocks base method. -func (m *MockControllerInterface[T, TList]) Cache() generic.CacheInterface[T] { +func (m *MockControllerInterface[T, TList]) Cache() *generic.Cache[T] { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Cache") - ret0, _ := ret[0].(generic.CacheInterface[T]) + ret0, _ := ret[0].(*generic.Cache[T]) return ret0 } @@ -888,10 +888,10 @@ func (mr *MockNonNamespacedControllerInterfaceMockRecorder[T, TList]) AddGeneric } // Cache mocks base method. -func (m *MockNonNamespacedControllerInterface[T, TList]) Cache() generic.NonNamespacedCacheInterface[T] { +func (m *MockNonNamespacedControllerInterface[T, TList]) Cache() *generic.NonNamespacedCache[T] { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Cache") - ret0, _ := ret[0].(generic.NonNamespacedCacheInterface[T]) + ret0, _ := ret[0].(*generic.NonNamespacedCache[T]) return ret0 }