Documentation
¶
Overview ¶
Package composite provides a unified client, cache, and discovery system that seamlessly handles both native Kubernetes resources and Δ-controller view objects.
The composite system creates a transparent abstraction layer that allows controllers to work with view objects using the same APIs as native Kubernetes resources. View objects are maintained in an in-memory cache with full CRUD and watch capabilities, while native resources are delegated to the standard Kubernetes API server (if available).
Key components:
- CompositeClient: Unified client interface for both views and native resources.
- CompositeCache: Split caching system with view cache and native resource cache.
- CompositeDiscoveryClient: Unified API discovery for views and native resources.
- ClientMultiplexer: Routes client operations based on resource type.
- ViewCache: Specialized cache for view objects with informer support.
The composite system automatically determines whether a resource is a view or native Kubernetes resource based on its GroupVersionKind and routes operations accordingly. This enables transparent operation where controllers don't need to distinguish between view and native resources.
Index ¶
- Constants
- func AppendToListItem(list client.ObjectList, obj client.Object)
- func NewViewObjectList(operator, view string) object.ObjectList
- type APIClient
- type CacheOptions
- type ClientMultiplexer
- type ClientOptions
- type CompositeCache
- func (cc *CompositeCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, ...) error
- func (cc *CompositeCache) GetDefaultCache() cache.Cache
- func (cc *CompositeCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
- func (cc *CompositeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, ...) (cache.Informer, error)
- func (cc *CompositeCache) GetLogger() logr.Logger
- func (cc *CompositeCache) GetViewCache() *ViewCache
- func (cc *CompositeCache) IndexField(ctx context.Context, obj client.Object, field string, ...) error
- func (cc *CompositeCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (cc *CompositeCache) RemoveInformer(ctx context.Context, obj client.Object) error
- func (cc *CompositeCache) Start(ctx context.Context) error
- func (cc *CompositeCache) WaitForCacheSync(ctx context.Context) bool
- type CompositeClient
- func (c *CompositeClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
- func (c *CompositeClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
- func (c *CompositeClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
- func (c *CompositeClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, ...) error
- func (c *CompositeClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (c *CompositeClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, ...) error
- func (c *CompositeClient) SetCache(cache cache.Cache)
- func (c *CompositeClient) SetClient(client client.Client)
- func (c *CompositeClient) Status() client.SubResourceWriter
- func (c *CompositeClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
- func (c *CompositeClient) Watch(ctx context.Context, list client.ObjectList, opts ...client.ListOption) (watch.Interface, error)
- type CompositeDiscoveryClient
- func (c *CompositeDiscoveryClient) OpenAPISchema() (*openapiv2.Document, error)
- func (c *CompositeDiscoveryClient) OpenAPIV3() openapi.Client
- func (c *CompositeDiscoveryClient) RESTClient() restclient.Interface
- func (c *CompositeDiscoveryClient) ServerGroups() (*metav1.APIGroupList, error)
- func (c *CompositeDiscoveryClient) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)
- func (c *CompositeDiscoveryClient) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error)
- func (c *CompositeDiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error)
- func (c *CompositeDiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error)
- func (c *CompositeDiscoveryClient) ServerVersion() (*version.Info, error)
- func (c *CompositeDiscoveryClient) WithLegacy() discovery.DiscoveryInterface
- type CompositeRESTMapper
- func (m *CompositeRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error)
- func (m *CompositeRESTMapper) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error)
- func (m *CompositeRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error)
- func (m *CompositeRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error)
- func (m *CompositeRESTMapper) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error)
- func (m *CompositeRESTMapper) ResourceSingularizer(resource string) (string, error)
- func (m *CompositeRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error)
- type FakeInformer
- func (f *FakeInformer) Add(obj metav1.Object)
- func (f *FakeInformer) AddEventHandler(handler toolscache.ResourceEventHandler) (toolscache.ResourceEventHandlerRegistration, error)
- func (f *FakeInformer) AddEventHandlerWithContext(handler toolscache.ResourceEventHandler, _ time.Duration) (toolscache.ResourceEventHandlerRegistration, error)
- func (f *FakeInformer) AddEventHandlerWithOptions(handler toolscache.ResourceEventHandler, _ toolscache.HandlerOptions) (toolscache.ResourceEventHandlerRegistration, error)
- func (f *FakeInformer) AddEventHandlerWithResyncPeriod(handler toolscache.ResourceEventHandler, _ time.Duration) (toolscache.ResourceEventHandlerRegistration, error)
- func (f *FakeInformer) AddIndexers(indexers toolscache.Indexers) error
- func (f *FakeInformer) Delete(obj metav1.Object)
- func (f *FakeInformer) GetController() toolscache.Controller
- func (f *FakeInformer) GetIndexer() toolscache.Indexer
- func (f *FakeInformer) GetStore() toolscache.Store
- func (f *FakeInformer) HasSynced() bool
- func (f *FakeInformer) Informer() toolscache.SharedIndexInformer
- func (f *FakeInformer) IsStopped() bool
- func (f *FakeInformer) LastSyncResourceVersion() string
- func (f *FakeInformer) RemoveEventHandler(handle toolscache.ResourceEventHandlerRegistration) error
- func (f *FakeInformer) Run(<-chan struct{})
- func (f *FakeInformer) RunWithContext(_ context.Context)
- func (f *FakeInformer) SetTransform(t toolscache.TransformFunc) error
- func (f *FakeInformer) SetWatchErrorHandler(toolscache.WatchErrorHandler) error
- func (f *FakeInformer) SetWatchErrorHandlerWithContext(toolscache.WatchErrorHandlerWithContext) error
- func (f *FakeInformer) Update(oldObj, newObj metav1.Object)
- type FakeRuntimeCache
- func (c *FakeRuntimeCache) Add(obj any) error
- func (c *FakeRuntimeCache) Delete(obj any) error
- func (c *FakeRuntimeCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, ...) error
- func (c *FakeRuntimeCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
- func (c *FakeRuntimeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, ...) (cache.Informer, error)
- func (c *FakeRuntimeCache) IndexField(ctx context.Context, obj client.Object, field string, ...) error
- func (c *FakeRuntimeCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (c *FakeRuntimeCache) RemoveInformer(ctx context.Context, obj client.Object) error
- func (c *FakeRuntimeCache) Start(ctx context.Context) error
- func (c *FakeRuntimeCache) Update(oldObj, newObj any) error
- func (c *FakeRuntimeCache) WaitForCacheSync(ctx context.Context) bool
- type Lister
- type Options
- type Store
- func (s *Store) Add(obj object.Object) error
- func (s *Store) Delete(obj object.Object) error
- func (s *Store) Get(obj object.Object) (object.Object, bool, error)
- func (s *Store) GetByKey(key string) (object.Object, bool, error)
- func (s *Store) List() []object.Object
- func (s *Store) ListKeys() []string
- func (s *Store) Replace(objs []object.Object, arg string) error
- func (s *Store) Resync() error
- func (s *Store) Update(obj object.Object) error
- type ViewCache
- func (c *ViewCache) Add(obj object.Object) error
- func (c *ViewCache) Delete(obj object.Object) error
- func (c *ViewCache) Dump(ctx context.Context, gvk schema.GroupVersionKind) []string
- func (c *ViewCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, ...) error
- func (c *ViewCache) GetCacheForKind(gvk schema.GroupVersionKind) (toolscache.Indexer, error)
- func (vc *ViewCache) GetClient() client.WithWatch
- func (c *ViewCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
- func (c *ViewCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, _ ...cache.InformerGetOption) (cache.Informer, error)
- func (c *ViewCache) IndexField(ctx context.Context, obj client.Object, field string, ...) error
- func (c *ViewCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (c *ViewCache) RegisterCacheForKind(gvk schema.GroupVersionKind) error
- func (c *ViewCache) RegisterInformerForKind(gvk schema.GroupVersionKind) error
- func (c *ViewCache) RemoveInformer(ctx context.Context, obj client.Object) error
- func (c *ViewCache) Start(ctx context.Context) error
- func (c *ViewCache) Update(oldObj, newObj object.Object) error
- func (c *ViewCache) WaitForCacheSync(_ context.Context) bool
- func (c *ViewCache) Watch(ctx context.Context, list client.ObjectList, opts ...client.ListOption) (watch.Interface, error)
- type ViewCacheInformer
- func (c *ViewCacheInformer) AddEventHandler(handler toolscache.ResourceEventHandler) (toolscache.ResourceEventHandlerRegistration, error)
- func (c *ViewCacheInformer) AddEventHandlerWithOptions(handler toolscache.ResourceEventHandler, _ toolscache.HandlerOptions) (toolscache.ResourceEventHandlerRegistration, error)
- func (c *ViewCacheInformer) AddEventHandlerWithResyncPeriod(handler toolscache.ResourceEventHandler, resyncPeriod time.Duration) (toolscache.ResourceEventHandlerRegistration, error)
- func (c *ViewCacheInformer) AddIndexers(indexers toolscache.Indexers) error
- func (c *ViewCacheInformer) GetController() toolscache.Controller
- func (c *ViewCacheInformer) GetIndexer() toolscache.Indexer
- func (c *ViewCacheInformer) GetStore() toolscache.Store
- func (c *ViewCacheInformer) HasSynced() bool
- func (c *ViewCacheInformer) IsStopped() bool
- func (c *ViewCacheInformer) LastSyncResourceVersion() string
- func (c *ViewCacheInformer) RemoveEventHandler(registration toolscache.ResourceEventHandlerRegistration) error
- func (c *ViewCacheInformer) Run(stopCh <-chan struct{})
- func (c *ViewCacheInformer) RunWithContext(ctx context.Context)
- func (c *ViewCacheInformer) SetTransform(transform toolscache.TransformFunc) error
- func (c *ViewCacheInformer) SetWatchErrorHandler(_ toolscache.WatchErrorHandler) error
- func (c *ViewCacheInformer) SetWatchErrorHandlerWithContext(_ toolscache.WatchErrorHandlerWithContext) error
- func (c *ViewCacheInformer) TriggerEvent(eventType toolscache.DeltaType, oldObj, newObj object.Object, ...)
- type ViewCacheWatcher
- type ViewDiscovery
- func (d *ViewDiscovery) GetRegisteredViewGVKs() []schema.GroupVersionKind
- func (d *ViewDiscovery) IsViewGroup(group string) bool
- func (d *ViewDiscovery) IsViewKind(gvk schema.GroupVersionKind) bool
- func (d *ViewDiscovery) IsViewListKind(gvk schema.GroupVersionKind) bool
- func (d *ViewDiscovery) KindFromResource(resource string) (string, error)
- func (d *ViewDiscovery) ListGVKFromObjectGVK(objGVK schema.GroupVersionKind) schema.GroupVersionKind
- func (d *ViewDiscovery) ObjectGVKFromListGVK(listGVK schema.GroupVersionKind) schema.GroupVersionKind
- func (d *ViewDiscovery) RegisterViewGVK(gvk schema.GroupVersionKind) error
- func (d *ViewDiscovery) ResourceFromKind(kind string) string
- func (d *ViewDiscovery) ServerGroups() (*metav1.APIGroupList, error)
- func (d *ViewDiscovery) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)
- func (d *ViewDiscovery) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error)
- func (d *ViewDiscovery) ServerPreferredResources() ([]*metav1.APIResourceList, error)
- func (d *ViewDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error)
- func (d *ViewDiscovery) UnregisterViewGVK(gvk schema.GroupVersionKind) error
- type ViewDiscoveryInterface
- type ViewRESTMapper
- func (m *ViewRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error)
- func (m *ViewRESTMapper) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error)
- func (m *ViewRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error)
- func (m *ViewRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error)
- func (m *ViewRESTMapper) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error)
- func (m *ViewRESTMapper) ResourceSingularizer(resource string) (string, error)
- func (m *ViewRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error)
Constants ¶
const DefaultWatchChannelBuffer = 256
DefaultWatchChannelBuffer defines the default buffer size for watches.
Variables ¶
This section is empty.
Functions ¶
func AppendToListItem ¶
func AppendToListItem(list client.ObjectList, obj client.Object)
AppendToListItem appends an object to a list.
func NewViewObjectList ¶
func NewViewObjectList(operator, view string) object.ObjectList
NewViewObjectList creates an empty object list.
Types ¶
type APIClient ¶
type APIClient struct { Client client.Client Cache cache.Cache Discovery discovery.DiscoveryInterface RESTMapper meta.RESTMapper Log logr.Logger }
APIClient bundles multiple API machinery components into a single client, including a regular client, a discovery client, a cache and a REST mapper.
func NewCompositeAPIClient ¶
NewCompositeAPIClient creates a composite API client with all components.
func (*APIClient) GetCache ¶
func (c *APIClient) GetCache() *CompositeCache
GetCache returns the cache for the bundle.
func (*APIClient) GetClient ¶
func (c *APIClient) GetClient() *CompositeClient
GetCache returns the client for the bundle.
func (*APIClient) GetDiscovery ¶
func (c *APIClient) GetDiscovery() *CompositeDiscoveryClient
GetDiscovery returns the composite discovery client with view-specific extensions.
type CacheOptions ¶
type CacheOptions struct { cache.Options // DefaultCache is the controller-runtime cache used for anything that is not a view. DefaultCache cache.Cache // Logger is for logging. Currently only the viewcache generates log messages. Logger logr.Logger }
CacheOptions are generic caching options.
type ClientMultiplexer ¶
type ClientMultiplexer interface { client.WithWatch RegisterClient(group string, client client.Client) error UnregisterClient(group string) error }
ClientMultiplexer multiplexes controller-runtime clients by API group.
func NewClientMultiplexer ¶
func NewClientMultiplexer(logger logr.Logger) ClientMultiplexer
NewClientMultiplexer creates a new ClientMultiplexer instance.
type ClientOptions ¶
type CompositeCache ¶
type CompositeCache struct {
// contains filtered or unexported fields
}
CompositeCache is a cache for storing view objects. It delegates native objects to a default cache.
func NewCompositeCache ¶
func NewCompositeCache(config *rest.Config, group string, opts CacheOptions) (*CompositeCache, error)
NewCompositeCache creates a new composite cache for the griven group. If the config is not nil it also creates a controller-runtime for storing native resources.
func (*CompositeCache) Get ¶
func (cc *CompositeCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error
Get retrieves an obj for the given object key from the cache.
func (*CompositeCache) GetDefaultCache ¶
func (cc *CompositeCache) GetDefaultCache() cache.Cache
GetDefaultCache returns the cache used for storing native objects.
func (*CompositeCache) GetInformer ¶
func (cc *CompositeCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
GetInformer fetches or constructs an informer for the given object.
func (*CompositeCache) GetInformerForKind ¶
func (cc *CompositeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, opts ...cache.InformerGetOption) (cache.Informer, error)
GetInformerForKind is similar to GetInformer, except that it takes a group-version-kind instead of the underlying object.
func (*CompositeCache) GetLogger ¶
func (cc *CompositeCache) GetLogger() logr.Logger
GetLogger returns the logger of the cache.
func (*CompositeCache) GetViewCache ¶
func (cc *CompositeCache) GetViewCache() *ViewCache
GetViewCache returns the cache used for storing view objects.
func (*CompositeCache) IndexField ¶
func (cc *CompositeCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error
IndexField adds an index with the given field name on the given object type.
func (*CompositeCache) List ¶
func (cc *CompositeCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
List retrieves list of objects for a given namespace and list options.
func (*CompositeCache) RemoveInformer ¶
RemoveInformer removes an informer entry and stops it if it was running.
func (*CompositeCache) Start ¶
func (cc *CompositeCache) Start(ctx context.Context) error
Start runs all the informers known to this cache until the context is closed. It blocks.
func (*CompositeCache) WaitForCacheSync ¶
func (cc *CompositeCache) WaitForCacheSync(ctx context.Context) bool
WaitForCacheSync waits for all the caches to sync. Returns false if it could not sync a cache.c
type CompositeClient ¶
CompositeClient is a controlller runtime client that uses a view cache to manage view resources and delegates native resources to a default client.
func NewCompositeClient ¶
func NewCompositeClient(config *rest.Config, group string, options ClientOptions) (*CompositeClient, error)
NewCompositeClient creates a composite client: views are served through the viewcache, native Kubernetes resources served from a native client (can be a split client).
func (*CompositeClient) Create ¶
func (c *CompositeClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error
Create saves the object obj.
func (*CompositeClient) Delete ¶
func (c *CompositeClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
Delete deletes the given obj.
func (*CompositeClient) DeleteAllOf ¶
func (c *CompositeClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error
DeleteAllOf deletes all objects of the given type matching the given options.
func (*CompositeClient) Get ¶
func (c *CompositeClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error
Get retrieves an obj for the given object key.
func (*CompositeClient) List ¶
func (c *CompositeClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
List retrieves list of objects for a given namespace and list options.
func (*CompositeClient) Patch ¶
func (c *CompositeClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error
Patch patches the given obj.
func (*CompositeClient) SetCache ¶
func (c *CompositeClient) SetCache(cache cache.Cache)
SetClient sets the cache in the composite client.
func (*CompositeClient) SetClient ¶
func (c *CompositeClient) SetClient(client client.Client)
SetClient sets the native client in the composite client.
func (*CompositeClient) Status ¶
func (c *CompositeClient) Status() client.SubResourceWriter
Status implements StatusClient. Note that normally this would not be needed since the default view-object client already writes the status if requested, but still needed because native objects' status can only be updated via the status-writer
func (*CompositeClient) Update ¶
func (c *CompositeClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error
Update updates the given obj.
func (*CompositeClient) Watch ¶
func (c *CompositeClient) Watch(ctx context.Context, list client.ObjectList, opts ...client.ListOption) (watch.Interface, error)
Watch watches objects of type obj and sends events on the returned channel
type CompositeDiscoveryClient ¶
type CompositeDiscoveryClient struct { ViewDiscoveryInterface // contains filtered or unexported fields }
CompositeDiscoveryClient implements discovery.DiscoveryInterface by routing view groups to ViewDiscovery and native groups to native discovery.
func NewCompositeDiscoveryClient ¶
func NewCompositeDiscoveryClient(nativeDiscovery discovery.DiscoveryInterface) *CompositeDiscoveryClient
NewCompositeDiscoveryClient creates a new composite discovery client.
func (*CompositeDiscoveryClient) OpenAPISchema ¶
func (c *CompositeDiscoveryClient) OpenAPISchema() (*openapiv2.Document, error)
OpenAPISchema retrieves and parses the swagger API schema the server supports.
func (*CompositeDiscoveryClient) OpenAPIV3 ¶
func (c *CompositeDiscoveryClient) OpenAPIV3() openapi.Client
OpenAPISchema retrieves and parses the OpenAPIv3 schema the server supports.
func (*CompositeDiscoveryClient) RESTClient ¶
func (c *CompositeDiscoveryClient) RESTClient() restclient.Interface
RESTClient implements discovery.DiscoveryInterface.
func (*CompositeDiscoveryClient) ServerGroups ¶
func (c *CompositeDiscoveryClient) ServerGroups() (*metav1.APIGroupList, error)
ServerGroups returns the supported groups, with information like supported versions and the preferred version.
func (*CompositeDiscoveryClient) ServerGroupsAndResources ¶
func (c *CompositeDiscoveryClient) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)
ServerGroupsAndResources returns the supported groups and resources for all groups and versions.
func (*CompositeDiscoveryClient) ServerPreferredNamespacedResources ¶
func (c *CompositeDiscoveryClient) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error)
ServerPreferredNamespacedResources returns the supported namespaced resources with the version preferred by the server.
func (*CompositeDiscoveryClient) ServerPreferredResources ¶
func (c *CompositeDiscoveryClient) ServerPreferredResources() ([]*metav1.APIResourceList, error)
ServerPreferredResources returns the supported resources with the version preferred by the server.
func (*CompositeDiscoveryClient) ServerResourcesForGroupVersion ¶
func (c *CompositeDiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error)
ServerResourcesForGroupVersion returns the supported resources for a group and version.
func (*CompositeDiscoveryClient) ServerVersion ¶
func (c *CompositeDiscoveryClient) ServerVersion() (*version.Info, error)
ServerVersion retrieves and parses the server's version.
func (*CompositeDiscoveryClient) WithLegacy ¶
func (c *CompositeDiscoveryClient) WithLegacy() discovery.DiscoveryInterface
WithLegacy returns a copy of the discovery client that will only receive the legacy discovery format.
type CompositeRESTMapper ¶
type CompositeRESTMapper struct {
// contains filtered or unexported fields
}
CompositeRESTMapper implements meta.RESTMapper by routing view groups to ViewRESTMapper and native groups to native RESTMapper.
func NewCompositeRESTMapper ¶
func NewCompositeRESTMapper(compositeDiscovery discovery.DiscoveryInterface) *CompositeRESTMapper
NewCompositeRESTMapper creates a new composite REST mapper.
func (*CompositeRESTMapper) KindFor ¶
func (m *CompositeRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error)
KindFor returns the Kind for the given resource.
func (*CompositeRESTMapper) KindsFor ¶
func (m *CompositeRESTMapper) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error)
KindsFor returns all Kinds for the given resource.
func (*CompositeRESTMapper) RESTMapping ¶
func (m *CompositeRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error)
RESTMapping returns the RESTMapping for the given GroupKind.
func (*CompositeRESTMapper) RESTMappings ¶
func (m *CompositeRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error)
RESTMappings returns all RESTMappings for the given GroupKind.
func (*CompositeRESTMapper) ResourceFor ¶
func (m *CompositeRESTMapper) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error)
ResourceFor returns the Resource for the given input.
func (*CompositeRESTMapper) ResourceSingularizer ¶
func (m *CompositeRESTMapper) ResourceSingularizer(resource string) (string, error)
ResourceSingularizer returns the singular form of the resource.
func (*CompositeRESTMapper) ResourcesFor ¶
func (m *CompositeRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error)
ResourcesFor returns all Resources for the given input.
type FakeInformer ¶
type FakeInformer struct { // Synced is returned by the HasSynced functions to implement the Informer interface Synced bool // RunCount is incremented each time RunInformersAndControllers is called RunCount int Indexer Lister // contains filtered or unexported fields }
FakeInformer provides fake Informer functionality for testing.
func (*FakeInformer) Add ¶
func (f *FakeInformer) Add(obj metav1.Object)
Add fakes an Add event for obj.
func (*FakeInformer) AddEventHandler ¶
func (f *FakeInformer) AddEventHandler(handler toolscache.ResourceEventHandler) (toolscache.ResourceEventHandlerRegistration, error)
func (*FakeInformer) AddEventHandlerWithContext ¶
func (f *FakeInformer) AddEventHandlerWithContext(handler toolscache.ResourceEventHandler, _ time.Duration) (toolscache.ResourceEventHandlerRegistration, error)
func (*FakeInformer) AddEventHandlerWithOptions ¶
func (f *FakeInformer) AddEventHandlerWithOptions(handler toolscache.ResourceEventHandler, _ toolscache.HandlerOptions) (toolscache.ResourceEventHandlerRegistration, error)
func (*FakeInformer) AddEventHandlerWithResyncPeriod ¶
func (f *FakeInformer) AddEventHandlerWithResyncPeriod(handler toolscache.ResourceEventHandler, _ time.Duration) (toolscache.ResourceEventHandlerRegistration, error)
func (*FakeInformer) AddIndexers ¶
func (f *FakeInformer) AddIndexers(indexers toolscache.Indexers) error
func (*FakeInformer) Delete ¶
func (f *FakeInformer) Delete(obj metav1.Object)
Delete fakes an Delete event for obj.
func (*FakeInformer) GetController ¶
func (f *FakeInformer) GetController() toolscache.Controller
func (*FakeInformer) GetIndexer ¶
func (f *FakeInformer) GetIndexer() toolscache.Indexer
func (*FakeInformer) GetStore ¶
func (f *FakeInformer) GetStore() toolscache.Store
func (*FakeInformer) HasSynced ¶
func (f *FakeInformer) HasSynced() bool
func (*FakeInformer) Informer ¶
func (f *FakeInformer) Informer() toolscache.SharedIndexInformer
func (*FakeInformer) IsStopped ¶
func (f *FakeInformer) IsStopped() bool
func (*FakeInformer) LastSyncResourceVersion ¶
func (f *FakeInformer) LastSyncResourceVersion() string
func (*FakeInformer) RemoveEventHandler ¶
func (f *FakeInformer) RemoveEventHandler(handle toolscache.ResourceEventHandlerRegistration) error
func (*FakeInformer) Run ¶
func (f *FakeInformer) Run(<-chan struct{})
func (*FakeInformer) RunWithContext ¶
func (f *FakeInformer) RunWithContext(_ context.Context)
func (*FakeInformer) SetTransform ¶
func (f *FakeInformer) SetTransform(t toolscache.TransformFunc) error
func (*FakeInformer) SetWatchErrorHandler ¶
func (f *FakeInformer) SetWatchErrorHandler(toolscache.WatchErrorHandler) error
func (*FakeInformer) SetWatchErrorHandlerWithContext ¶
func (f *FakeInformer) SetWatchErrorHandlerWithContext(toolscache.WatchErrorHandlerWithContext) error
func (*FakeInformer) Update ¶
func (f *FakeInformer) Update(oldObj, newObj metav1.Object)
Update fakes an Update event for obj.
type FakeRuntimeCache ¶
type FakeRuntimeCache struct { InformersByGVK map[schema.GroupVersionKind]toolscache.SharedIndexInformer Error error Synced *bool Store *Store }
FakeRuntimeCache is a fake implementation of Informers. Client can store only a single object. Source: sigs.k8s.io/controller-runtime/pkg/cache/informertest/fake_cache.go.
func NewFakeRuntimeCache ¶
func NewFakeRuntimeCache(s *runtime.Scheme) *FakeRuntimeCache
func (*FakeRuntimeCache) Add ¶
func (c *FakeRuntimeCache) Add(obj any) error
func (*FakeRuntimeCache) Delete ¶
func (c *FakeRuntimeCache) Delete(obj any) error
func (*FakeRuntimeCache) GetInformer ¶
func (c *FakeRuntimeCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
GetInformer implements Informers.
func (*FakeRuntimeCache) GetInformerForKind ¶
func (c *FakeRuntimeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, opts ...cache.InformerGetOption) (cache.Informer, error)
GetInformerForKind implements Informers.
func (*FakeRuntimeCache) IndexField ¶
func (c *FakeRuntimeCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error
IndexField implements Cache.
func (*FakeRuntimeCache) List ¶
func (c *FakeRuntimeCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
func (*FakeRuntimeCache) RemoveInformer ¶
RemoveInformer implements Informers.
func (*FakeRuntimeCache) Start ¶
func (c *FakeRuntimeCache) Start(ctx context.Context) error
Start implements Informers.
func (*FakeRuntimeCache) Update ¶
func (c *FakeRuntimeCache) Update(oldObj, newObj any) error
func (*FakeRuntimeCache) WaitForCacheSync ¶
func (c *FakeRuntimeCache) WaitForCacheSync(ctx context.Context) bool
WaitForCacheSync implements Informers.
type Options ¶
type Options struct { CacheOptions ClientOptions Logger logr.Logger }
Options for creating composite API clients.
type Store ¶
type Store struct {
Store toolscache.Store
}
Store is like toolscache.Store but it also deep-copies objects.
func (*Store) Add ¶
Add adds the given object to the database associated with the given object's key.
func (*Store) Delete ¶
Delete deletes the given object from the database associated with the given object's key.
func (*Store) ListKeys ¶
ListKeys returns a list of all the keys currently associated with non-empty databases.
func (*Store) Replace ¶
Replace will delete the contents of the store, using instead the given list. Store takes ownership of the list, you should not reference it after calling this function.
type ViewCache ¶
type ViewCache struct {
// contains filtered or unexported fields
}
ViewCache implements an ephemeral store for view objects. The view cache has an internal cache per each GVK that can be stored in the cache.
func NewViewCache ¶
func NewViewCache(group string, opts CacheOptions) *ViewCache
NewViewCache creates a new view cache.
func (*ViewCache) Dump ¶
Dump returns a string representation of all objects stored in a cache given a GVK. Used mostly for testing and debugging.
func (*ViewCache) Get ¶
func (c *ViewCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error
Get retrieves an obj for the given object key from the cache.
func (*ViewCache) GetCacheForKind ¶
func (c *ViewCache) GetCacheForKind(gvk schema.GroupVersionKind) (toolscache.Indexer, error)
GetCacheForKind returns the internal cache for a given GVK.
func (*ViewCache) GetClient ¶
GetClient returns a controller-runtime client backed by this ViewCache.
func (*ViewCache) GetInformer ¶
func (c *ViewCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
GetInformer fetches or constructs an informer for the given object.
func (*ViewCache) GetInformerForKind ¶
func (c *ViewCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, _ ...cache.InformerGetOption) (cache.Informer, error)
GetInformerForKind is similar to GetInformer, except that it takes a group-version-kind, instead of the underlying object.
func (*ViewCache) IndexField ¶
func (c *ViewCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error
IndexField adds an index with the given field name on the given object type.
func (*ViewCache) List ¶
func (c *ViewCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
List retrieves a list of objects for a given namespace and list options from the cache.
func (*ViewCache) RegisterCacheForKind ¶
func (c *ViewCache) RegisterCacheForKind(gvk schema.GroupVersionKind) error
RegisterCacheForKind registers a new GVK in the cache.
func (*ViewCache) RegisterInformerForKind ¶
func (c *ViewCache) RegisterInformerForKind(gvk schema.GroupVersionKind) error
RegisterInformerForKind registers an informer for a GVK.
func (*ViewCache) RemoveInformer ¶
RemoveInformer removes an informer entry and stops it if it was running.
func (*ViewCache) Start ¶
Start runs all the informers known to this cache until the context is closed. It blocks.
func (*ViewCache) WaitForCacheSync ¶
WaitForCacheSync waits for all the caches to sync. Returns false if it could not sync a cache.
type ViewCacheInformer ¶
type ViewCacheInformer struct {
// contains filtered or unexported fields
}
ViewCacheInformer is an informer for implementing watchers on the view cache.
func NewViewCacheInformer ¶
func NewViewCacheInformer(gvk schema.GroupVersionKind, indexer toolscache.Indexer, logger logr.Logger) *ViewCacheInformer
NewViewCacheInformer returns a new informer for the view cache.
func (*ViewCacheInformer) AddEventHandler ¶
func (c *ViewCacheInformer) AddEventHandler(handler toolscache.ResourceEventHandler) (toolscache.ResourceEventHandlerRegistration, error)
AddEventHandler adds an event handler to the shared informer.
func (*ViewCacheInformer) AddEventHandlerWithOptions ¶
func (c *ViewCacheInformer) AddEventHandlerWithOptions(handler toolscache.ResourceEventHandler, _ toolscache.HandlerOptions) (toolscache.ResourceEventHandlerRegistration, error)
AddEventHandlerWithOptions is a variant of AddEventHandlerWithResyncPeriod where all optional parameters are passed in as a struct.
func (*ViewCacheInformer) AddEventHandlerWithResyncPeriod ¶
func (c *ViewCacheInformer) AddEventHandlerWithResyncPeriod(handler toolscache.ResourceEventHandler, resyncPeriod time.Duration) (toolscache.ResourceEventHandlerRegistration, error)
AddEventHandlerWithResyncPeriod adds an event handler to the shared informer informer using the specified resync period.
func (*ViewCacheInformer) AddIndexers ¶
func (c *ViewCacheInformer) AddIndexers(indexers toolscache.Indexers) error
AddIndexers adds more indexers to this store. This supports adding indexes after the store already has items.
func (*ViewCacheInformer) GetController ¶
func (c *ViewCacheInformer) GetController() toolscache.Controller
GetController is deprecated, it does nothing useful.
func (*ViewCacheInformer) GetIndexer ¶
func (c *ViewCacheInformer) GetIndexer() toolscache.Indexer
GetIndexer returns the indexer for a view cache.
func (*ViewCacheInformer) GetStore ¶
func (c *ViewCacheInformer) GetStore() toolscache.Store
GetStore returns the informer's local cache as a Store.
func (*ViewCacheInformer) HasSynced ¶
func (c *ViewCacheInformer) HasSynced() bool
HasSynced returns true if the shared informer's store has been informed by at least one full LIST of the authoritative state of the informer's object collection.
func (*ViewCacheInformer) IsStopped ¶
func (c *ViewCacheInformer) IsStopped() bool
IsStopped reports whether the informer has already been stopped. An informer already stopped will never be started again.
func (*ViewCacheInformer) LastSyncResourceVersion ¶
func (c *ViewCacheInformer) LastSyncResourceVersion() string
LastSyncResourceVersion is the resource version observed when last synced with the underlying store.
func (*ViewCacheInformer) RemoveEventHandler ¶
func (c *ViewCacheInformer) RemoveEventHandler(registration toolscache.ResourceEventHandlerRegistration) error
RemoveEventHandler removes a previously added event handler given by its registration handle.
func (*ViewCacheInformer) Run ¶
func (c *ViewCacheInformer) Run(stopCh <-chan struct{})
Run starts and runs the shared informer, returning after it stops. The informer will be stopped when stopCh is closed.
func (*ViewCacheInformer) RunWithContext ¶
func (c *ViewCacheInformer) RunWithContext(ctx context.Context)
RunWithContext starts and runs the shared informer, returning after it stops. The informer will be stopped when the context is canceled.
func (*ViewCacheInformer) SetTransform ¶
func (c *ViewCacheInformer) SetTransform(transform toolscache.TransformFunc) error
SetTransform create a transformer with a given TransformFunc that is called for each object which is about to be stored.
func (*ViewCacheInformer) SetWatchErrorHandler ¶
func (c *ViewCacheInformer) SetWatchErrorHandler(_ toolscache.WatchErrorHandler) error
The WatchErrorHandler is called whenever ListAndWatch drops the connection with an error. After calling this handler, the informer will backoff and retry.
func (*ViewCacheInformer) SetWatchErrorHandlerWithContext ¶
func (c *ViewCacheInformer) SetWatchErrorHandlerWithContext(_ toolscache.WatchErrorHandlerWithContext) error
SetWatchErrorHandlerWithContext is a variant of SetWatchErrorHandler where the handler is passed an additional context parameter.
func (*ViewCacheInformer) TriggerEvent ¶
func (c *ViewCacheInformer) TriggerEvent(eventType toolscache.DeltaType, oldObj, newObj object.Object, isInitialList bool)
TriggerEvent will send an event on newObj of eventType to all registered handlers. Set isInitialList to true if event is an Added as a part of the initial object list. For all event types except Update events the oldObj must not be nil.
type ViewCacheWatcher ¶
type ViewCacheWatcher struct {
// contains filtered or unexported fields
}
ViewCacheWatcher is a watcher specialized tof the view cache.
func (*ViewCacheWatcher) ResultChan ¶
func (w *ViewCacheWatcher) ResultChan() <-chan watch.Event
ResultChan returns the event channel of the watcher.
type ViewDiscovery ¶
type ViewDiscovery struct {
// contains filtered or unexported fields
}
ViewDiscovery implements discovery for view resources.
func NewViewDiscovery ¶
func NewViewDiscovery() *ViewDiscovery
NewViewDiscovery creates a new view discovery instance.
func (*ViewDiscovery) GetRegisteredViewGVKs ¶
func (d *ViewDiscovery) GetRegisteredViewGVKs() []schema.GroupVersionKind
GetRegisteredViewGVKs returns all registered view GVKs.
func (*ViewDiscovery) IsViewGroup ¶
func (d *ViewDiscovery) IsViewGroup(group string) bool
IsViewGroup returns true if the group is a view group.
func (*ViewDiscovery) IsViewKind ¶
func (d *ViewDiscovery) IsViewKind(gvk schema.GroupVersionKind) bool
IsViewKind returns true if this is a view object kind (not a list).
func (*ViewDiscovery) IsViewListKind ¶
func (d *ViewDiscovery) IsViewListKind(gvk schema.GroupVersionKind) bool
IsViewListKind returns true if this is a view list kind.
func (*ViewDiscovery) KindFromResource ¶
func (d *ViewDiscovery) KindFromResource(resource string) (string, error)
KindFromResource converts resource name to view kind (Title case). Works only for registered views.
func (*ViewDiscovery) ListGVKFromObjectGVK ¶
func (d *ViewDiscovery) ListGVKFromObjectGVK(objGVK schema.GroupVersionKind) schema.GroupVersionKind
ListGVKFromObjectGVK converts an object GVK to its list GVK.
func (*ViewDiscovery) ObjectGVKFromListGVK ¶
func (d *ViewDiscovery) ObjectGVKFromListGVK(listGVK schema.GroupVersionKind) schema.GroupVersionKind
ObjectGVKFromListGVK converts a list GVK to its object GVK.
func (*ViewDiscovery) RegisterViewGVK ¶
func (d *ViewDiscovery) RegisterViewGVK(gvk schema.GroupVersionKind) error
RegisterViewGVK registers a new view GVK for discovery.
func (*ViewDiscovery) ResourceFromKind ¶
func (d *ViewDiscovery) ResourceFromKind(kind string) string
ResourceFromKind converts view kind to resource name. The convention is that the resource name is the lowercase kind, which is typically singular. This is a digression from Kubernetes where the resource name is plural. Since views are declared implicitly with the singular name (as a controller source or target) we cannot know the plural.
func (*ViewDiscovery) ServerGroups ¶
func (d *ViewDiscovery) ServerGroups() (*metav1.APIGroupList, error)
ServerGroups returns available view API groups.
func (*ViewDiscovery) ServerGroupsAndResources ¶
func (d *ViewDiscovery) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error)
ServerGroupsAndResources returns groups and resources separately.
func (*ViewDiscovery) ServerPreferredNamespacedResources ¶
func (d *ViewDiscovery) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error)
ServerPreferredNamespacedResources returns the supported namespaced resources with the version preferred by the server.
func (*ViewDiscovery) ServerPreferredResources ¶
func (d *ViewDiscovery) ServerPreferredResources() ([]*metav1.APIResourceList, error)
ServerPreferredResources returns preferred API resources.
func (*ViewDiscovery) ServerResourcesForGroupVersion ¶
func (d *ViewDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error)
ServerResourcesForGroupVersion returns API resources for a view group version.
func (*ViewDiscovery) UnregisterViewGVK ¶
func (d *ViewDiscovery) UnregisterViewGVK(gvk schema.GroupVersionKind) error
UnregisterViewGVK removes a view GVK from discovery.
type ViewDiscoveryInterface ¶
type ViewDiscoveryInterface interface { discovery.ServerResourcesInterface discovery.ServerGroupsInterface // View-specific methods IsViewGroup(group string) bool IsViewKind(gvk schema.GroupVersionKind) bool IsViewListKind(gvk schema.GroupVersionKind) bool ObjectGVKFromListGVK(listGVK schema.GroupVersionKind) schema.GroupVersionKind ListGVKFromObjectGVK(objGVK schema.GroupVersionKind) schema.GroupVersionKind ResourceFromKind(kind string) string KindFromResource(resource string) (string, error) // Dynamic registration RegisterViewGVK(gvk schema.GroupVersionKind) error UnregisterViewGVK(gvk schema.GroupVersionKind) error GetRegisteredViewGVKs() []schema.GroupVersionKind }
ViewDiscoveryInterface handles view-specific discovery operations.
type ViewRESTMapper ¶
type ViewRESTMapper struct{}
ViewRESTMapper implements meta.RESTMapper for view resources.
func NewViewRESTMapper ¶
func NewViewRESTMapper() *ViewRESTMapper
NewViewRESTMapper creates a new view REST mapper.
func (*ViewRESTMapper) KindFor ¶
func (m *ViewRESTMapper) KindFor(resource schema.GroupVersionResource) (schema.GroupVersionKind, error)
KindFor returns the Kind for the given view resource.
func (*ViewRESTMapper) KindsFor ¶
func (m *ViewRESTMapper) KindsFor(resource schema.GroupVersionResource) ([]schema.GroupVersionKind, error)
KindsFor returns all Kinds for the given view resource (just one).
func (*ViewRESTMapper) RESTMapping ¶
func (m *ViewRESTMapper) RESTMapping(gk schema.GroupKind, versions ...string) (*meta.RESTMapping, error)
RESTMapping returns the RESTMapping for the given view GroupKind.
func (*ViewRESTMapper) RESTMappings ¶
func (m *ViewRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error)
RESTMappings returns all RESTMappings for the given view GroupKind (just one).
func (*ViewRESTMapper) ResourceFor ¶
func (m *ViewRESTMapper) ResourceFor(input schema.GroupVersionResource) (schema.GroupVersionResource, error)
ResourceFor returns the Resource for the given view input.
func (*ViewRESTMapper) ResourceSingularizer ¶
func (m *ViewRESTMapper) ResourceSingularizer(resource string) (string, error)
ResourceSingularizer returns the singular form (same as plural for views).
func (*ViewRESTMapper) ResourcesFor ¶
func (m *ViewRESTMapper) ResourcesFor(input schema.GroupVersionResource) ([]schema.GroupVersionResource, error)
ResourcesFor returns all Resources for the given view input (just one).