Skip to content

Commit 8a255d3

Browse files
author
Mengqi Yu
committed
polish the godoc a little more
1 parent 47fc5ab commit 8a255d3

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

pkg/doc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ system must be read for each Reconciler.
5151
5252
Webhook
5353
54-
Admission Webhook is a mechanism for extending kubernetes APIs. The API server will send AdmissionRequests to
54+
Admission Webhooks are a mechanism for extending kubernetes APIs. The API server will send AdmissionRequests to
5555
the webhooks according to the configured target event type (object Create, Update, Delete). The webhooks may
5656
mutate and (or) validate the object embedded in the AdmissionReview requests.
5757
5858
There are 2 types of admission webhook: mutating and validating admission webhook.
59-
Mutating webhook is used to mutate a core API object or a CRD instance before the API server admit it.
60-
Validting webhook is used to validate if a core API object or a CRD instance meet certain requirements.
59+
Mutating webhook is used to mutate a core API object or a CRD instance before the API server admits it.
60+
Validating webhook is used to validate if an object meets certain requirements.
6161
6262
* Admission Webhooks require Handler(s) to be provided to process the received AdmissionReview requests.
6363

pkg/webhook/admission/builder/doc.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ limitations under the License.
1717
/*
1818
Package builder provides methods to build admission webhooks.
1919
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.
2123
2224
webhook1, err := NewWebhookBuilder().
2325
Mutating().
@@ -41,8 +43,27 @@ For most users, we recommend to use Operations and ForType to construct a webhoo
4143
// handle error
4244
}
4345
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+
}
4667
4768
There are more options for configuring a webhook. e.g. Name, Path, FailurePolicy, NamespaceSelector.
4869
Here is another example:

pkg/webhook/admission/doc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ The following snippet is an example implementation of mutating handler.
4343
return admission.PatchResponse(pod, copy)
4444
}
4545
46-
// InjectClient injects the client into the Handler
46+
// InjectClient is called by the Manager and provides a client.Client to the Mutator instance.
4747
func (m *Mutator) InjectClient(c client.Client) error {
4848
h.client = c
4949
return nil
5050
}
5151
52-
// InjectDecoder injects the decoder into the Handler
52+
// InjectDecoder is called by the Manager and provides a types.Decoder to the Mutator instance.
5353
func (m *Mutator) InjectDecoder(d types.Decoder) error {
5454
h.decoder = d
5555
return nil
@@ -80,13 +80,13 @@ The following snippet is an example implementation of validating handler.
8080
return admission.ValidationResponse(allowed, reason)
8181
}
8282
83-
// InjectClient injects the client into the Handler
83+
// InjectClient is called by the Manager and provides a client.Client to the Validator instance.
8484
func (v *Validator) InjectClient(c client.Client) error {
8585
h.client = c
8686
return nil
8787
}
8888
89-
// InjectDecoder injects the decoder into the Handler
89+
// InjectDecoder is called by the Manager and provides a types.Decoder to the Validator instance.
9090
func (v *Validator) InjectDecoder(d types.Decoder) error {
9191
h.decoder = d
9292
return nil

0 commit comments

Comments
 (0)