agones.dev/agones@v1.53.0/pkg/client/informers/externalversions/generic.go (about)

     1  // Copyright 2024 Google LLC All Rights Reserved.
     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  
    15  // This code was autogenerated. Do not edit directly.
    16  
    17  // Code generated by informer-gen. DO NOT EDIT.
    18  
    19  package externalversions
    20  
    21  import (
    22  	fmt "fmt"
    23  
    24  	v1 "agones.dev/agones/pkg/apis/agones/v1"
    25  	autoscalingv1 "agones.dev/agones/pkg/apis/autoscaling/v1"
    26  	multiclusterv1 "agones.dev/agones/pkg/apis/multicluster/v1"
    27  	schema "k8s.io/apimachinery/pkg/runtime/schema"
    28  	cache "k8s.io/client-go/tools/cache"
    29  )
    30  
    31  // GenericInformer is type of SharedIndexInformer which will locate and delegate to other
    32  // sharedInformers based on type
    33  type GenericInformer interface {
    34  	Informer() cache.SharedIndexInformer
    35  	Lister() cache.GenericLister
    36  }
    37  
    38  type genericInformer struct {
    39  	informer cache.SharedIndexInformer
    40  	resource schema.GroupResource
    41  }
    42  
    43  // Informer returns the SharedIndexInformer.
    44  func (f *genericInformer) Informer() cache.SharedIndexInformer {
    45  	return f.informer
    46  }
    47  
    48  // Lister returns the GenericLister.
    49  func (f *genericInformer) Lister() cache.GenericLister {
    50  	return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
    51  }
    52  
    53  // ForResource gives generic access to a shared informer of the matching type
    54  // TODO extend this to unknown resources with a client pool
    55  func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
    56  	switch resource {
    57  	// Group=agones.dev, Version=v1
    58  	case v1.SchemeGroupVersion.WithResource("fleets"):
    59  		return &genericInformer{resource: resource.GroupResource(), informer: f.Agones().V1().Fleets().Informer()}, nil
    60  	case v1.SchemeGroupVersion.WithResource("gameservers"):
    61  		return &genericInformer{resource: resource.GroupResource(), informer: f.Agones().V1().GameServers().Informer()}, nil
    62  	case v1.SchemeGroupVersion.WithResource("gameserversets"):
    63  		return &genericInformer{resource: resource.GroupResource(), informer: f.Agones().V1().GameServerSets().Informer()}, nil
    64  
    65  		// Group=autoscaling.agones.dev, Version=v1
    66  	case autoscalingv1.SchemeGroupVersion.WithResource("fleetautoscalers"):
    67  		return &genericInformer{resource: resource.GroupResource(), informer: f.Autoscaling().V1().FleetAutoscalers().Informer()}, nil
    68  
    69  		// Group=multicluster.agones.dev, Version=v1
    70  	case multiclusterv1.SchemeGroupVersion.WithResource("gameserverallocationpolicies"):
    71  		return &genericInformer{resource: resource.GroupResource(), informer: f.Multicluster().V1().GameServerAllocationPolicies().Informer()}, nil
    72  
    73  	}
    74  
    75  	return nil, fmt.Errorf("no informer found for %v", resource)
    76  }