volcano.sh/apis@v1.8.2/pkg/client/informers/externalversions/generic.go (about)

     1  /*
     2  Copyright 2021 The Volcano Authors.
     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  // Code generated by informer-gen. DO NOT EDIT.
    17  
    18  package externalversions
    19  
    20  import (
    21  	"fmt"
    22  
    23  	schema "k8s.io/apimachinery/pkg/runtime/schema"
    24  	cache "k8s.io/client-go/tools/cache"
    25  	v1alpha1 "volcano.sh/apis/pkg/apis/batch/v1alpha1"
    26  	busv1alpha1 "volcano.sh/apis/pkg/apis/bus/v1alpha1"
    27  	flowv1alpha1 "volcano.sh/apis/pkg/apis/flow/v1alpha1"
    28  	nodeinfov1alpha1 "volcano.sh/apis/pkg/apis/nodeinfo/v1alpha1"
    29  	v1beta1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
    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=batch.volcano.sh, Version=v1alpha1
    59  	case v1alpha1.SchemeGroupVersion.WithResource("jobs"):
    60  		return &genericInformer{resource: resource.GroupResource(), informer: f.Batch().V1alpha1().Jobs().Informer()}, nil
    61  
    62  		// Group=bus.volcano.sh, Version=v1alpha1
    63  	case busv1alpha1.SchemeGroupVersion.WithResource("commands"):
    64  		return &genericInformer{resource: resource.GroupResource(), informer: f.Bus().V1alpha1().Commands().Informer()}, nil
    65  
    66  		// Group=flow.volcano.sh, Version=v1alpha1
    67  	case flowv1alpha1.SchemeGroupVersion.WithResource("jobflows"):
    68  		return &genericInformer{resource: resource.GroupResource(), informer: f.Flow().V1alpha1().JobFlows().Informer()}, nil
    69  	case flowv1alpha1.SchemeGroupVersion.WithResource("jobtemplates"):
    70  		return &genericInformer{resource: resource.GroupResource(), informer: f.Flow().V1alpha1().JobTemplates().Informer()}, nil
    71  
    72  		// Group=nodeinfo.volcano.sh, Version=v1alpha1
    73  	case nodeinfov1alpha1.SchemeGroupVersion.WithResource("numatopologies"):
    74  		return &genericInformer{resource: resource.GroupResource(), informer: f.Nodeinfo().V1alpha1().Numatopologies().Informer()}, nil
    75  
    76  		// Group=scheduling.volcano.sh, Version=v1beta1
    77  	case v1beta1.SchemeGroupVersion.WithResource("podgroups"):
    78  		return &genericInformer{resource: resource.GroupResource(), informer: f.Scheduling().V1beta1().PodGroups().Informer()}, nil
    79  	case v1beta1.SchemeGroupVersion.WithResource("queues"):
    80  		return &genericInformer{resource: resource.GroupResource(), informer: f.Scheduling().V1beta1().Queues().Informer()}, nil
    81  
    82  	}
    83  
    84  	return nil, fmt.Errorf("no informer found for %v", resource)
    85  }