@@ -19,6 +19,8 @@ package cache
19
19
import (
20
20
"time"
21
21
22
+ "fmt"
23
+
22
24
"github.com/kubernetes-sigs/controller-runtime/pkg/cache/internal"
23
25
"github.com/kubernetes-sigs/controller-runtime/pkg/client"
24
26
"github.com/kubernetes-sigs/controller-runtime/pkg/client/apiutil"
@@ -60,7 +62,11 @@ type Informers interface {
60
62
// WaitForCacheSync waits for all the caches to sync. Returns false if it could not sync a cache.
61
63
WaitForCacheSync (stop <- chan struct {}) bool
62
64
63
- // IndexField adds an index to a field.
65
+ // IndexField adds an index with the given field name on the given object type
66
+ // by using the given function to extract the value for that field. If you want
67
+ // compatibility with the Kubernetes API server, only return one key, and only use
68
+ // fields that the API server supports. Otherwise, you can return multiple keys,
69
+ // and "equality" in the field selector means that at least one key matches the value.
64
70
IndexField (obj runtime.Object , field string , extractValue client.IndexerFunc ) error
65
71
}
66
72
@@ -85,8 +91,7 @@ type informerCache struct {
85
91
* internal.InformersMap
86
92
}
87
93
88
- // New initializes and returns a new Cache
89
- func New (config * rest.Config , opts Options ) (Cache , error ) {
94
+ func Default (config * rest.Config , opts Options ) (Options , error ) {
90
95
// Use the default Kubernetes Scheme if unset
91
96
if opts .Scheme == nil {
92
97
opts .Scheme = scheme .Scheme
@@ -98,7 +103,7 @@ func New(config *rest.Config, opts Options) (Cache, error) {
98
103
opts .Mapper , err = apiutil .NewDiscoveryRESTMapper (config )
99
104
if err != nil {
100
105
log .WithName ("setup" ).Error (err , "Failed to get API Group-Resources" )
101
- return nil , err
106
+ return opts , fmt . Errorf ( "could not create RESTMapper from config" )
102
107
}
103
108
}
104
109
@@ -107,7 +112,15 @@ func New(config *rest.Config, opts Options) (Cache, error) {
107
112
r := 10 * time .Hour
108
113
opts .Resync = & r
109
114
}
115
+ return opts , nil
116
+ }
110
117
118
+ // New initializes and returns a new Cache
119
+ func New (config * rest.Config , opts Options ) (Cache , error ) {
120
+ opts , err := Default (config , opts )
121
+ if err != nil {
122
+ return nil , err
123
+ }
111
124
im := internal .NewInformersMap (config , opts .Scheme , opts .Mapper , * opts .Resync )
112
125
return & informerCache {InformersMap : im }, nil
113
126
}
0 commit comments