@@ -100,11 +100,45 @@ type Options struct {
100
100
// Scheme is the scheme used to resolve runtime.Objects to GroupVersionKinds / Resources.
101
101
// Defaults to the kubernetes/client-go scheme.Scheme, but it's almost always better
102
102
// to pass your own scheme in. See the documentation in pkg/scheme for more information.
103
+ //
104
+ // If set, the Scheme will be used to create the default Client and Cache.
103
105
Scheme * runtime.Scheme
104
106
105
- // MapperProvider provides the rest mapper used to map go types to Kubernetes APIs
107
+ // MapperProvider provides the rest mapper used to map go types to Kubernetes APIs.
108
+ //
109
+ // If set, the RESTMapper returned by this function is used to create the RESTMapper
110
+ // used by the Client and Cache.
106
111
MapperProvider func (c * rest.Config , httpClient * http.Client ) (meta.RESTMapper , error )
107
112
113
+ // Cache is the cache.Options that will be used to create the default Cache.
114
+ // By default, the cache will watch and list requested objects in all namespaces.
115
+ Cache cache.Options
116
+
117
+ // NewCache is the function that will create the cache to be used
118
+ // by the manager. If not set this will use the default new cache function.
119
+ //
120
+ // When using a custom NewCache, the Cache options will be passed to the
121
+ // NewCache function.
122
+ //
123
+ // NOTE: LOW LEVEL PRIMITIVE!
124
+ // Only use a custom NewCache if you know what you are doing.
125
+ NewCache cache.NewCacheFunc
126
+
127
+ // Client is the client.Options that will be used to create the default Client.
128
+ // By default, the client will use the cache for reads and direct calls for writes.
129
+ Client client.Options
130
+
131
+ // NewClient is the func that creates the client to be used by the manager.
132
+ // If not set this will create a Client backed by a Cache for read operations
133
+ // and a direct Client for write operations.
134
+ //
135
+ // When using a custom NewClient, the Client options will be passed to the
136
+ // NewClient function.
137
+ //
138
+ // NOTE: LOW LEVEL PRIMITIVE!
139
+ // Only use a custom NewClient if you know what you are doing.
140
+ NewClient client.NewClientFunc
141
+
108
142
// SyncPeriod determines the minimum frequency at which watched resources are
109
143
// reconciled. A lower period will correct entropy more quickly, but reduce
110
144
// responsiveness to change if there are many watched resources. Change this
@@ -130,6 +164,8 @@ type Options struct {
130
164
// is "done" with an object, and would otherwise not requeue it, i.e., we
131
165
// recommend the `Reconcile` function return `reconcile.Result{RequeueAfter: t}`,
132
166
// instead of `reconcile.Result{}`.
167
+ //
168
+ // Deprecated: Use Cache.SyncPeriod instead.
133
169
SyncPeriod * time.Duration
134
170
135
171
// Logger is the logger that should be used by this manager.
@@ -215,6 +251,8 @@ type Options struct {
215
251
// Note: If a namespace is specified, controllers can still Watch for a
216
252
// cluster-scoped resource (e.g Node). For namespaced resources, the cache
217
253
// will only hold objects from the desired namespace.
254
+ //
255
+ // Deprecated: Use Cache.Namespaces instead.
218
256
Namespace string
219
257
220
258
// MetricsBindAddress is the TCP address that the controller should bind to
@@ -235,48 +273,49 @@ type Options struct {
235
273
236
274
// Port is the port that the webhook server serves at.
237
275
// It is used to set webhook.Server.Port if WebhookServer is not set.
276
+ //
277
+ // Deprecated: Use WebhookServer.Port instead.
238
278
Port int
239
279
// Host is the hostname that the webhook server binds to.
240
280
// It is used to set webhook.Server.Host if WebhookServer is not set.
281
+ //
282
+ // Deprecated: Use WebhookServer.Host instead.
241
283
Host string
242
284
243
285
// CertDir is the directory that contains the server key and certificate.
244
286
// If not set, webhook server would look up the server key and certificate in
245
287
// {TempDir}/k8s-webhook-server/serving-certs. The server key and certificate
246
288
// must be named tls.key and tls.crt, respectively.
247
289
// It is used to set webhook.Server.CertDir if WebhookServer is not set.
290
+ //
291
+ // Deprecated: Use WebhookServer.CertDir instead.
248
292
CertDir string
249
293
250
294
// TLSOpts is used to allow configuring the TLS config used for the webhook server.
295
+ //
296
+ // Deprecated: Use WebhookServer.TLSConfig instead.
251
297
TLSOpts []func (* tls.Config )
252
298
253
299
// WebhookServer is an externally configured webhook.Server. By default,
254
300
// a Manager will create a default server using Port, Host, and CertDir;
255
301
// if this is set, the Manager will use this server instead.
256
302
WebhookServer * webhook.Server
257
303
258
- // Functions to allow for a user to customize values that will be injected.
259
-
260
- // NewCache is the function that will create the cache to be used
261
- // by the manager. If not set this will use the default new cache function.
262
- NewCache cache.NewCacheFunc
263
-
264
- // NewClient is the func that creates the client to be used by the manager.
265
- // If not set this will create a Client backed by a Cache for read operations
266
- // and a direct Client for write operations.
267
- NewClient client.NewClientFunc
268
-
269
304
// BaseContext is the function that provides Context values to Runnables
270
305
// managed by the Manager. If a BaseContext function isn't provided, Runnables
271
306
// will receive a new Background Context instead.
272
307
BaseContext BaseContextFunc
273
308
274
309
// ClientDisableCacheFor tells the client that, if any cache is used, to bypass it
275
310
// for the given objects.
311
+ //
312
+ // Deprecated: Use Client.Cache.DisableCacheFor instead.
276
313
ClientDisableCacheFor []client.Object
277
314
278
315
// DryRunClient specifies whether the client should be configured to enforce
279
316
// dryRun mode.
317
+ //
318
+ // Deprecated: Use Client.DryRun instead.
280
319
DryRunClient bool
281
320
282
321
// EventBroadcaster records Events emitted by the manager and sends them to the Kubernetes API
@@ -348,12 +387,14 @@ func New(config *rest.Config, options Options) (Manager, error) {
348
387
349
388
cluster , err := cluster .New (config , func (clusterOptions * cluster.Options ) {
350
389
clusterOptions .Scheme = options .Scheme
351
- clusterOptions .MapperProvider = options .MapperProvider //nolint:staticcheck
390
+ clusterOptions .MapperProvider = options .MapperProvider
352
391
clusterOptions .Logger = options .Logger
353
392
clusterOptions .SyncPeriod = options .SyncPeriod
354
- clusterOptions .Namespace = options .Namespace //nolint:staticcheck
355
393
clusterOptions .NewCache = options .NewCache
356
394
clusterOptions .NewClient = options .NewClient
395
+ clusterOptions .Cache = options .Cache
396
+ clusterOptions .Client = options .Client
397
+ clusterOptions .Namespace = options .Namespace //nolint:staticcheck
357
398
clusterOptions .ClientDisableCacheFor = options .ClientDisableCacheFor //nolint:staticcheck
358
399
clusterOptions .DryRunClient = options .DryRunClient //nolint:staticcheck
359
400
clusterOptions .EventBroadcaster = options .EventBroadcaster //nolint:staticcheck
@@ -432,10 +473,6 @@ func New(config *rest.Config, options Options) (Manager, error) {
432
473
controllerConfig : options .Controller ,
433
474
logger : options .Logger ,
434
475
elected : make (chan struct {}),
435
- port : options .Port ,
436
- host : options .Host ,
437
- certDir : options .CertDir ,
438
- tlsOpts : options .TLSOpts ,
439
476
webhookServer : options .WebhookServer ,
440
477
leaderElectionID : options .LeaderElectionID ,
441
478
leaseDuration : * options .LeaseDuration ,
@@ -496,14 +533,19 @@ func (o Options) AndFrom(loader config.ControllerManagerConfiguration) (Options,
496
533
if o .Port == 0 && newObj .Webhook .Port != nil {
497
534
o .Port = * newObj .Webhook .Port
498
535
}
499
-
500
536
if o .Host == "" && newObj .Webhook .Host != "" {
501
537
o .Host = newObj .Webhook .Host
502
538
}
503
-
504
539
if o .CertDir == "" && newObj .Webhook .CertDir != "" {
505
540
o .CertDir = newObj .Webhook .CertDir
506
541
}
542
+ if o .WebhookServer == nil {
543
+ o .WebhookServer = & webhook.Server {
544
+ Port : o .Port ,
545
+ Host : o .Host ,
546
+ CertDir : o .CertDir ,
547
+ }
548
+ }
507
549
508
550
if newObj .Controller != nil {
509
551
if o .Controller .CacheSyncTimeout == 0 && newObj .Controller .CacheSyncTimeout != nil {
@@ -657,5 +699,14 @@ func setOptionsDefaults(options Options) Options {
657
699
options .BaseContext = defaultBaseContext
658
700
}
659
701
702
+ if options .WebhookServer == nil {
703
+ options .WebhookServer = & webhook.Server {
704
+ Host : options .Host ,
705
+ Port : options .Port ,
706
+ CertDir : options .CertDir ,
707
+ TLSOpts : options .TLSOpts ,
708
+ }
709
+ }
710
+
660
711
return options
661
712
}
0 commit comments