github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/api/client/informers/externalversions/generic.go (about)

     1  /*
     2  Copyright Red Hat, Inc.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Code generated by informer-gen. DO NOT EDIT.
    18  
    19  package externalversions
    20  
    21  import (
    22  	"fmt"
    23  
    24  	v1 "github.com/operator-framework/api/pkg/operators/v1"
    25  	v1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
    26  	v1alpha2 "github.com/operator-framework/api/pkg/operators/v1alpha2"
    27  	v2 "github.com/operator-framework/api/pkg/operators/v2"
    28  	schema "k8s.io/apimachinery/pkg/runtime/schema"
    29  	cache "k8s.io/client-go/tools/cache"
    30  )
    31  
    32  // GenericInformer is type of SharedIndexInformer which will locate and delegate to other
    33  // sharedInformers based on type
    34  type GenericInformer interface {
    35  	Informer() cache.SharedIndexInformer
    36  	Lister() cache.GenericLister
    37  }
    38  
    39  type genericInformer struct {
    40  	informer cache.SharedIndexInformer
    41  	resource schema.GroupResource
    42  }
    43  
    44  // Informer returns the SharedIndexInformer.
    45  func (f *genericInformer) Informer() cache.SharedIndexInformer {
    46  	return f.informer
    47  }
    48  
    49  // Lister returns the GenericLister.
    50  func (f *genericInformer) Lister() cache.GenericLister {
    51  	return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
    52  }
    53  
    54  // ForResource gives generic access to a shared informer of the matching type
    55  // TODO extend this to unknown resources with a client pool
    56  func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
    57  	switch resource {
    58  	// Group=operators.coreos.com, Version=v1
    59  	case v1.SchemeGroupVersion.WithResource("olmconfigs"):
    60  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1().OLMConfigs().Informer()}, nil
    61  	case v1.SchemeGroupVersion.WithResource("operators"):
    62  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1().Operators().Informer()}, nil
    63  	case v1.SchemeGroupVersion.WithResource("operatorconditions"):
    64  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1().OperatorConditions().Informer()}, nil
    65  	case v1.SchemeGroupVersion.WithResource("operatorgroups"):
    66  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1().OperatorGroups().Informer()}, nil
    67  
    68  		// Group=operators.coreos.com, Version=v1alpha1
    69  	case v1alpha1.SchemeGroupVersion.WithResource("catalogsources"):
    70  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1alpha1().CatalogSources().Informer()}, nil
    71  	case v1alpha1.SchemeGroupVersion.WithResource("clusterserviceversions"):
    72  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1alpha1().ClusterServiceVersions().Informer()}, nil
    73  	case v1alpha1.SchemeGroupVersion.WithResource("installplans"):
    74  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1alpha1().InstallPlans().Informer()}, nil
    75  	case v1alpha1.SchemeGroupVersion.WithResource("subscriptions"):
    76  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1alpha1().Subscriptions().Informer()}, nil
    77  
    78  		// Group=operators.coreos.com, Version=v1alpha2
    79  	case v1alpha2.SchemeGroupVersion.WithResource("operatorgroups"):
    80  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V1alpha2().OperatorGroups().Informer()}, nil
    81  
    82  		// Group=operators.coreos.com, Version=v2
    83  	case v2.SchemeGroupVersion.WithResource("operatorconditions"):
    84  		return &genericInformer{resource: resource.GroupResource(), informer: f.Operators().V2().OperatorConditions().Informer()}, nil
    85  
    86  	}
    87  
    88  	return nil, fmt.Errorf("no informer found for %v", resource)
    89  }