Skip to content

Commit 5b1048c

Browse files
committed
🐛 Fix webhook example
Trying to use a zeroed Manager results in immediate panic on startup, so let's create it properly. Signed-off-by: Morten Siebuhr <[email protected]>
1 parent 4836ec2 commit 5b1048c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/webhook/example_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ import (
2424
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
2525
)
2626

27-
var (
28-
mgr ctrl.Manager
29-
)
30-
3127
func Example() {
3228
// Build webhooks
3329
// These handlers could be also be implementations
@@ -48,6 +44,13 @@ func Example() {
4844
}),
4945
}
5046

47+
// Create a manager
48+
// Note: GetConfigOrDie will os.Exit(1) w/o any message if no kube-config can be found
49+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
50+
if err != nil {
51+
panic(err)
52+
}
53+
5154
// Create a webhook server.
5255
hookServer := &Server{
5356
Port: 8443,

0 commit comments

Comments
 (0)