Skip to content

docs/olm-integration: fix example Go code for OLM < 0.17 #4945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions website/content/en/docs/olm-integration/generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,28 @@ import (
func main() {
...

// Standard Manager setup.
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Host: <some host>, // May not be configured explicitly.
Port: <some port>, // May not be configured explicitly.
})

...

// Before any webhooks are registered:
var certDir, certName, keyName string
if info, err := os.Stat("/apiserver.local.config/certificates"); err == nil && info.IsDir() {
certDir = "/apiserver.local.config/certificates"
certName = "apiserver.crt"
keyName = "apiserver.key"
}
if err = mgr.Add(webhook.Server{
Host: <some host>, // Set this only if set in ctrl.Options above.
Port: <some port>, // Set this only if set in ctrl.Options above.
CertDir: certDir, // Defaults to the correct path if unset.
CertName: certName, // Defaults to the correct path if unset.
KeyName: keyName, // Defaults to the correct path if unset.
}); err != nil {
setupLog.Error(err, "unable to add webhook server")
os.Exit(1)
// Configure a webhook.Server with the correct path and file names.
// If webhookServer is nil, which will be the case of OLM >= 0.17 is available,
// the manager will create a server for you using Host, Port,
// and the default CertDir, KeyName, and CertName.
var webhookServer *webhook.Server
const legacyOLMCertDir = "/apiserver.local.config/certificates"
if info, err := os.Stat(legacyOLMCertDir); err == nil && info.IsDir() {
webhookServer = &webhook.Server{
Host: <some host>, // Set this only if normally set in ctrl.Options below.
Port: <some port>, // Set this only if normally set in ctrl.Options below.
CertDir: legacyOLMCertDir,
CertName: "apiserver.crt",
KeyName: "apiserver.key",
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Host: <some host>,
Port: <some port>,
WebhookServer: webhookServer, // Host/Port will not be used if webhookServer is nil.
})

// Now you can register webhooks.
...
}
Expand Down