MCPcopy
hub / github.com/kubernetes-sigs/controller-runtime / Example

Function Example

pkg/webhook/example_test.go:55–81  ·  view source on GitHub ↗

This example registers a webhooks to a webhook server that gets ran by a controller manager.

()

Source from the content-addressed store, hash-verified

53// This example registers a webhooks to a webhook server
54// that gets ran by a controller manager.
55func Example() {
56 // Create a manager
57 // Note: GetConfigOrDie will os.Exit(1) w/o any message if no kube-config can be found
58 mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
59 if err != nil {
60 panic(err)
61 }
62
63 // Create a webhook server.
64 hookServer := NewServer(Options{
65 Port: 8443,
66 })
67 if err := mgr.Add(hookServer); err != nil {
68 panic(err)
69 }
70
71 // Register the webhooks in the server.
72 hookServer.Register("/mutating", mutatingHook)
73 hookServer.Register("/validating", validatingHook)
74
75 // Start the server by starting a previously-set-up manager
76 err = mgr.Start(ctrl.SetupSignalHandler())
77 if err != nil {
78 // handle error
79 panic(err)
80 }
81}
82
83// This example creates a webhook server that can be
84// ran without a controller manager.

Callers

nothing calls this directly

Calls 4

AddMethod · 0.95
RegisterMethod · 0.95
StartMethod · 0.95
NewServerFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…