github.com/kubeflow/training-operator@v1.7.0/pkg/client/informers/externalversions/generic.go (about)

     1  // Copyright 2023 The Kubeflow 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  
    15  // Code generated by informer-gen. DO NOT EDIT.
    16  
    17  package externalversions
    18  
    19  import (
    20  	"fmt"
    21  
    22  	v1 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v1"
    23  	schema "k8s.io/apimachinery/pkg/runtime/schema"
    24  	cache "k8s.io/client-go/tools/cache"
    25  )
    26  
    27  // GenericInformer is type of SharedIndexInformer which will locate and delegate to other
    28  // sharedInformers based on type
    29  type GenericInformer interface {
    30  	Informer() cache.SharedIndexInformer
    31  	Lister() cache.GenericLister
    32  }
    33  
    34  type genericInformer struct {
    35  	informer cache.SharedIndexInformer
    36  	resource schema.GroupResource
    37  }
    38  
    39  // Informer returns the SharedIndexInformer.
    40  func (f *genericInformer) Informer() cache.SharedIndexInformer {
    41  	return f.informer
    42  }
    43  
    44  // Lister returns the GenericLister.
    45  func (f *genericInformer) Lister() cache.GenericLister {
    46  	return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
    47  }
    48  
    49  // ForResource gives generic access to a shared informer of the matching type
    50  // TODO extend this to unknown resources with a client pool
    51  func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
    52  	switch resource {
    53  	// Group=kubeflow.org, Version=v1
    54  	case v1.SchemeGroupVersion.WithResource("mpijobs"):
    55  		return &genericInformer{resource: resource.GroupResource(), informer: f.Kubeflow().V1().MPIJobs().Informer()}, nil
    56  	case v1.SchemeGroupVersion.WithResource("mxjobs"):
    57  		return &genericInformer{resource: resource.GroupResource(), informer: f.Kubeflow().V1().MXJobs().Informer()}, nil
    58  	case v1.SchemeGroupVersion.WithResource("paddlejobs"):
    59  		return &genericInformer{resource: resource.GroupResource(), informer: f.Kubeflow().V1().PaddleJobs().Informer()}, nil
    60  	case v1.SchemeGroupVersion.WithResource("pytorchjobs"):
    61  		return &genericInformer{resource: resource.GroupResource(), informer: f.Kubeflow().V1().PyTorchJobs().Informer()}, nil
    62  	case v1.SchemeGroupVersion.WithResource("tfjobs"):
    63  		return &genericInformer{resource: resource.GroupResource(), informer: f.Kubeflow().V1().TFJobs().Informer()}, nil
    64  	case v1.SchemeGroupVersion.WithResource("xgboostjobs"):
    65  		return &genericInformer{resource: resource.GroupResource(), informer: f.Kubeflow().V1().XGBoostJobs().Informer()}, nil
    66  
    67  	}
    68  
    69  	return nil, fmt.Errorf("no informer found for %v", resource)
    70  }