generic.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2026 the Kilo authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Code generated by informer-gen. DO NOT EDIT.
  15. package informers
  16. import (
  17. "fmt"
  18. v1alpha1 "github.com/squat/kilo/pkg/k8s/apis/kilo/v1alpha1"
  19. schema "k8s.io/apimachinery/pkg/runtime/schema"
  20. cache "k8s.io/client-go/tools/cache"
  21. )
  22. // GenericInformer is type of SharedIndexInformer which will locate and delegate to other
  23. // sharedInformers based on type
  24. type GenericInformer interface {
  25. Informer() cache.SharedIndexInformer
  26. Lister() cache.GenericLister
  27. }
  28. type genericInformer struct {
  29. informer cache.SharedIndexInformer
  30. resource schema.GroupResource
  31. }
  32. // Informer returns the SharedIndexInformer.
  33. func (f *genericInformer) Informer() cache.SharedIndexInformer {
  34. return f.informer
  35. }
  36. // Lister returns the GenericLister.
  37. func (f *genericInformer) Lister() cache.GenericLister {
  38. return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
  39. }
  40. // ForResource gives generic access to a shared informer of the matching type
  41. // TODO extend this to unknown resources with a client pool
  42. func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
  43. switch resource {
  44. // Group=kilo.squat.ai, Version=v1alpha1
  45. case v1alpha1.SchemeGroupVersion.WithResource("peers"):
  46. return &genericInformer{resource: resource.GroupResource(), informer: f.Kilo().V1alpha1().Peers().Informer()}, nil
  47. }
  48. return nil, fmt.Errorf("no informer found for %v", resource)
  49. }