k8s.io/apiserver@v0.31.1/pkg/admission/plugin/policy/internal/generic/informer.go (about) 1 /* 2 Copyright 2022 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 package generic 18 19 import ( 20 "k8s.io/apimachinery/pkg/runtime" 21 "k8s.io/client-go/tools/cache" 22 ) 23 24 var _ Informer[runtime.Object] = informer[runtime.Object]{} 25 26 type informer[T runtime.Object] struct { 27 cache.SharedIndexInformer 28 lister[T] 29 } 30 31 // Creates a generic informer around a type-erased cache.SharedIndexInformer 32 // It is incumbent on the caller to ensure that the generic type argument is 33 // consistent with the type of the objects stored inside the SharedIndexInformer 34 // as they will be casted. 35 func NewInformer[T runtime.Object](informe cache.SharedIndexInformer) Informer[T] { 36 return informer[T]{ 37 SharedIndexInformer: informe, 38 lister: NewLister[T](informe.GetIndexer()), 39 } 40 }