| 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 |
"context" |
| 21 |
|
| 22 |
"k8s.io/apimachinery/pkg/labels" |
| 23 |
"k8s.io/apimachinery/pkg/runtime" |
| 24 |
"k8s.io/client-go/tools/cache" |
| 25 |
) |
| 26 |
|
| 27 |
type Controller[T runtime.Object] interface { |
| 28 |
// Meant to be run inside a goroutine |
| 29 |
// Waits for and reacts to changes in whatever type the controller |
| 30 |
// is concerned with. |
| 31 |
// |
| 32 |
// Returns an error always non-nil explaining why the worker stopped |
| 33 |
Run(ctx context.Context) error |
| 34 |
|
| 35 |
// Retrieves the informer used to back this controller |
| 36 |
Informer() Informer[T] |
| 37 |
|
| 38 |
// Returns true if the informer cache has synced, and all the objects from |
| 39 |
// the initial list have been reconciled at least once. |
| 40 |
HasSynced() bool |
| 41 |
} |
| 42 |
|
| 43 |
type NamespacedLister[T any] interface { |
| 44 |
// List lists all ValidationRuleSets in the indexer for a given namespace. |
| 45 |
// Objects returned here must be treated as read-only. |
| 46 |
List(selector labels.Selector) (ret []T, err error) |
| 47 |
// Get retrieves the ValidationRuleSet from the indexer for a given namespace and name. |
| 48 |
// Objects returned here must be treated as read-only. |
| 49 |
Get(name string) (T, error) |
| 50 |
} |
| 51 |
|
| 52 |
type Informer[T any] interface { |
| 53 |
cache.SharedIndexInformer |
| 54 |
Lister[T] |
| 55 |
} |
| 56 |
|
| 57 |
// Lister[T] helps list Ts. |
| 58 |
// All objects returned here must be treated as read-only. |
| 59 |
type Lister[T any] interface { |
| 60 |
NamespacedLister[T] |
| 61 |
Namespaced(namespace string) NamespacedLister[T] |
| 62 |
} |