@@ -17,7 +17,9 @@ limitations under the License.
17
17
/*
18
18
Package builder provides methods to build admission webhooks.
19
19
20
- For most users, we recommend to use Operations and ForType to construct a webhook.
20
+ For most users, we recommend to use Operations and ForType to construct a webhook,
21
+ since it is more intuitive and easier to pass the target operations to Operations method and
22
+ a empty target object to ForType method than passing a complex RuleWithOperations struct to Rules method.
21
23
22
24
webhook1, err := NewWebhookBuilder().
23
25
Mutating().
@@ -41,8 +43,27 @@ For most users, we recommend to use Operations and ForType to construct a webhoo
41
43
// handle error
42
44
}
43
45
44
- Note: To build a webhook for CRD, you need to ensure the manager is
45
- constructed from the scheme that understands your CRD.
46
+ Note: To build a webhook for a CRD, you need to ensure the manager uses the scheme that understands your CRD.
47
+ This is necessary, because if the scheme doesn't understand your CRD types, the decoder won't be able to decode
48
+ the CR object from the admission review request.
49
+
50
+ The following snippet shows how to register CRD types with manager's scheme.
51
+
52
+ mgr, err := manager.New(cfg, manager.Options{})
53
+ if err != nil {
54
+ // handle error
55
+ }
56
+ // SchemeGroupVersion is group version used to register these objects
57
+ SchemeGroupVersion = schema.GroupVersion{Group: "crew.k8s.io", Version: "v1"}
58
+ // SchemeBuilder is used to add go types to the GroupVersionKind scheme
59
+ SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
60
+ // Register your CRD types.
61
+ SchemeBuilder.Register(&Kraken{}, &KrakenList{})
62
+ // Register your CRD types with the manager's scheme.
63
+ err = SchemeBuilder.AddToScheme(mgr.GetScheme())
64
+ if err != nil {
65
+ // handle error
66
+ }
46
67
47
68
There are more options for configuring a webhook. e.g. Name, Path, FailurePolicy, NamespaceSelector.
48
69
Here is another example:
0 commit comments