sigs.k8s.io/prow@v0.0.0-20240503223140-c5e374dc7eb1/pkg/client/listers/prowjobs/v1/prowjob.go (about)

     1  /*
     2  Copyright The Kubernetes 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  
    17  // Code generated by lister-gen. DO NOT EDIT.
    18  
    19  package v1
    20  
    21  import (
    22  	"k8s.io/apimachinery/pkg/api/errors"
    23  	"k8s.io/apimachinery/pkg/labels"
    24  	"k8s.io/client-go/tools/cache"
    25  	v1 "sigs.k8s.io/prow/pkg/apis/prowjobs/v1"
    26  )
    27  
    28  // ProwJobLister helps list ProwJobs.
    29  // All objects returned here must be treated as read-only.
    30  type ProwJobLister interface {
    31  	// List lists all ProwJobs in the indexer.
    32  	// Objects returned here must be treated as read-only.
    33  	List(selector labels.Selector) (ret []*v1.ProwJob, err error)
    34  	// ProwJobs returns an object that can list and get ProwJobs.
    35  	ProwJobs(namespace string) ProwJobNamespaceLister
    36  	ProwJobListerExpansion
    37  }
    38  
    39  // prowJobLister implements the ProwJobLister interface.
    40  type prowJobLister struct {
    41  	indexer cache.Indexer
    42  }
    43  
    44  // NewProwJobLister returns a new ProwJobLister.
    45  func NewProwJobLister(indexer cache.Indexer) ProwJobLister {
    46  	return &prowJobLister{indexer: indexer}
    47  }
    48  
    49  // List lists all ProwJobs in the indexer.
    50  func (s *prowJobLister) List(selector labels.Selector) (ret []*v1.ProwJob, err error) {
    51  	err = cache.ListAll(s.indexer, selector, func(m interface{}) {
    52  		ret = append(ret, m.(*v1.ProwJob))
    53  	})
    54  	return ret, err
    55  }
    56  
    57  // ProwJobs returns an object that can list and get ProwJobs.
    58  func (s *prowJobLister) ProwJobs(namespace string) ProwJobNamespaceLister {
    59  	return prowJobNamespaceLister{indexer: s.indexer, namespace: namespace}
    60  }
    61  
    62  // ProwJobNamespaceLister helps list and get ProwJobs.
    63  // All objects returned here must be treated as read-only.
    64  type ProwJobNamespaceLister interface {
    65  	// List lists all ProwJobs in the indexer for a given namespace.
    66  	// Objects returned here must be treated as read-only.
    67  	List(selector labels.Selector) (ret []*v1.ProwJob, err error)
    68  	// Get retrieves the ProwJob from the indexer for a given namespace and name.
    69  	// Objects returned here must be treated as read-only.
    70  	Get(name string) (*v1.ProwJob, error)
    71  	ProwJobNamespaceListerExpansion
    72  }
    73  
    74  // prowJobNamespaceLister implements the ProwJobNamespaceLister
    75  // interface.
    76  type prowJobNamespaceLister struct {
    77  	indexer   cache.Indexer
    78  	namespace string
    79  }
    80  
    81  // List lists all ProwJobs in the indexer for a given namespace.
    82  func (s prowJobNamespaceLister) List(selector labels.Selector) (ret []*v1.ProwJob, err error) {
    83  	err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
    84  		ret = append(ret, m.(*v1.ProwJob))
    85  	})
    86  	return ret, err
    87  }
    88  
    89  // Get retrieves the ProwJob from the indexer for a given namespace and name.
    90  func (s prowJobNamespaceLister) Get(name string) (*v1.ProwJob, error) {
    91  	obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	if !exists {
    96  		return nil, errors.NewNotFound(v1.Resource("prowjob"), name)
    97  	}
    98  	return obj.(*v1.ProwJob), nil
    99  }