@@ -209,17 +209,24 @@ type Options struct {
209
209
LivenessEndpointName string
210
210
211
211
// Port is the port that the webhook server serves at.
212
- // It is used to set webhook.Server.Port.
212
+ // It is used to set webhook.Server.Port if WebhookServer is not set .
213
213
Port int
214
214
// Host is the hostname that the webhook server binds to.
215
- // It is used to set webhook.Server.Host.
215
+ // It is used to set webhook.Server.Host if WebhookServer is not set .
216
216
Host string
217
217
218
218
// CertDir is the directory that contains the server key and certificate.
219
- // if not set, webhook server would look up the server key and certificate in
219
+ // If not set, webhook server would look up the server key and certificate in
220
220
// {TempDir}/k8s-webhook-server/serving-certs. The server key and certificate
221
221
// must be named tls.key and tls.crt, respectively.
222
+ // It is used to set webhook.Server.CertDir if WebhookServer is not set.
222
223
CertDir string
224
+
225
+ // WebhookServer is an externally configured webhook.Server. By default,
226
+ // a Manager will create a default server using Port, Host, and CertDir;
227
+ // if this is set, the Manager will use this server instead.
228
+ WebhookServer * webhook.Server
229
+
223
230
// Functions to all for a user to customize the values that will be injected.
224
231
225
232
// NewCache is the function that will create the cache to be used
@@ -358,7 +365,7 @@ func New(config *rest.Config, options Options) (Manager, error) {
358
365
return nil , err
359
366
}
360
367
361
- return & controllerManager {
368
+ cm := & controllerManager {
362
369
cluster : cluster ,
363
370
recorderProvider : recorderProvider ,
364
371
resourceLock : resourceLock ,
@@ -370,6 +377,7 @@ func New(config *rest.Config, options Options) (Manager, error) {
370
377
port : options .Port ,
371
378
host : options .Host ,
372
379
certDir : options .CertDir ,
380
+ webhookServer : options .WebhookServer ,
373
381
leaseDuration : * options .LeaseDuration ,
374
382
renewDeadline : * options .RenewDeadline ,
375
383
retryPeriod : * options .RetryPeriod ,
@@ -379,7 +387,17 @@ func New(config *rest.Config, options Options) (Manager, error) {
379
387
gracefulShutdownTimeout : * options .GracefulShutdownTimeout ,
380
388
internalProceduresStop : make (chan struct {}),
381
389
leaderElectionStopped : make (chan struct {}),
382
- }, nil
390
+ }
391
+
392
+ // A webhook server set by New's caller should be added now
393
+ // so GetWebhookServer can construct a new one if unset and add it only once.
394
+ if cm .webhookServer != nil {
395
+ if err := cm .Add (cm .webhookServer ); err != nil {
396
+ return nil , err
397
+ }
398
+ }
399
+
400
+ return cm , nil
383
401
}
384
402
385
403
// AndFrom will use a supplied type and convert to Options
0 commit comments