@@ -101,32 +101,28 @@ import (
101
101
func main () {
102
102
...
103
103
104
- // Standard Manager setup.
105
- mgr , err := ctrl.NewManager (ctrl.GetConfigOrDie (), ctrl.Options {
106
- Host: <some host>, // May not be configured explicitly.
107
- Port: <some port>, // May not be configured explicitly.
108
- })
109
-
110
- ...
111
-
112
- // Before any webhooks are registered:
113
- var certDir , certName , keyName string
114
- if info , err := os.Stat (" /apiserver.local.config/certificates" ); err == nil && info.IsDir () {
115
- certDir = " /apiserver.local.config/certificates"
116
- certName = " apiserver.crt"
117
- keyName = " apiserver.key"
118
- }
119
- if err = mgr.Add (webhook.Server {
120
- Host: <some host>, // Set this only if set in ctrl.Options above.
121
- Port: <some port>, // Set this only if set in ctrl.Options above.
122
- CertDir: certDir, // Defaults to the correct path if unset.
123
- CertName: certName, // Defaults to the correct path if unset.
124
- KeyName: keyName, // Defaults to the correct path if unset.
125
- }); err != nil {
126
- setupLog.Error (err, " unable to add webhook server" )
127
- os.Exit (1 )
104
+ // Configure a webhook.Server with the correct path and file names.
105
+ // If webhookServer is nil, which will be the case of OLM >= 0.17 is available,
106
+ // the manager will create a server for you using Host, Port,
107
+ // and the default CertDir, KeyName, and CertName.
108
+ var webhookServer *webhook.Server
109
+ const legacyOLMCertDir = " /apiserver.local.config/certificates"
110
+ if info , err := os.Stat (legacyOLMCertDir); err == nil && info.IsDir () {
111
+ webhookServer = &webhook.Server {
112
+ Host: <some host>, // Set this only if normally set in ctrl.Options below.
113
+ Port: <some port>, // Set this only if normally set in ctrl.Options below.
114
+ CertDir: legacyOLMCertDir,
115
+ CertName: " apiserver.crt" ,
116
+ KeyName: " apiserver.key" ,
117
+ }
128
118
}
129
119
120
+ mgr , err := ctrl.NewManager (ctrl.GetConfigOrDie (), ctrl.Options {
121
+ Host: <some host>,
122
+ Port: <some port>,
123
+ WebhookServer: webhookServer, // Host/Port will not be used if webhookServer is nil.
124
+ })
125
+
130
126
// Now you can register webhooks.
131
127
...
132
128
}
0 commit comments