This example registers a webhooks to a webhook server that gets ran by a controller manager.
()
| 53 | // This example registers a webhooks to a webhook server |
| 54 | // that gets ran by a controller manager. |
| 55 | func 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. |