Commit 12e64c8b authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Go generate

parent a7f71bb5
...@@ -19,114 +19,21 @@ limitations under the License. ...@@ -19,114 +19,21 @@ limitations under the License.
package v1 package v1
import ( import (
"context"
"time"
v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1" v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1"
"github.com/rancher/wrangler/pkg/generic" "github.com/rancher/wrangler/pkg/generic"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
) )
// AddonController interface for managing Addon resources. // AddonController interface for managing Addon resources.
type AddonController interface { type AddonController interface {
generic.ControllerMeta generic.ControllerInterface[*v1.Addon, *v1.AddonList]
AddonClient
// OnChange runs the given handler when the controller detects a resource was changed.
OnChange(ctx context.Context, name string, sync AddonHandler)
// OnRemove runs the given handler when the controller detects a resource was changed.
OnRemove(ctx context.Context, name string, sync AddonHandler)
// 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() AddonCache
} }
// AddonClient interface for managing Addon resources in Kubernetes. // AddonClient interface for managing Addon resources in Kubernetes.
type AddonClient interface { type AddonClient interface {
// Create creates a new object and return the newly created Object or an error. generic.ClientInterface[*v1.Addon, *v1.AddonList]
Create(*v1.Addon) (*v1.Addon, error)
// Update updates the object and return the newly updated Object or an error.
Update(*v1.Addon) (*v1.Addon, 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.Addon, error)
// List will attempt to find multiple resources.
List(namespace string, opts metav1.ListOptions) (*v1.AddonList, 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.Addon, err error)
} }
// AddonCache interface for retrieving Addon resources in memory. // AddonCache interface for retrieving Addon resources in memory.
type AddonCache interface { type AddonCache interface {
// Get returns the resources with the specified name from the cache.
Get(namespace, name string) (*v1.Addon, error)
// List will attempt to find resources from the Cache.
List(namespace string, selector labels.Selector) ([]*v1.Addon, 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 AddonIndexer)
// GetByIndex returns the stored objects whose set of indexed values
// for the named index includes the given indexed value.
GetByIndex(indexName, key string) ([]*v1.Addon, error)
}
// AddonHandler is function for performing any potential modifications to a Addon resource.
type AddonHandler func(string, *v1.Addon) (*v1.Addon, error)
// AddonIndexer computes a set of indexed values for the provided object.
type AddonIndexer func(obj *v1.Addon) ([]string, error)
// AddonGenericController wraps wrangler/pkg/generic.Controller so that the function definitions adhere to AddonController interface.
type AddonGenericController struct {
generic.ControllerInterface[*v1.Addon, *v1.AddonList]
}
// OnChange runs the given resource handler when the controller detects a resource was changed.
func (c *AddonGenericController) OnChange(ctx context.Context, name string, sync AddonHandler) {
c.ControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.Addon](sync))
}
// OnRemove runs the given object handler when the controller detects a resource was changed.
func (c *AddonGenericController) OnRemove(ctx context.Context, name string, sync AddonHandler) {
c.ControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.Addon](sync))
}
// Cache returns a cache of resources in memory.
func (c *AddonGenericController) Cache() AddonCache {
return &AddonGenericCache{
c.ControllerInterface.Cache(),
}
}
// AddonGenericCache wraps wrangler/pkg/generic.Cache so the function definitions adhere to AddonCache interface.
type AddonGenericCache struct {
generic.CacheInterface[*v1.Addon] generic.CacheInterface[*v1.Addon]
} }
// 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 AddonGenericCache) AddIndexer(indexName string, indexer AddonIndexer) {
c.CacheInterface.AddIndexer(indexName, generic.Indexer[*v1.Addon](indexer))
}
...@@ -29,133 +29,36 @@ import ( ...@@ -29,133 +29,36 @@ import (
"github.com/rancher/wrangler/pkg/kv" "github.com/rancher/wrangler/pkg/kv"
"k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors" "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"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
) )
// ETCDSnapshotFileController interface for managing ETCDSnapshotFile resources. // ETCDSnapshotFileController interface for managing ETCDSnapshotFile resources.
type ETCDSnapshotFileController interface { type ETCDSnapshotFileController interface {
generic.ControllerMeta generic.NonNamespacedControllerInterface[*v1.ETCDSnapshotFile, *v1.ETCDSnapshotFileList]
ETCDSnapshotFileClient
// OnChange runs the given handler when the controller detects a resource was changed.
OnChange(ctx context.Context, name string, sync ETCDSnapshotFileHandler)
// OnRemove runs the given handler when the controller detects a resource was changed.
OnRemove(ctx context.Context, name string, sync ETCDSnapshotFileHandler)
// 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() ETCDSnapshotFileCache
} }
// ETCDSnapshotFileClient interface for managing ETCDSnapshotFile resources in Kubernetes. // ETCDSnapshotFileClient interface for managing ETCDSnapshotFile resources in Kubernetes.
type ETCDSnapshotFileClient interface { type ETCDSnapshotFileClient interface {
// Create creates a new object and return the newly created Object or an error. generic.NonNamespacedClientInterface[*v1.ETCDSnapshotFile, *v1.ETCDSnapshotFileList]
Create(*v1.ETCDSnapshotFile) (*v1.ETCDSnapshotFile, error)
// Update updates the object and return the newly updated Object or an error.
Update(*v1.ETCDSnapshotFile) (*v1.ETCDSnapshotFile, 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.ETCDSnapshotFile) (*v1.ETCDSnapshotFile, 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.ETCDSnapshotFile, error)
// List will attempt to find multiple resources.
List(opts metav1.ListOptions) (*v1.ETCDSnapshotFileList, 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.ETCDSnapshotFile, err error)
} }
// ETCDSnapshotFileCache interface for retrieving ETCDSnapshotFile resources in memory. // ETCDSnapshotFileCache interface for retrieving ETCDSnapshotFile resources in memory.
type ETCDSnapshotFileCache interface { type ETCDSnapshotFileCache interface {
// Get returns the resources with the specified name from the cache.
Get(name string) (*v1.ETCDSnapshotFile, error)
// List will attempt to find resources from the Cache.
List(selector labels.Selector) ([]*v1.ETCDSnapshotFile, 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 ETCDSnapshotFileIndexer)
// GetByIndex returns the stored objects whose set of indexed values
// for the named index includes the given indexed value.
GetByIndex(indexName, key string) ([]*v1.ETCDSnapshotFile, error)
}
// ETCDSnapshotFileHandler is function for performing any potential modifications to a ETCDSnapshotFile resource.
type ETCDSnapshotFileHandler func(string, *v1.ETCDSnapshotFile) (*v1.ETCDSnapshotFile, error)
// ETCDSnapshotFileIndexer computes a set of indexed values for the provided object.
type ETCDSnapshotFileIndexer func(obj *v1.ETCDSnapshotFile) ([]string, error)
// ETCDSnapshotFileGenericController wraps wrangler/pkg/generic.NonNamespacedController so that the function definitions adhere to ETCDSnapshotFileController interface.
type ETCDSnapshotFileGenericController struct {
generic.NonNamespacedControllerInterface[*v1.ETCDSnapshotFile, *v1.ETCDSnapshotFileList]
}
// OnChange runs the given resource handler when the controller detects a resource was changed.
func (c *ETCDSnapshotFileGenericController) OnChange(ctx context.Context, name string, sync ETCDSnapshotFileHandler) {
c.NonNamespacedControllerInterface.OnChange(ctx, name, generic.ObjectHandler[*v1.ETCDSnapshotFile](sync))
}
// OnRemove runs the given object handler when the controller detects a resource was changed.
func (c *ETCDSnapshotFileGenericController) OnRemove(ctx context.Context, name string, sync ETCDSnapshotFileHandler) {
c.NonNamespacedControllerInterface.OnRemove(ctx, name, generic.ObjectHandler[*v1.ETCDSnapshotFile](sync))
}
// Cache returns a cache of resources in memory.
func (c *ETCDSnapshotFileGenericController) Cache() ETCDSnapshotFileCache {
return &ETCDSnapshotFileGenericCache{
c.NonNamespacedControllerInterface.Cache(),
}
}
// ETCDSnapshotFileGenericCache wraps wrangler/pkg/generic.NonNamespacedCache so the function definitions adhere to ETCDSnapshotFileCache interface.
type ETCDSnapshotFileGenericCache struct {
generic.NonNamespacedCacheInterface[*v1.ETCDSnapshotFile] generic.NonNamespacedCacheInterface[*v1.ETCDSnapshotFile]
} }
// 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 ETCDSnapshotFileGenericCache) AddIndexer(indexName string, indexer ETCDSnapshotFileIndexer) {
c.NonNamespacedCacheInterface.AddIndexer(indexName, generic.Indexer[*v1.ETCDSnapshotFile](indexer))
}
type ETCDSnapshotFileStatusHandler func(obj *v1.ETCDSnapshotFile, status v1.ETCDSnapshotStatus) (v1.ETCDSnapshotStatus, error) type ETCDSnapshotFileStatusHandler func(obj *v1.ETCDSnapshotFile, status v1.ETCDSnapshotStatus) (v1.ETCDSnapshotStatus, error)
type ETCDSnapshotFileGeneratingHandler func(obj *v1.ETCDSnapshotFile, status v1.ETCDSnapshotStatus) ([]runtime.Object, v1.ETCDSnapshotStatus, error) type ETCDSnapshotFileGeneratingHandler func(obj *v1.ETCDSnapshotFile, status v1.ETCDSnapshotStatus) ([]runtime.Object, v1.ETCDSnapshotStatus, error)
func FromETCDSnapshotFileHandlerToHandler(sync ETCDSnapshotFileHandler) generic.Handler {
return generic.FromObjectHandlerToHandler(generic.ObjectHandler[*v1.ETCDSnapshotFile](sync))
}
func RegisterETCDSnapshotFileStatusHandler(ctx context.Context, controller ETCDSnapshotFileController, condition condition.Cond, name string, handler ETCDSnapshotFileStatusHandler) { func RegisterETCDSnapshotFileStatusHandler(ctx context.Context, controller ETCDSnapshotFileController, condition condition.Cond, name string, handler ETCDSnapshotFileStatusHandler) {
statusHandler := &eTCDSnapshotFileStatusHandler{ statusHandler := &eTCDSnapshotFileStatusHandler{
client: controller, client: controller,
condition: condition, condition: condition,
handler: handler, handler: handler,
} }
controller.AddGenericHandler(ctx, name, FromETCDSnapshotFileHandlerToHandler(statusHandler.sync)) controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync))
} }
func RegisterETCDSnapshotFileGeneratingHandler(ctx context.Context, controller ETCDSnapshotFileController, apply apply.Apply, func RegisterETCDSnapshotFileGeneratingHandler(ctx context.Context, controller ETCDSnapshotFileController, apply apply.Apply,
......
...@@ -46,13 +46,9 @@ type version struct { ...@@ -46,13 +46,9 @@ type version struct {
} }
func (v *version) Addon() AddonController { func (v *version) Addon() AddonController {
return &AddonGenericController{ return generic.NewController[*v1.Addon, *v1.AddonList](schema.GroupVersionKind{Group: "k3s.cattle.io", Version: "v1", Kind: "Addon"}, "addons", true, v.controllerFactory)
generic.NewController[*v1.Addon, *v1.AddonList](schema.GroupVersionKind{Group: "k3s.cattle.io", Version: "v1", Kind: "Addon"}, "addons", true, v.controllerFactory),
}
} }
func (v *version) ETCDSnapshotFile() ETCDSnapshotFileController { func (v *version) ETCDSnapshotFile() ETCDSnapshotFileController {
return &ETCDSnapshotFileGenericController{ return generic.NewNonNamespacedController[*v1.ETCDSnapshotFile, *v1.ETCDSnapshotFileList](schema.GroupVersionKind{Group: "k3s.cattle.io", Version: "v1", Kind: "ETCDSnapshotFile"}, "etcdsnapshotfiles", v.controllerFactory)
generic.NewNonNamespacedController[*v1.ETCDSnapshotFile, *v1.ETCDSnapshotFileList](schema.GroupVersionKind{Group: "k3s.cattle.io", Version: "v1", Kind: "ETCDSnapshotFile"}, "etcdsnapshotfiles", v.controllerFactory),
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment