@@ -100,11 +100,45 @@ type Options struct {
100100	// Scheme is the scheme used to resolve runtime.Objects to GroupVersionKinds / Resources. 
101101	// Defaults to the kubernetes/client-go scheme.Scheme, but it's almost always better 
102102	// 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. 
103105	Scheme  * runtime.Scheme 
104106
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. 
106111	MapperProvider  func (c  * rest.Config , httpClient  * http.Client ) (meta.RESTMapper , error )
107112
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+ 
108142	// SyncPeriod determines the minimum frequency at which watched resources are 
109143	// reconciled. A lower period will correct entropy more quickly, but reduce 
110144	// responsiveness to change if there are many watched resources. Change this 
@@ -130,6 +164,8 @@ type Options struct {
130164	// is "done" with an object, and would otherwise not requeue it, i.e., we 
131165	// recommend the `Reconcile` function return `reconcile.Result{RequeueAfter: t}`, 
132166	// instead of `reconcile.Result{}`. 
167+ 	// 
168+ 	// Deprecated: Use Cache.SyncPeriod instead. 
133169	SyncPeriod  * time.Duration 
134170
135171	// Logger is the logger that should be used by this manager. 
@@ -215,6 +251,8 @@ type Options struct {
215251	// Note: If a namespace is specified, controllers can still Watch for a 
216252	// cluster-scoped resource (e.g Node). For namespaced resources, the cache 
217253	// will only hold objects from the desired namespace. 
254+ 	// 
255+ 	// Deprecated: Use Cache.Namespaces instead. 
218256	Namespace  string 
219257
220258	// MetricsBindAddress is the TCP address that the controller should bind to 
@@ -235,48 +273,49 @@ type Options struct {
235273
236274	// Port is the port that the webhook server serves at. 
237275	// It is used to set webhook.Server.Port if WebhookServer is not set. 
276+ 	// 
277+ 	// Deprecated: Use WebhookServer.Port instead. 
238278	Port  int 
239279	// Host is the hostname that the webhook server binds to. 
240280	// It is used to set webhook.Server.Host if WebhookServer is not set. 
281+ 	// 
282+ 	// Deprecated: Use WebhookServer.Host instead. 
241283	Host  string 
242284
243285	// CertDir is the directory that contains the server key and certificate. 
244286	// If not set, webhook server would look up the server key and certificate in 
245287	// {TempDir}/k8s-webhook-server/serving-certs. The server key and certificate 
246288	// must be named tls.key and tls.crt, respectively. 
247289	// It is used to set webhook.Server.CertDir if WebhookServer is not set. 
290+ 	// 
291+ 	// Deprecated: Use WebhookServer.CertDir instead. 
248292	CertDir  string 
249293
250294	// TLSOpts is used to allow configuring the TLS config used for the webhook server. 
295+ 	// 
296+ 	// Deprecated: Use WebhookServer.TLSConfig instead. 
251297	TLSOpts  []func (* tls.Config )
252298
253299	// WebhookServer is an externally configured webhook.Server. By default, 
254300	// a Manager will create a default server using Port, Host, and CertDir; 
255301	// if this is set, the Manager will use this server instead. 
256302	WebhookServer  * webhook.Server 
257303
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- 
269304	// BaseContext is the function that provides Context values to Runnables 
270305	// managed by the Manager. If a BaseContext function isn't provided, Runnables 
271306	// will receive a new Background Context instead. 
272307	BaseContext  BaseContextFunc 
273308
274309	// ClientDisableCacheFor tells the client that, if any cache is used, to bypass it 
275310	// for the given objects. 
311+ 	// 
312+ 	// Deprecated: Use Client.Cache.DisableCacheFor instead. 
276313	ClientDisableCacheFor  []client.Object 
277314
278315	// DryRunClient specifies whether the client should be configured to enforce 
279316	// dryRun mode. 
317+ 	// 
318+ 	// Deprecated: Use Client.DryRun instead. 
280319	DryRunClient  bool 
281320
282321	// 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) {
348387
349388	cluster , err  :=  cluster .New (config , func (clusterOptions  * cluster.Options ) {
350389		clusterOptions .Scheme  =  options .Scheme 
351- 		clusterOptions .MapperProvider  =  options .MapperProvider   //nolint:staticcheck 
390+ 		clusterOptions .MapperProvider  =  options .MapperProvider 
352391		clusterOptions .Logger  =  options .Logger 
353392		clusterOptions .SyncPeriod  =  options .SyncPeriod 
354- 		clusterOptions .Namespace  =  options .Namespace  //nolint:staticcheck 
355393		clusterOptions .NewCache  =  options .NewCache 
356394		clusterOptions .NewClient  =  options .NewClient 
395+ 		clusterOptions .Cache  =  options .Cache 
396+ 		clusterOptions .Client  =  options .Client 
397+ 		clusterOptions .Namespace  =  options .Namespace                          //nolint:staticcheck 
357398		clusterOptions .ClientDisableCacheFor  =  options .ClientDisableCacheFor  //nolint:staticcheck 
358399		clusterOptions .DryRunClient  =  options .DryRunClient                    //nolint:staticcheck 
359400		clusterOptions .EventBroadcaster  =  options .EventBroadcaster            //nolint:staticcheck 
@@ -432,10 +473,6 @@ func New(config *rest.Config, options Options) (Manager, error) {
432473		controllerConfig :              options .Controller ,
433474		logger :                        options .Logger ,
434475		elected :                       make (chan  struct {}),
435- 		port :                          options .Port ,
436- 		host :                          options .Host ,
437- 		certDir :                       options .CertDir ,
438- 		tlsOpts :                       options .TLSOpts ,
439476		webhookServer :                 options .WebhookServer ,
440477		leaderElectionID :              options .LeaderElectionID ,
441478		leaseDuration :                 * options .LeaseDuration ,
@@ -488,16 +525,27 @@ func (o Options) AndFrom(loader config.ControllerManagerConfiguration) (Options,
488525		o .LivenessEndpointName  =  newObj .Health .LivenessEndpointName 
489526	}
490527
491- 	if  o .Port  ==  0  &&  newObj .Webhook .Port  !=  nil  {
492- 		o .Port  =  * newObj .Webhook .Port 
528+ 	webhookServer  :=  & webhook.Server {}
529+ 	if  newObj .Webhook .Port  !=  nil  {
530+ 		if  o .Port  ==  0  {
531+ 			o .Port  =  * newObj .Webhook .Port 
532+ 		}
533+ 		webhookServer .Port  =  * newObj .Webhook .Port 
493534	}
494- 
495- 	if  o .Host  ==  ""  &&  newObj .Webhook .Host  !=  ""  {
496- 		o .Host  =  newObj .Webhook .Host 
535+ 	if  newObj .Webhook .Host  !=  ""  {
536+ 		if  o .Host  ==  ""  {
537+ 			o .Host  =  newObj .Webhook .Host 
538+ 		}
539+ 		webhookServer .Host  =  newObj .Webhook .Host 
497540	}
498- 
499- 	if  o .CertDir  ==  ""  &&  newObj .Webhook .CertDir  !=  ""  {
500- 		o .CertDir  =  newObj .Webhook .CertDir 
541+ 	if  newObj .Webhook .CertDir  !=  ""  {
542+ 		if  o .CertDir  ==  ""  {
543+ 			o .CertDir  =  newObj .Webhook .CertDir 
544+ 		}
545+ 		webhookServer .CertDir  =  newObj .Webhook .CertDir 
546+ 	}
547+ 	if  o .WebhookServer  ==  nil  {
548+ 		o .WebhookServer  =  webhookServer 
501549	}
502550
503551	if  newObj .Controller  !=  nil  {
@@ -647,5 +695,14 @@ func setOptionsDefaults(options Options) Options {
647695		options .BaseContext  =  defaultBaseContext 
648696	}
649697
698+ 	if  options .WebhookServer  ==  nil  {
699+ 		options .WebhookServer  =  & webhook.Server {
700+ 			Host :    options .Host ,
701+ 			Port :    options .Port ,
702+ 			CertDir : options .CertDir ,
703+ 			TLSOpts : options .TLSOpts ,
704+ 		}
705+ 	}
706+ 
650707	return  options 
651708}
0 commit comments